Skip to content

Commit

Permalink
Support the $comment keyword in test cases (#124)
Browse files Browse the repository at this point in the history
See: #110
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jul 15, 2024
1 parent ba5a588 commit b789eea
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/test.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ To create a test definition, you must write JSON documents that look like this:
```json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$comment": "An arbitrary comment! Put whatever you want here",
"tests": [
{
"description": "The empty object is valid",
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ add_jsonschema_test_unix(test/pass_empty)
add_jsonschema_test_unix(test/pass_empty_verbose)
add_jsonschema_test_unix(test/pass_single_resolve)
add_jsonschema_test_unix(test/pass_single_resolve_verbose)
add_jsonschema_test_unix(test/pass_single_comment_verbose)
add_jsonschema_test_unix(test/pass_single_no_description_verbose)
add_jsonschema_test_unix(test/pass_single_no_test_description_verbose)
add_jsonschema_test_unix(test/pass_multi_directory_resolve)
Expand Down
44 changes: 44 additions & 0 deletions test/test/pass_single_comment_verbose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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": "string"
}
EOF

cat << 'EOF' > "$TMP/test.json"
{
"$schema": "https://example.com",
"$comment": "A random comment",
"tests": [
{
"valid": true,
"data": "foo"
},
{
"valid": false,
"data": 1
}
]
}
EOF

"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1

cat << EOF > "$TMP/expected.txt"
Importing schema into the resolution context: $(realpath "$TMP")/schema.json
$(realpath "$TMP")/test.json:
1/2 PASS <no description>
2/2 PASS <no description>
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"

0 comments on commit b789eea

Please sign in to comment.