Skip to content
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
4 changes: 3 additions & 1 deletion src/command_fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ auto sourcemeta::jsonschema::fmt(const sourcemeta::core::Options &options)
<< "\n";
}

throw Fail{EXIT_FAILURE};
// Report a different exit code for formatting check failures, to
// distinguish them from other errors
throw Fail{2};
}
}
16 changes: 12 additions & 4 deletions src/command_lint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
output << "\n";
}
} else {
result = false;
// Exception was caught - exit immediately with error code 1
throw Fail{EXIT_FAILURE};
}
}
} else {
Expand All @@ -263,7 +264,8 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
if (subresult.first) {
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
// Return 2 for logical lint failures
return 2;
}
} catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) {
throw FileError<sourcemeta::core::SchemaUnknownBaseDialectError>(
Expand All @@ -274,8 +276,12 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
}
});

if (wrapper_result != EXIT_SUCCESS) {
if (wrapper_result == 2) {
// Logical lint failure
result = false;
} else if (wrapper_result != EXIT_SUCCESS) {
// Exception was caught - exit immediately with error code 1
throw Fail{EXIT_FAILURE};
}
}
}
Expand All @@ -299,6 +305,8 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
}

if (!result) {
throw Fail{EXIT_FAILURE};
// Report a different exit code for linting failures, to
// distinguish them from other errors
throw Fail{2};
}
}
4 changes: 3 additions & 1 deletion src/command_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ auto sourcemeta::jsonschema::test(const sourcemeta::core::Options &options)
}

if (!result) {
throw Fail{EXIT_FAILURE};
// Report a different exit code for test failures, to
// distinguish them from other errors
throw Fail{2};
}
}
2 changes: 1 addition & 1 deletion test/format/fail_check_many.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cat << 'EOF' > "$TMP/schemas/3.json"
EOF

"$1" fmt "$TMP/schemas" --check >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
fail: $(realpath "$TMP")/schemas/1.json
Expand Down
2 changes: 1 addition & 1 deletion test/format/fail_check_many_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cat << 'EOF' > "$TMP/schemas/3.json"
EOF

"$1" fmt "$TMP/schemas" --check --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.json"
{
Expand Down
2 changes: 1 addition & 1 deletion test/format/fail_check_single.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cat << 'EOF' > "$TMP/schema.json"
EOF

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

cat << EOF > "$TMP/expected.txt"
fail: $(realpath "$TMP")/schema.json
Expand Down
2 changes: 1 addition & 1 deletion test/format/fail_check_single_indentation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cat << 'EOF' > "$TMP/schema.json"
EOF

"$1" fmt "$TMP/schema.json" --indentation 4 --check >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
fail: $(realpath "$TMP")/schema.json
Expand Down
2 changes: 1 addition & 1 deletion test/format/fail_check_single_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

"$1" fmt "$TMP/this/is/a/very/very/very/long/path/schema.json" \
--check --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.json"
{
Expand Down
2 changes: 1 addition & 1 deletion test/format/fail_check_single_json_indentation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

"$1" fmt "$TMP/this/is/a/very/very/very/long/path/schema.json" \
--check --json --indentation 4 >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.json"
{
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.json:4:3:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.json:6:7:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_default_dialect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cd "$TMP"
"$1" lint "$TMP/schema.json" \
--default-dialect "http://json-schema.org/draft-04/schema#" \
>"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.json:3:3:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_default_dialect_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ EOF
cd "$TMP"
"$1" lint "$TMP/schema.json" --verbose \
>"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
Using configuration file: $(realpath "$TMP")/jsonschema.json
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_default_dialect_config_relative.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ EOF
cd "$TMP"
"$1" lint schema.json --verbose \
>"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
Using configuration file: $(realpath "$TMP")/jsonschema.json
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_directory_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cat << 'EOF' > "$TMP/schemas/bar.json"
EOF

"$1" lint "$TMP/schemas" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.json"
{
Expand Down
1 change: 0 additions & 1 deletion test/lint/fail_lint_directory_unresolvable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ error: Could not resolve the reference to an external schema
at file path $(realpath "$TMP")/baz.json

This is likely because you forgot to import such schema using \`--resolve/-r\`
Linting: $(realpath "$TMP")/foo.json
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
1 change: 0 additions & 1 deletion test/lint/fail_lint_directory_unresolvable_dialect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ error: Could not resolve the metaschema of the schema
at file path $(realpath "$TMP")/baz.json

This is likely because you forgot to import such schema using \`--resolve/-r\`
Linting: $(realpath "$TMP")/foo.json
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
1 change: 0 additions & 1 deletion test/lint/fail_lint_directory_unresolvable_fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ error: Could not resolve the reference to an external schema
at file path $(realpath "$TMP")/baz.json

This is likely because you forgot to import such schema using \`--resolve/-r\`
Linting: $(realpath "$TMP")/foo.json
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
2 changes: 1 addition & 1 deletion test/lint/fail_lint_disable_many.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" --exclude enum_to_const -x enum_with_type >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.json:4:3:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_disable_one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" --exclude enum_to_const >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.json:4:3:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_disable_one_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" --verbose --exclude enum_to_const >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
Disabling rule: enum_to_const
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_disable_unknown_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" --verbose --exclude foo_bar >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
warning: Cannot exclude unknown rule: foo_bar
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.json:6:21:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_invalid_embedded_resource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat "$TMP/stderr.txt"

Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cat << 'EOF' > "$TMP/schema.json"
EOF

"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.json"
{
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.json:4:3:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_with_id.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << 'EOF' > "$TMP/expected.txt"
schema.json:4:3:
Expand Down
2 changes: 1 addition & 1 deletion test/lint/fail_lint_yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EOF

cd "$TMP"
"$1" lint "$TMP/schema.yaml" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
test "$CODE" = "2" || exit 1

cat << EOF > "$TMP/expected.txt"
schema.yaml:3:1:
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_anyof.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ EOF

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

cat "$TMP/output.txt"

Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_false_single_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/test.json:
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_false_single_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
Detecting schema resources from file: $(realpath "$TMP")/schema.json
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_multi_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/test.json:
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_multi_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
Detecting schema resources from file: $(realpath "$TMP")/schema.json
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_multi_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/tests/1.json:
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_resolve_fragment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/test.json:
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_single_resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
$(realpath "$TMP")/test.json:
Expand Down
2 changes: 1 addition & 1 deletion test/test/fail_true_single_resolve_verbose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ EOF

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

cat << EOF > "$TMP/expected.txt"
Detecting schema resources from file: $(realpath "$TMP")/schema.json
Expand Down