Skip to content

Commit

Permalink
Improve error message when test attempts to resolve a non-schema (#191
Browse files Browse the repository at this point in the history
)

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti authored Nov 7, 2024
1 parent 8b5d1c5 commit e77f2e5
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
noa https://github.com/sourcemeta/noa caad2e1ceedf9fd1a18686a6a6d1e2b9757ead75
jsontoolkit https://github.com/sourcemeta/jsontoolkit c6d056cc608bf98705ad7700c8c891e1cf6865a0
jsontoolkit https://github.com/sourcemeta/jsontoolkit 7a398224cc2e76ea9ae8541a872b131c7c025267
hydra https://github.com/sourcemeta/hydra a4a74f3cabd32f2f829f449d67339dac33f9910e
alterschema https://github.com/sourcemeta/alterschema 92e370ce9c1f0582014b54d43e388ee012dfe13d
jsonbinpack https://github.com/sourcemeta/jsonbinpack d777179441d3c703e1fda1187742541aa26836b5
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_resolve_directory_non_schema)
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)
46 changes: 46 additions & 0 deletions test/test/fail_resolve_directory_non_schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

mkdir "$TMP/schemas"

cat << 'EOF' > "$TMP/schemas/schema.json"
{
"id": "https://example.com",
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"foo": { "type": "string" },
"bar": { "type": "integer" }
}
}
EOF

cat << 'EOF' > "$TMP/schemas/test.json"
{
"target": "https://example.com#/definitions/foo",
"tests": [
{
"description": "Fail",
"valid": true,
"data": 5
}
]
}
EOF

"$1" test "$TMP/schemas/test.json" --verbose --resolve "$TMP" 1> "$TMP/output.txt" 2>&1 \
&& CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
Importing schema into the resolution context: $(realpath "$TMP")/schemas/schema.json
Importing schema into the resolution context: $(realpath "$TMP")/schemas/test.json
error: Cannot determine the base dialect of the schema
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
4 changes: 3 additions & 1 deletion vendor/jsontoolkit/src/jsonschema/reference.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e77f2e5

Please sign in to comment.