Add test for invalid schemars attributes
This commit is contained in:
parent
b0a2f9994b
commit
4197bf4183
6 changed files with 54 additions and 2 deletions
|
@ -26,6 +26,7 @@ arrayvec = { version = "0.5", default-features = false, optional = true }
|
|||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "0.6.1"
|
||||
trybuild = "1.0"
|
||||
|
||||
[features]
|
||||
default = ["derive"]
|
||||
|
@ -36,6 +37,8 @@ impl_json_schema = ["derive"]
|
|||
# derive_json_schema will be removed in a later version
|
||||
derive_json_schema = ["impl_json_schema"]
|
||||
|
||||
ui_test = []
|
||||
|
||||
[[test]]
|
||||
name = "chrono"
|
||||
required-features = ["chrono"]
|
||||
|
@ -64,5 +67,9 @@ required-features = ["arrayvec"]
|
|||
name = "schema_for_schema"
|
||||
required-features = ["impl_json_schema"]
|
||||
|
||||
[[test]]
|
||||
name = "ui"
|
||||
required-features = ["ui_test"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::flatten::Merge;
|
||||
use crate::schema::*;
|
||||
use crate::{visit::*, JsonSchema, Map};
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Settings to customize how Schemas are generated.
|
||||
///
|
||||
|
|
5
schemars/tests/ui.rs
Normal file
5
schemars/tests/ui.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
#[test]
|
||||
fn ui() {
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/*.rs");
|
||||
}
|
11
schemars/tests/ui/invalid_attrs.rs
Normal file
11
schemars/tests/ui/invalid_attrs.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use schemars::JsonSchema;
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
|
||||
pub struct Struct1;
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
|
||||
pub struct Struct2;
|
||||
|
||||
fn main() {}
|
29
schemars/tests/ui/invalid_attrs.stderr
Normal file
29
schemars/tests/ui/invalid_attrs.stderr
Normal file
|
@ -0,0 +1,29 @@
|
|||
error: expected serde default attribute to be a string: `default = "..."`
|
||||
--> $DIR/invalid_attrs.rs:4:19
|
||||
|
|
||||
4 | #[serde(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
|
||||
| ^
|
||||
|
||||
error: duplicate serde attribute `deny_unknown_fields`
|
||||
--> $DIR/invalid_attrs.rs:4:48
|
||||
|
|
||||
4 | #[serde(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: expected serde default attribute to be a string: `default = "..."`
|
||||
--> $DIR/invalid_attrs.rs:8:22
|
||||
|
|
||||
8 | #[schemars(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
|
||||
| ^
|
||||
|
||||
error: duplicate serde attribute `deny_unknown_fields`
|
||||
--> $DIR/invalid_attrs.rs:8:51
|
||||
|
|
||||
8 | #[schemars(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unknown schemars container attribute `foo`
|
||||
--> $DIR/invalid_attrs.rs:8:25
|
||||
|
|
||||
8 | #[schemars(default = 0, foo, deny_unknown_fields, deny_unknown_fields)]
|
||||
| ^^^
|
|
@ -5,7 +5,7 @@ cd schemars
|
|||
|
||||
rm -f tests/actual/*.json
|
||||
|
||||
cargo test --all-features --no-fail-fast --tests || :
|
||||
TRYBUILD=overwrite cargo test --all-features --no-fail-fast --tests || :
|
||||
|
||||
if ls tests/actual/*.json 1> /dev/null 2>&1; then
|
||||
mv -f tests/actual/*.json tests/expected/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue