Skip to content

Commit

Permalink
test: Adjust test suite runner
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <[email protected]>
  • Loading branch information
Stranger6667 committed Sep 13, 2024
1 parent 1b36eeb commit 3c58526
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
2 changes: 2 additions & 0 deletions crates/jsonschema-testsuite-codegen/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn generate_nested_structure(
case_path.push(test_name.clone());

let full_test_path = case_path.join("::");
let is_optional = case_path.iter().any(|segment| segment == "optional");
let should_ignore = xfail.iter().any(|x| full_test_path.starts_with(x));
let ignore_attr = if should_ignore {
quote! { #[ignore] }
Expand All @@ -78,6 +79,7 @@ fn generate_nested_structure(
let test = testsuite::Test {
draft: #draft,
schema: serde_json::from_str(#schema).expect("Failed to load JSON"),
is_optional: #is_optional,
case: #case_description,
description: #test_description,
data: serde_json::from_str(#data).expect("Failed to load JSON"),
Expand Down
1 change: 1 addition & 0 deletions crates/jsonschema-testsuite-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Test {
pub draft: &'static str,
pub schema: Value,
pub case: &'static str,
pub is_optional: bool,
/// The test description, briefly explaining which behavior it exercises.
pub description: &'static str,
/// The instance which should be validated against the schema in schema.
Expand Down
52 changes: 16 additions & 36 deletions crates/jsonschema/tests/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use testsuite::{suite, Test};
"draft7::ref_remote::ref_to_ref_finds_location_independent_id",
"draft2019-09::anchor",
"draft2019-09::defs",
"draft2019-09::format::validation_of",
"draft2019-09::id::invalid_use_of_fragments_in_location_independent_id",
"draft2019-09::optional::anchor",
"draft2019-09::optional::cross_draft::refs_to_historic_drafts_are_processed_as_historic_drafts",
"draft2019-09::optional::ecmascript_regex::d_in_pattern_properties_matches_0_9_not_unicode_digits",
Expand All @@ -51,29 +49,6 @@ use testsuite::{suite, Test};
"draft2020-12::anchor",
"draft2020-12::defs::validate_definition_against_metaschema::invalid_definition_schema",
"draft2020-12::dynamic_ref",
"draft2020-12::format::date_format",
"draft2020-12::format::date_format",
"draft2020-12::format::date_time_format",
"draft2020-12::format::date_time_format",
"draft2020-12::format::email_format",
"draft2020-12::format::email_format",
"draft2020-12::format::hostname_format",
"draft2020-12::format::hostname_format",
"draft2020-12::format::idn_email_format",
"draft2020-12::format::idn_email_format",
"draft2020-12::format::ipv4_format",
"draft2020-12::format::ipv4_format",
"draft2020-12::format::ipv6_format",
"draft2020-12::format::ipv6_format",
"draft2020-12::format::regex_format",
"draft2020-12::format::regex_format",
"draft2020-12::format::time_format",
"draft2020-12::format::time_format",
"draft2020-12::format::uri_format",
"draft2020-12::format::uri_format",
"draft2020-12::format::uuid_format::invalid_uuid",
"draft2020-12::format::validation_of",
"draft2020-12::id::invalid_use_of_fragments_in_location_independent_id",
"draft2020-12::optional::anchor::anchor_inside_an_enum_is_not_a_real_identifier",
"draft2020-12::optional::cross_draft::refs_to_historic_drafts_are_processed_as_historic_drafts",
"draft2020-12::optional::dynamic_ref::dynamic_ref_skips_over_intermediate_resources_pointer_reference_across_resource_boundary",
Expand Down Expand Up @@ -106,21 +81,26 @@ use testsuite::{suite, Test};
]
)]
fn test_suite(test: Test) {
let draft = match test.draft {
"draft4" => Draft::Draft4,
"draft6" => Draft::Draft6,
"draft7" => Draft::Draft7,
"draft2019-09" => Draft::Draft201909,
"draft2020-12" => Draft::Draft202012,
let mut options = JSONSchema::options();
match test.draft {
"draft4" => {
options.with_draft(Draft::Draft4);
}
"draft6" => {
options.with_draft(Draft::Draft6);
}
"draft7" => {
options.with_draft(Draft::Draft7);
}
"draft2019-09" | "draft2020-12" => {}
_ => panic!("Unsupported draft"),
};

let compiled = JSONSchema::options()
.with_draft(draft)
.should_validate_formats(true)
if test.is_optional {
options.should_validate_formats(true);
}
let compiled = options
.compile(&test.schema)
.expect("should not fail to compile schema");

let result = compiled.validate(&test.data);

if test.valid {
Expand Down

0 comments on commit 3c58526

Please sign in to comment.