Skip to content

Commit

Permalink
Fix segmentation fault on describing objects failures in test
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Nov 7, 2024
1 parent 7f08123 commit 2d7ef8a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/command_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions test/test/fail_additional_properties.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion test/test/fail_multi_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $(realpath "$TMP")/test.json:
2/4 FAIL First failure
error: Schema validation failure
The value was expected to be of type string but it was of type object
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_multi_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $(realpath "$TMP")/test.json:
2/4 FAIL First failure
error: Schema validation failure
The value was expected to be of type string but it was of type object
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_resolve_fragment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $(realpath "$TMP")/test.json:
1/1 FAIL Fail
error: Schema validation failure
The value was expected to be of type string but it was of type object
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
EOF
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_single_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(realpath "$TMP")/test.json:
2/3 FAIL Unexpected
error: Schema validation failure
The value was expected to be of type string but it was of type object
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
EOF
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_single_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $(realpath "$TMP")/test.json:
2/3 FAIL Unexpected
error: Schema validation failure
The value was expected to be of type string but it was of type object
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
Expand Down

0 comments on commit 2d7ef8a

Please sign in to comment.