diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 018d88c..44b19af 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,6 +37,7 @@ add_jsonschema_test_unix(validate/fail_relative_external_ref_missing) add_jsonschema_test_unix(validate/fail_resolve_enoent) add_jsonschema_test_unix(validate/fail_resolve_directory_with_invalid_json) add_jsonschema_test_unix(validate/fail_resolve_invalid_json) +add_jsonschema_test_unix(validate/fail_resolve_missing_open_brace) add_jsonschema_test_unix(validate/fail_schema_directory) add_jsonschema_test_unix(validate/fail_schema_enoent) add_jsonschema_test_unix(validate/fail_schema_invalid_json) diff --git a/test/validate/fail_resolve_missing_open_brace.sh b/test/validate/fail_resolve_missing_open_brace.sh new file mode 100755 index 0000000..05c3db1 --- /dev/null +++ b/test/validate/fail_resolve_missing_open_brace.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << 'EOF' > "$TMP/schema.json" +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "string" +} +EOF + +cat << 'EOF' > "$TMP/instance.json" +"foo" +EOF + +cat << 'EOF' > "$TMP/invalid.json" + + "$schema": "http://json-schema.org/draft-04/schema#", + "$id": "https://example.com", + "type": "string" +} +EOF + +"$1" validate "$TMP/schema.json" "$TMP/instance.json" \ + --resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \ + && CODE="$?" || CODE="$?" +test "$CODE" = "1" || exit 1 + +cat << EOF > "$TMP/expected.txt" +error: Failed to parse the JSON document at line 2 and column 3 + $(realpath "$TMP")/invalid.json +EOF + +diff "$TMP/stderr.txt" "$TMP/expected.txt"