Run clang-format

Fix pre-commit workflow failures
This commit is contained in:
ss 2024-09-01 19:23:56 +02:00 committed by Patrick Boettcher
parent 813eb6312b
commit fbd72de0d6
2 changed files with 176 additions and 195 deletions

View File

@ -429,8 +429,7 @@ enum logical_combination_types {
class logical_combination_error_handler : public error_handler class logical_combination_error_handler : public error_handler
{ {
public: public:
struct error_entry struct error_entry {
{
json::json_pointer ptr_; json::json_pointer ptr_;
json instance_; json instance_;
std::string message_; std::string message_;
@ -513,8 +512,7 @@ const std::string logical_combination<oneOf>::key = "oneOf";
template <> template <>
bool logical_combination<allOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &e, const logical_combination_error_handler &esub, size_t, size_t current_schema_index) bool logical_combination<allOf>::is_validate_complete(const json &, const json::json_pointer &, error_handler &e, const logical_combination_error_handler &esub, size_t, size_t current_schema_index)
{ {
if (esub) if (esub) {
{
e.error(esub.error_entry_list_.front().ptr_, esub.error_entry_list_.front().instance_, "at least one subschema has failed, but all of them are required to validate - " + esub.error_entry_list_.front().message_); e.error(esub.error_entry_list_.front().ptr_, esub.error_entry_list_.front().instance_, "at least one subschema has failed, but all of them are required to validate - " + esub.error_entry_list_.front().message_);
esub.propagate(e, "[combination: allOf / case#" + std::to_string(current_schema_index) + "] "); esub.propagate(e, "[combination: allOf / case#" + std::to_string(current_schema_index) + "] ");
} }

View File

@ -13,18 +13,14 @@
std::cerr << __FILE__ << ":" << __LINE__ << ": " << LOG_ERROR__ARGS << std::endl std::cerr << __FILE__ << ":" << __LINE__ << ": " << LOG_ERROR__ARGS << std::endl
#define EXPECT_THROW_WITH_MESSAGE(EXPRESSION, MESSAGE) \ #define EXPECT_THROW_WITH_MESSAGE(EXPRESSION, MESSAGE) \
do \ do { \
{ \ try { \
try \
{ \
EXPRESSION; \ EXPRESSION; \
LOG_ERROR("Expected exception not thrown with matching regex: \"" << MESSAGE << "\""); \ LOG_ERROR("Expected exception not thrown with matching regex: \"" << MESSAGE << "\""); \
++g_error_count; \ ++g_error_count; \
} catch (const std::exception& error) \ } catch (const std::exception &error) { \
{ \
const std::regex error_re{MESSAGE}; \ const std::regex error_re{MESSAGE}; \
if (!std::regex_search(error.what(), error_re)) \ if (!std::regex_search(error.what(), error_re)) { \
{ \
LOG_ERROR("Expected exception with matching regex: \"" << MESSAGE << "\", but got this instead: " << error.what()); \ LOG_ERROR("Expected exception with matching regex: \"" << MESSAGE << "\", but got this instead: " << error.what()); \
++g_error_count; \ ++g_error_count; \
} \ } \
@ -32,32 +28,25 @@
} while (false) } while (false)
#define ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, RETURN_IN_CASE_OF_ERROR) \ #define ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, RETURN_IN_CASE_OF_ERROR) \
do \ do { \
{ \ if ((FIRST_THING) != (SECOND_THING)) { \
if ((FIRST_THING) != (SECOND_THING)) \
{ \
LOG_ERROR("The two values of " << (FIRST_THING) << " (" #FIRST_THING << ") and " << (SECOND_THING) << " (" #SECOND_THING << ") should be equal"); \ LOG_ERROR("The two values of " << (FIRST_THING) << " (" #FIRST_THING << ") and " << (SECOND_THING) << " (" #SECOND_THING << ") should be equal"); \
if (RETURN_IN_CASE_OF_ERROR) \ if (RETURN_IN_CASE_OF_ERROR) { \
{ \
return; \ return; \
} \ } \
} \ } \
} \ } while (false)
while(false)
#define ASSERT_EQ(FIRST_THING, SECOND_THING) ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, true) #define ASSERT_EQ(FIRST_THING, SECOND_THING) ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, true)
#define EXPECT_EQ(FIRST_THING, SECOND_THING) ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, true) #define EXPECT_EQ(FIRST_THING, SECOND_THING) ASSERT_OR_EXPECT_EQ(FIRST_THING, SECOND_THING, true)
#define EXPECT_MATCH(STRING, REGEX) \ #define EXPECT_MATCH(STRING, REGEX) \
do \ do { \
{ \ if (!std::regex_search((STRING), std::regex{(REGEX)})) { \
if (!std::regex_search((STRING), std::regex{ (REGEX) })) \
{ \
LOG_ERROR("String \"" << (STRING) << "\" doesn't match with regex: \"" << (REGEX) << "\""); \ LOG_ERROR("String \"" << (STRING) << "\" doesn't match with regex: \"" << (REGEX) << "\""); \
++g_error_count; \ ++g_error_count; \
} \ } \
} \ } while (false)
while(false)
namespace namespace
{ {
@ -123,8 +112,7 @@ auto generateSchema(const std::string& first_combination, const std::string& sec
class MyErrorHandler : public nlohmann::json_schema::error_handler class MyErrorHandler : public nlohmann::json_schema::error_handler
{ {
public: public:
struct ErrorEntry struct ErrorEntry {
{
nlohmann::json::json_pointer ptr; nlohmann::json::json_pointer ptr;
nlohmann::json intance; nlohmann::json intance;
std::string message; std::string message;
@ -174,12 +162,9 @@ auto validate(const nlohmann::json& schema, const nlohmann::json& instance, nloh
nlohmann::json_schema::json_validator validator; nlohmann::json_schema::json_validator validator;
validator.set_root_schema(schema); validator.set_root_schema(schema);
if (error_handler) if (error_handler) {
{
validator.validate(instance, *error_handler); validator.validate(instance, *error_handler);
} } else {
else
{
validator.validate(instance); validator.validate(instance);
} }
} }
@ -191,8 +176,7 @@ auto simpleTest(const std::string& first_combination, const std::string& second_
{ {
const nlohmann::json schema = generateSchema(first_combination, second_combination); const nlohmann::json schema = generateSchema(first_combination, second_combination);
EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", {{"second", 1}}}}), rootError(first_combination, 3)); EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", {{"second", 1}}}}), rootError(first_combination, 3));
if (second_combination == "oneOf") if (second_combination == "oneOf") {
{
EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", {{"second", 8}}}}), rootError(first_combination, 3)); EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", {{"second", 8}}}}), rootError(first_combination, 3));
} }
EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", 10}}), rootError(first_combination, 3)); EXPECT_THROW_WITH_MESSAGE(validate(schema, nlohmann::json{{"first", 10}}), rootError(first_combination, 3));
@ -255,8 +239,7 @@ auto verboseTest(const std::string& first_combination, const std::string& second
EXPECT_MATCH(error_list[5].message, combinationError(first_combination, 2) << "unexpected instance type"); EXPECT_MATCH(error_list[5].message, combinationError(first_combination, 2) << "unexpected instance type");
} }
if (second_combination == "oneOf") if (second_combination == "oneOf") {
{
MyErrorHandler error_handler; MyErrorHandler error_handler;
validate(schema, nlohmann::json{{"first", {{"second", 8}}}}, &error_handler); validate(schema, nlohmann::json{{"first", {{"second", 8}}}}, &error_handler);
@ -317,7 +300,7 @@ auto verboseTest(const std::string& first_combination, const std::string& second
} }
} }
} // namespace <anonymous> } // namespace
//============================================================================== //==============================================================================
// MAIN - calling the test cases // MAIN - calling the test cases