Skip to content

Commit

Permalink
Replace trybuild tests with some local ones
Browse files Browse the repository at this point in the history
As it turns out, rustc's "trait unimplemented" error messages have not
stayed perfectly stable across the last 10 versions. This is likely an
issue that would keep happening with trybuild which would make it
somewhat unsuitable.

With some thinking I was able to get the same test coverage without
requiring a compile error.
  • Loading branch information
swlynch99 committed Dec 18, 2023
1 parent c170cdf commit 2147424
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 62 deletions.
30 changes: 25 additions & 5 deletions serde_with/tests/schemars_0_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,31 @@ fn schemars_basic() {
assert_eq!(value, expected);
}

#[test]
fn trybuild() {
let t = trybuild::TestCases::new();
t.pass("tests/trybuild/schemars_0_8/pass.conditional_derive_enabled.rs");
t.compile_fail("tests/trybuild/schemars_0_8/fail.conditional_derive_disabled.rs");
mod derive {
use super::*;

#[serde_with::serde_as]
#[derive(Serialize)]
#[cfg_attr(all(), derive(JsonSchema))]
struct Enabled {
#[serde_as(as = "DisplayFromStr")]
field: u32,
}

#[serde_with::serde_as]
#[derive(Serialize)]
#[cfg_attr(any(), derive(JsonSchema))]
struct Disabled {
// If we are incorrectly adding `#[schemars(with = ...)]` attributes
// then we should get an error on this field.
#[serde_as(as = "DisplayFromStr")]
field: u32,
}

#[test]
fn test_enabled_has_correct_schema() {
check_valid_json_schema(&Enabled { field: 77 });
}
}

mod array {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 2147424

Please sign in to comment.