Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test output incorrectly printing paths in a single line #256

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/command_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ auto sourcemeta::jsonschema::cli::test(
}
}

if (!verbose && result) {
if (!verbose && pass_count == total) {
std::cout << " PASS " << pass_count << "/" << total << "\n";
}
}
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ 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)
add_jsonschema_test_unix(test/fail_false_single_resolve_verbose)
add_jsonschema_test_unix(test/fail_multi_test)
add_jsonschema_test_unix(test/fail_multi_resolve)
add_jsonschema_test_unix(test/fail_multi_resolve_verbose)
add_jsonschema_test_unix(test/fail_unresolvable)
Expand Down
80 changes: 80 additions & 0 deletions test/test/fail_multi_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/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

mkdir "$TMP/tests"

cat << 'EOF' > "$TMP/tests/1.json"
{
"target": "https://example.com",
"tests": [
{
"description": "First test",
"valid": true,
"data": "foo"
},
{
"description": "First failure",
"valid": true,
"data": 1
}
]
}
EOF

cat << 'EOF' > "$TMP/tests/2.json"
{
"target": "https://example.com",
"tests": [
{
"description": "Invalid type",
"valid": false,
"data": 1
}
]
}
EOF

cat << 'EOF' > "$TMP/tests/3.json"
{
"target": "https://example.com",
"tests": [
{
"description": "Invalid type",
"valid": false,
"data": []
}
]
}
EOF

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

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/tests/1.json:
2/2 FAIL First failure

error: Schema validation failure
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
$(realpath "$TMP")/tests/2.json: PASS 1/1
$(realpath "$TMP")/tests/3.json: PASS 1/1
EOF

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