Skip to content

Commit

Permalink
Extend --trace to print out keyword location URIs (#194)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Nov 7, 2024
1 parent cbd0667 commit 200fec4
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ jsontoolkit https://github.com/sourcemeta/jsontoolkit 7a398224cc2e76ea9ae8541a87
hydra https://github.com/sourcemeta/hydra a4a74f3cabd32f2f829f449d67339dac33f9910e
alterschema https://github.com/sourcemeta/alterschema 92e370ce9c1f0582014b54d43e388ee012dfe13d
jsonbinpack https://github.com/sourcemeta/jsonbinpack d777179441d3c703e1fda1187742541aa26836b5
blaze https://github.com/sourcemeta/blaze a5b3c8e4d77a0b88e4a93f304ae75e711b30a2e6
blaze https://github.com/sourcemeta/blaze 4db8309470369332d3d0658ade9402a37abe418e
10 changes: 9 additions & 1 deletion src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ auto print(const sourcemeta::blaze::ErrorOutput &output, std::ostream &stream)

auto print(const sourcemeta::blaze::TraceOutput &output, std::ostream &stream)
-> void {
for (const auto &entry : output) {
for (auto iterator = output.cbegin(); iterator != output.cend(); iterator++) {
const auto &entry{*iterator};

if (entry.evaluate_path.empty()) {
continue;
}
Expand All @@ -217,6 +219,12 @@ auto print(const sourcemeta::blaze::TraceOutput &output, std::ostream &stream)
stream << " at \"";
sourcemeta::jsontoolkit::stringify(entry.instance_location, stream);
stream << "\"\n";
stream << " at keyword location \"" << entry.keyword_location << "\"\n";

// To make it easier to read
if (std::next(iterator) != output.cend()) {
stream << "\n";
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions test/metaschema/fail_trace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,61 @@ test "$CODE" = "1" || exit 1
cat << 'EOF' > "$TMP/expected-1.txt"
-> (push) "/dependencies"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/dependencies"
<- (pass) "/dependencies"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/dependencies"
-> (push) "/properties"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/properties"
-> (push) "/properties/$schema/type"
at "/$schema"
at keyword location "http://json-schema.org/draft-04/schema#/properties/$schema/type"
<- (pass) "/properties/$schema/type"
at "/$schema"
at keyword location "http://json-schema.org/draft-04/schema#/properties/$schema/type"
-> (push) "/properties/minimum/type"
at "/minimum"
at keyword location "http://json-schema.org/draft-04/schema#/properties/minimum/type"
<- (fail) "/properties/minimum/type"
at "/minimum"
at keyword location "http://json-schema.org/draft-04/schema#/properties/minimum/type"
<- (fail) "/properties"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/properties"
EOF

cat << 'EOF' > "$TMP/expected-2.txt"
-> (push) "/dependencies"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/dependencies"
<- (pass) "/dependencies"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/dependencies"
-> (push) "/properties"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/properties"
-> (push) "/properties/minimum/type"
at "/minimum"
at keyword location "http://json-schema.org/draft-04/schema#/properties/minimum/type"
<- (fail) "/properties/minimum/type"
at "/minimum"
at keyword location "http://json-schema.org/draft-04/schema#/properties/minimum/type"
<- (fail) "/properties"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/properties"
EOF

diff "$TMP/output.txt" "$TMP/expected-1.txt" || \
Expand Down
15 changes: 15 additions & 0 deletions test/metaschema/pass_trace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,35 @@ EOF
cat << 'EOF' > "$TMP/expected.txt"
-> (push) "/dependencies"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/dependencies"
<- (pass) "/dependencies"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/dependencies"
-> (push) "/properties"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/properties"
-> (push) "/properties/$schema/type"
at "/$schema"
at keyword location "http://json-schema.org/draft-04/schema#/properties/$schema/type"
<- (pass) "/properties/$schema/type"
at "/$schema"
at keyword location "http://json-schema.org/draft-04/schema#/properties/$schema/type"
<- (pass) "/properties"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/properties"
-> (push) "/type"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/type"
<- (pass) "/type"
at ""
at keyword location "http://json-schema.org/draft-04/schema#/type"
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
3 changes: 3 additions & 0 deletions test/validate/fail_trace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ test "$CODE" = "1" || exit 1
cat << EOF > "$TMP/expected.txt"
-> (push) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
<- (fail) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
3 changes: 3 additions & 0 deletions test/validate/pass_trace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ EOF
cat << EOF > "$TMP/expected.txt"
-> (push) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
<- (pass) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
EOF

diff "$TMP/output.txt" "$TMP/expected.txt"
27 changes: 23 additions & 4 deletions vendor/blaze/src/compiler/compile_output_trace.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 1 addition & 10 deletions vendor/blaze/src/compiler/default_compiler_draft4.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion vendor/blaze/src/evaluator/evaluator.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 200fec4

Please sign in to comment.