Skip to content

Commit 5728172

Browse files
authored
Extend SimpleOutput::Entry with a schema_location field (#475)
Fixes: #474 Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent b6dbce3 commit 5728172

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/compiler/compile_output_simple.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ auto SimpleOutput::operator()(
9999
this->output.push_back(
100100
{describe(result, step, evaluate_path, instance_location, this->instance_,
101101
annotation),
102-
instance_location, std::move(effective_evaluate_path)});
102+
instance_location, std::move(effective_evaluate_path),
103+
step.keyword_location});
103104
}
104105

105106
auto SimpleOutput::stacktrace(std::ostream &stream,

src/compiler/include/sourcemeta/blaze/compiler_output.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class SOURCEMETA_BLAZE_COMPILER_EXPORT SimpleOutput {
8181
const std::string message;
8282
const sourcemeta::core::WeakPointer instance_location;
8383
const sourcemeta::core::WeakPointer evaluate_path;
84+
const std::reference_wrapper<const std::string> schema_location;
8485
};
8586

8687
auto operator()(const EvaluationType type, const bool result,

test/compiler/compiler_output_simple_test.cc

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
#include <sourcemeta/core/jsonschema.h>
88

99
#define EXPECT_OUTPUT(traces, index, expected_instance_location, \
10-
expected_evaluate_path, expected_message) \
10+
expected_evaluate_path, expected_schema_location, \
11+
expected_message) \
1112
EXPECT_TRUE(traces.size() > index); \
1213
EXPECT_EQ(traces.at((index)).message, (expected_message)); \
1314
EXPECT_EQ(sourcemeta::core::to_string(traces.at((index)).instance_location), \
1415
expected_instance_location); \
1516
EXPECT_EQ(sourcemeta::core::to_string(traces.at((index)).evaluate_path), \
16-
expected_evaluate_path);
17+
expected_evaluate_path); \
18+
EXPECT_EQ(traces.at((index)).schema_location.get(), \
19+
(expected_schema_location));
1720

1821
#define EXPECT_ANNOTATION_COUNT(output, expected_count) \
1922
EXPECT_EQ(output.annotations().size(), (expected_count));
@@ -116,9 +119,11 @@ TEST(Compiler_output_simple, fail_meaningless_if_1) {
116119

117120
EXPECT_OUTPUT(
118121
traces, 0, "/foo/~1baz", "/properties/foo/unevaluatedProperties",
122+
"#/properties/foo/unevaluatedProperties",
119123
"The object value was not expected to define the property \"/baz\"");
120124
EXPECT_OUTPUT(
121125
traces, 1, "/foo", "/properties/foo/unevaluatedProperties",
126+
"#/properties/foo/unevaluatedProperties",
122127
"The object value was not expected to define unevaluated properties");
123128

124129
EXPECT_ANNOTATION_COUNT(output, 0);
@@ -209,7 +214,7 @@ TEST(Compiler_output_simple, fail_string) {
209214

210215
EXPECT_EQ(traces.size(), 1);
211216
EXPECT_OUTPUT(
212-
traces, 0, "", "/type",
217+
traces, 0, "", "/type", "#/type",
213218
"The value was expected to be of type string but it was of type integer");
214219

215220
EXPECT_ANNOTATION_COUNT(output, 0);
@@ -244,7 +249,7 @@ TEST(Compiler_output_simple, fail_string_over_ref) {
244249

245250
EXPECT_EQ(traces.size(), 1);
246251
EXPECT_OUTPUT(
247-
traces, 0, "", "/$ref/type",
252+
traces, 0, "", "/$ref/type", "#/$defs/string/type",
248253
"The value was expected to be of type string but it was of type integer");
249254
EXPECT_ANNOTATION_COUNT(output, 0);
250255
}
@@ -280,7 +285,7 @@ TEST(Compiler_output_simple, fail_string_with_matching_base) {
280285

281286
EXPECT_EQ(traces.size(), 1);
282287
EXPECT_OUTPUT(
283-
traces, 0, "", "/type",
288+
traces, 0, "", "/type", "#/$defs/string/type",
284289
"The value was expected to be of type string but it was of type integer");
285290
EXPECT_ANNOTATION_COUNT(output, 0);
286291
}
@@ -315,7 +320,7 @@ TEST(Compiler_output_simple, fail_string_with_non_matching_base) {
315320

316321
EXPECT_EQ(traces.size(), 1);
317322
EXPECT_OUTPUT(
318-
traces, 0, "", "/$ref/type",
323+
traces, 0, "", "/$ref/type", "#/$defs/string/type",
319324
"The value was expected to be of type string but it was of type integer");
320325
EXPECT_ANNOTATION_COUNT(output, 0);
321326
}
@@ -346,7 +351,7 @@ TEST(Compiler_output_simple, fail_oneof_1) {
346351
output.cend()};
347352

348353
EXPECT_EQ(traces.size(), 1);
349-
EXPECT_OUTPUT(traces, 0, "", "/oneOf",
354+
EXPECT_OUTPUT(traces, 0, "", "/oneOf", "#/oneOf",
350355
"The string value was expected to validate against one and "
351356
"only one of the 2 given subschemas");
352357
EXPECT_ANNOTATION_COUNT(output, 0);
@@ -377,7 +382,7 @@ TEST(Compiler_output_simple, fail_not_1) {
377382
output.cend()};
378383

379384
EXPECT_EQ(traces.size(), 1);
380-
EXPECT_OUTPUT(traces, 0, "", "/not",
385+
EXPECT_OUTPUT(traces, 0, "", "/not", "#/not",
381386
"The string value was expected to not validate against the "
382387
"given subschema, but it did");
383388
EXPECT_ANNOTATION_COUNT(output, 0);
@@ -410,7 +415,7 @@ TEST(Compiler_output_simple, fail_not_not_1) {
410415
output.cend()};
411416

412417
EXPECT_EQ(traces.size(), 1);
413-
EXPECT_OUTPUT(traces, 0, "", "/not",
418+
EXPECT_OUTPUT(traces, 0, "", "/not", "#/not",
414419
"The integer value was expected to not validate against the "
415420
"given subschema, but it did");
416421
EXPECT_ANNOTATION_COUNT(output, 0);
@@ -450,7 +455,7 @@ TEST(Compiler_output_simple, fail_anyof_1) {
450455

451456
EXPECT_EQ(traces.size(), 1);
452457
EXPECT_OUTPUT(
453-
traces, 0, "", "/allOf/1/type",
458+
traces, 0, "", "/allOf/1/type", "#/allOf/1/type",
454459
"The value was expected to be of type integer but it was of type object");
455460
EXPECT_ANNOTATION_COUNT(output, 0);
456461
}
@@ -483,7 +488,7 @@ TEST(Compiler_output_simple, fail_anyof_2) {
483488
output.cend()};
484489

485490
EXPECT_EQ(traces.size(), 1);
486-
EXPECT_OUTPUT(traces, 0, "", "/anyOf",
491+
EXPECT_OUTPUT(traces, 0, "", "/anyOf", "#/anyOf",
487492
"The object value was expected to validate against at least "
488493
"one of the 2 given subschemas");
489494
EXPECT_ANNOTATION_COUNT(output, 0);

0 commit comments

Comments
 (0)