Skip to content

Commit b7d32ce

Browse files
authored
Remove the SimpleOutput::stacktrace method (#513)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent b5e41dc commit b7d32ce

5 files changed

Lines changed: 22 additions & 108 deletions

File tree

src/linter/valid_default.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,16 @@ auto ValidDefault::condition(
7676
}
7777

7878
std::ostringstream message;
79-
output.stacktrace(message);
79+
for (const auto &entry : output) {
80+
message << entry.message << "\n";
81+
message << " at instance location \"";
82+
sourcemeta::core::stringify(entry.instance_location, message);
83+
message << "\"\n";
84+
message << " at evaluate path \"";
85+
sourcemeta::core::stringify(entry.evaluate_path, message);
86+
message << "\"\n";
87+
}
88+
8089
return {{{"default"}}, std::move(message).str()};
8190
}
8291

src/linter/valid_examples.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ auto ValidExamples::condition(
7979
if (!result) {
8080
std::ostringstream message;
8181
message << "Invalid example instance at index " << cursor << "\n";
82-
output.stacktrace(message, " ");
82+
for (const auto &entry : output) {
83+
message << " " << entry.message << "\n";
84+
message << " "
85+
<< " at instance location \"";
86+
sourcemeta::core::stringify(entry.instance_location, message);
87+
message << "\"\n";
88+
message << " "
89+
<< " at evaluate path \"";
90+
sourcemeta::core::stringify(entry.evaluate_path, message);
91+
message << "\"\n";
92+
}
93+
8394
return {{{"examples", cursor}}, std::move(message).str()};
8495
}
8596

src/output/include/sourcemeta/blaze/output_simple.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ class SOURCEMETA_BLAZE_OUTPUT_EXPORT SimpleOutput {
114114
const std::reference_wrapper<const std::string> schema_location;
115115
};
116116

117-
auto stacktrace(std::ostream &stream,
118-
const std::string &indentation = "") const -> void;
119-
120117
private:
121118
// Exporting symbols that depends on the standard C++ library is considered
122119
// safe.

src/output/output_simple.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,4 @@ auto SimpleOutput::operator()(
103103
step.keyword_location});
104104
}
105105

106-
auto SimpleOutput::stacktrace(std::ostream &stream,
107-
const std::string &indentation) const -> void {
108-
for (const auto &entry : *this) {
109-
stream << indentation << entry.message << "\n";
110-
stream << indentation << " at instance location \"";
111-
sourcemeta::core::stringify(entry.instance_location, stream);
112-
stream << "\"\n";
113-
stream << indentation << " at evaluate path \"";
114-
sourcemeta::core::stringify(entry.evaluate_path, stream);
115-
stream << "\"\n";
116-
}
117-
}
118-
119106
} // namespace sourcemeta::blaze

test/output/output_simple_test.cc

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -858,93 +858,3 @@ TEST(Output_simple, annotations_failure_1) {
858858
EXPECT_FALSE(result);
859859
EXPECT_ANNOTATION_COUNT(output, 0);
860860
}
861-
862-
TEST(Output_simple, fail_stacktrace) {
863-
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
864-
"$schema": "https://json-schema.org/draft/2019-09/schema",
865-
"properties": {
866-
"foo": { "type": "object", "unevaluatedProperties": false },
867-
"bar": {
868-
"additionalProperties": {
869-
"if": {
870-
"type": "object",
871-
"required": [ "$ref" ]
872-
}
873-
}
874-
}
875-
}
876-
})JSON")};
877-
878-
const auto schema_template{sourcemeta::blaze::compile(
879-
schema, sourcemeta::core::schema_official_walker,
880-
sourcemeta::core::schema_official_resolver,
881-
sourcemeta::blaze::default_schema_compiler)};
882-
883-
const sourcemeta::core::JSON instance{sourcemeta::core::parse_json(R"JSON({
884-
"foo": { "/baz": 1 },
885-
"bar": { "qux": {} }
886-
})JSON")};
887-
888-
sourcemeta::blaze::SimpleOutput output{instance};
889-
sourcemeta::blaze::Evaluator evaluator;
890-
const auto result{
891-
evaluator.validate(schema_template, instance, std::ref(output))};
892-
EXPECT_FALSE(result);
893-
894-
std::ostringstream message;
895-
output.stacktrace(message);
896-
EXPECT_EQ(
897-
message.str(),
898-
R"JSON(The object value was not expected to define the property "/baz"
899-
at instance location "/foo/~1baz"
900-
at evaluate path "/properties/foo/unevaluatedProperties"
901-
The object value was not expected to define unevaluated properties
902-
at instance location "/foo"
903-
at evaluate path "/properties/foo/unevaluatedProperties"
904-
)JSON");
905-
}
906-
907-
TEST(Output_simple, fail_stacktrace_with_indentation) {
908-
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
909-
"$schema": "https://json-schema.org/draft/2019-09/schema",
910-
"properties": {
911-
"foo": { "type": "object", "unevaluatedProperties": false },
912-
"bar": {
913-
"additionalProperties": {
914-
"if": {
915-
"type": "object",
916-
"required": [ "$ref" ]
917-
}
918-
}
919-
}
920-
}
921-
})JSON")};
922-
923-
const auto schema_template{sourcemeta::blaze::compile(
924-
schema, sourcemeta::core::schema_official_walker,
925-
sourcemeta::core::schema_official_resolver,
926-
sourcemeta::blaze::default_schema_compiler)};
927-
928-
const sourcemeta::core::JSON instance{sourcemeta::core::parse_json(R"JSON({
929-
"foo": { "/baz": 1 },
930-
"bar": { "qux": {} }
931-
})JSON")};
932-
933-
sourcemeta::blaze::SimpleOutput output{instance};
934-
sourcemeta::blaze::Evaluator evaluator;
935-
const auto result{
936-
evaluator.validate(schema_template, instance, std::ref(output))};
937-
EXPECT_FALSE(result);
938-
939-
std::ostringstream message;
940-
output.stacktrace(message, " ");
941-
EXPECT_EQ(
942-
message.str(),
943-
R"JSON( The object value was not expected to define the property "/baz"
944-
at instance location "/foo/~1baz"
945-
at evaluate path "/properties/foo/unevaluatedProperties"
946-
The object value was not expected to define unevaluated properties
947-
at instance location "/foo"
948-
at evaluate path "/properties/foo/unevaluatedProperties"
949-
)JSON");
950-
}

0 commit comments

Comments
 (0)