Skip to content

Commit b789eea

Browse files
authored
Support the $comment keyword in test cases (#124)
See: #110 Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent ba5a588 commit b789eea

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

docs/test.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ To create a test definition, you must write JSON documents that look like this:
3030
```json
3131
{
3232
"$schema": "http://json-schema.org/draft-04/schema#",
33+
"$comment": "An arbitrary comment! Put whatever you want here",
3334
"tests": [
3435
{
3536
"description": "The empty object is valid",

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ add_jsonschema_test_unix(test/pass_empty)
8787
add_jsonschema_test_unix(test/pass_empty_verbose)
8888
add_jsonschema_test_unix(test/pass_single_resolve)
8989
add_jsonschema_test_unix(test/pass_single_resolve_verbose)
90+
add_jsonschema_test_unix(test/pass_single_comment_verbose)
9091
add_jsonschema_test_unix(test/pass_single_no_description_verbose)
9192
add_jsonschema_test_unix(test/pass_single_no_test_description_verbose)
9293
add_jsonschema_test_unix(test/pass_multi_directory_resolve)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.json"
11+
{
12+
"id": "https://example.com",
13+
"$schema": "http://json-schema.org/draft-04/schema#",
14+
"type": "string"
15+
}
16+
EOF
17+
18+
cat << 'EOF' > "$TMP/test.json"
19+
{
20+
"$schema": "https://example.com",
21+
"$comment": "A random comment",
22+
"tests": [
23+
{
24+
"valid": true,
25+
"data": "foo"
26+
},
27+
{
28+
"valid": false,
29+
"data": 1
30+
}
31+
]
32+
}
33+
EOF
34+
35+
"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1
36+
37+
cat << EOF > "$TMP/expected.txt"
38+
Importing schema into the resolution context: $(realpath "$TMP")/schema.json
39+
$(realpath "$TMP")/test.json:
40+
1/2 PASS <no description>
41+
2/2 PASS <no description>
42+
EOF
43+
44+
diff "$TMP/output.txt" "$TMP/expected.txt"

0 commit comments

Comments
 (0)