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
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
core https://github.com/sourcemeta/core 1e83e267f00bd5686d9546fb20877bf6e4b20dc5
core https://github.com/sourcemeta/core 1f23fc7df56f41ceb140719bbcf94ee6f4d6f066
jsonschema-test-suite https://github.com/json-schema-org/JSON-Schema-Test-Suite 15e4505bf689de5d30c29d50782bb48fa465c93f
8 changes: 6 additions & 2 deletions src/linter/include/sourcemeta/blaze/linter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class SOURCEMETA_BLAZE_LINTER_EXPORT ValidExamples final
const sourcemeta::core::SchemaWalker &,
const sourcemeta::core::SchemaResolver &) const
-> sourcemeta::core::SchemaTransformRule::Result override;
auto transform(sourcemeta::core::JSON &) const -> void override;
auto transform(sourcemeta::core::JSON &,
const sourcemeta::core::SchemaTransformRule::Result &) const
-> void override;

private:
// Exporting symbols that depends on the standard C++ library is considered
Expand Down Expand Up @@ -66,7 +68,9 @@ class SOURCEMETA_BLAZE_LINTER_EXPORT ValidDefault final
const sourcemeta::core::SchemaWalker &,
const sourcemeta::core::SchemaResolver &) const
-> sourcemeta::core::SchemaTransformRule::Result override;
auto transform(sourcemeta::core::JSON &) const -> void override;
auto transform(sourcemeta::core::JSON &,
const sourcemeta::core::SchemaTransformRule::Result &) const
-> void override;

private:
// Exporting symbols that depends on the standard C++ library is considered
Expand Down
6 changes: 4 additions & 2 deletions src/linter/valid_default.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ auto ValidDefault::condition(

std::ostringstream message;
output.stacktrace(message);
return message.str();
return {{{"default"}}, std::move(message).str()};
}

auto ValidDefault::transform(sourcemeta::core::JSON &schema) const -> void {
auto ValidDefault::transform(
sourcemeta::core::JSON &schema,
const sourcemeta::core::SchemaTransformRule::Result &) const -> void {
schema.erase("default");
}

Expand Down
6 changes: 4 additions & 2 deletions src/linter/valid_examples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ auto ValidExamples::condition(
std::ostringstream message;
message << "Invalid example instance at index " << cursor << "\n";
output.stacktrace(message, " ");
return message.str();
return {{{"examples", cursor}}, std::move(message).str()};
}

cursor += 1;
Expand All @@ -91,7 +91,9 @@ auto ValidExamples::condition(
return false;
}

auto ValidExamples::transform(sourcemeta::core::JSON &schema) const -> void {
auto ValidExamples::transform(
sourcemeta::core::JSON &schema,
const sourcemeta::core::SchemaTransformRule::Result &) const -> void {
schema.erase("examples");
}

Expand Down
64 changes: 44 additions & 20 deletions test/linter/linter_valid_default_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <sourcemeta/core/json.h>
#include <sourcemeta/core/jsonschema.h>

static auto transformer_callback_error(const sourcemeta::core::Pointer &,
const std::string_view,
const std::string_view,
const std::string_view) -> void {
static auto transformer_callback_error(
const sourcemeta::core::Pointer &, const std::string_view,
const std::string_view,
const sourcemeta::core::SchemaTransformRule::Result &) -> void {
throw std::runtime_error("The transform callback must not be called");
}

Expand All @@ -28,14 +28,14 @@ TEST(Linter, valid_default_error_message_without_id_nested) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -46,12 +46,18 @@ TEST(Linter, valid_default_error_message_without_id_nested) {
EXPECT_EQ(std::get<1>(entries.at(0)), "blaze/valid_default");
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only set a `default` value that validates against the schema");
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(
std::get<3>(entries.at(0)),
std::get<3>(entries.at(0)).description.value(),
R"TXT(The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/default");
}

TEST(Linter, valid_default_error_message_without_id_flat) {
Expand All @@ -66,14 +72,14 @@ TEST(Linter, valid_default_error_message_without_id_flat) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -83,12 +89,18 @@ TEST(Linter, valid_default_error_message_without_id_flat) {
EXPECT_EQ(std::get<1>(entries.at(0)), "blaze/valid_default");
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only set a `default` value that validates against the schema");
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(
std::get<3>(entries.at(0)),
std::get<3>(entries.at(0)).description.value(),
R"TXT(The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/default");
}

TEST(Linter, valid_default_error_message_with_id_nested) {
Expand All @@ -108,14 +120,14 @@ TEST(Linter, valid_default_error_message_with_id_nested) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -126,12 +138,18 @@ TEST(Linter, valid_default_error_message_with_id_nested) {
EXPECT_EQ(std::get<1>(entries.at(0)), "blaze/valid_default");
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only set a `default` value that validates against the schema");
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(
std::get<3>(entries.at(0)),
std::get<3>(entries.at(0)).description.value(),
R"TXT(The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/default");
}

TEST(Linter, valid_default_error_message_with_id_flat) {
Expand All @@ -147,14 +165,14 @@ TEST(Linter, valid_default_error_message_with_id_flat) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -164,12 +182,18 @@ TEST(Linter, valid_default_error_message_with_id_flat) {
EXPECT_EQ(std::get<1>(entries.at(0)), "blaze/valid_default");
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only set a `default` value that validates against the schema");
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(
std::get<3>(entries.at(0)),
std::get<3>(entries.at(0)).description.value(),
R"TXT(The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/default");
}

TEST(Linter, valid_default_1) {
Expand Down
64 changes: 44 additions & 20 deletions test/linter/linter_valid_examples_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <sourcemeta/core/json.h>
#include <sourcemeta/core/jsonschema.h>

static auto transformer_callback_error(const sourcemeta::core::Pointer &,
const std::string_view,
const std::string_view,
const std::string_view) -> void {
static auto transformer_callback_error(
const sourcemeta::core::Pointer &, const std::string_view,
const std::string_view,
const sourcemeta::core::SchemaTransformRule::Result &) -> void {
throw std::runtime_error("The transform callback must not be called");
}

Expand All @@ -28,14 +28,14 @@ TEST(Linter, valid_examples_error_message_without_id_nested) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -47,12 +47,18 @@ TEST(Linter, valid_examples_error_message_without_id_nested) {
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only include instances in the `examples` array that validate "
"against the schema");
EXPECT_EQ(std::get<3>(entries.at(0)),
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(std::get<3>(entries.at(0)).description.value(),
R"TXT(Invalid example instance at index 0
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/examples/0");
}

TEST(Linter, valid_examples_error_message_without_id_flat) {
Expand All @@ -67,14 +73,14 @@ TEST(Linter, valid_examples_error_message_without_id_flat) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -85,12 +91,18 @@ TEST(Linter, valid_examples_error_message_without_id_flat) {
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only include instances in the `examples` array that validate "
"against the schema");
EXPECT_EQ(std::get<3>(entries.at(0)),
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(std::get<3>(entries.at(0)).description.value(),
R"TXT(Invalid example instance at index 0
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/examples/0");
}

TEST(Linter, valid_examples_error_message_with_id_nested) {
Expand All @@ -110,14 +122,14 @@ TEST(Linter, valid_examples_error_message_with_id_nested) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -129,12 +141,18 @@ TEST(Linter, valid_examples_error_message_with_id_nested) {
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only include instances in the `examples` array that validate "
"against the schema");
EXPECT_EQ(std::get<3>(entries.at(0)),
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(std::get<3>(entries.at(0)).description.value(),
R"TXT(Invalid example instance at index 0
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/examples/0");
}

TEST(Linter, valid_examples_error_message_with_id_flat) {
Expand All @@ -150,14 +168,14 @@ TEST(Linter, valid_examples_error_message_with_id_flat) {
})JSON")};

std::vector<std::tuple<sourcemeta::core::Pointer, std::string, std::string,
std::string>>
sourcemeta::core::SchemaTransformRule::Result>>
entries;
const auto result =
bundle.check(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver,
[&entries](const auto &pointer, const auto &name,
const auto &message, const auto &description) {
entries.emplace_back(pointer, name, message, description);
const auto &message, const auto &outcome) {
entries.emplace_back(pointer, name, message, outcome);
});

EXPECT_FALSE(result.first);
Expand All @@ -168,12 +186,18 @@ TEST(Linter, valid_examples_error_message_with_id_flat) {
EXPECT_EQ(std::get<2>(entries.at(0)),
"Only include instances in the `examples` array that validate "
"against the schema");
EXPECT_EQ(std::get<3>(entries.at(0)),
EXPECT_TRUE(std::get<3>(entries.at(0)).description.has_value());
EXPECT_EQ(std::get<3>(entries.at(0)).description.value(),
R"TXT(Invalid example instance at index 0
The value was expected to be of type string but it was of type integer
at instance location ""
at evaluate path "/type"
)TXT");

EXPECT_EQ(std::get<3>(entries.at(0)).locations.size(), 1);
EXPECT_EQ(
sourcemeta::core::to_string(std::get<3>(entries.at(0)).locations.at(0)),
"/examples/0");
}

TEST(Linter, valid_examples_1) {
Expand Down
Loading
Loading