diff --git a/src/command_test.cc b/src/command_test.cc index b533001a..96feabab 100644 --- a/src/command_test.cc +++ b/src/command_test.cc @@ -241,13 +241,12 @@ auto sourcemeta::jsonschema::cli::test( return EXIT_FAILURE; } + const auto instance{ + get_data(test_case, entry.first.parent_path(), verbose)}; const std::string ref{"$ref"}; - sourcemeta::blaze::ErrorTraceOutput output{schema.value(), - {std::cref(ref)}}; + sourcemeta::blaze::ErrorTraceOutput output{instance, {std::cref(ref)}}; const auto case_result{sourcemeta::blaze::evaluate( - schema_template, - get_data(test_case, entry.first.parent_path(), verbose), - std::ref(output))}; + schema_template, instance, std::ref(output))}; std::ostringstream test_case_description; if (test_case.defines("description")) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9da80194..0f1924d9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -79,6 +79,7 @@ add_jsonschema_test_unix(metaschema/pass_single) add_jsonschema_test_unix(metaschema/pass_2020_12) # Test +add_jsonschema_test_unix(test/fail_additional_properties) add_jsonschema_test_unix(test/fail_true_single_resolve) add_jsonschema_test_unix(test/fail_true_single_resolve_verbose) add_jsonschema_test_unix(test/fail_false_single_resolve) diff --git a/test/test/fail_additional_properties.sh b/test/test/fail_additional_properties.sh new file mode 100755 index 00000000..6434d380 --- /dev/null +++ b/test/test/fail_additional_properties.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << 'EOF' > "$TMP/schema.json" +{ + "id": "https://example.com", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "additionalProperties": false, + "properties": { + "foo": true, + "bar": true + } +} +EOF + +cat << 'EOF' > "$TMP/test.json" +{ + "target": "https://example.com", + "tests": [ + { + "valid": false, + "data": { "fo": true } + } + ] +} +EOF + +"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 + +cat << EOF > "$TMP/expected.txt" +$(realpath "$TMP")/test.json: PASS 1/1 +EOF + +diff "$TMP/output.txt" "$TMP/expected.txt"