json-schema-validator/test/issue-143/test_issue.cpp
Cristian Le cadf5cc226 Migrate tests to Catch2
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
2023-11-28 15:08:28 +01:00

24 lines
958 B
C++

#include <filesystem>
#include <string_view>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>
#include "utils.h"
using namespace std::literals;
using Catch::Matchers::ContainsSubstring;
using Catch::Matchers::MessageMatches;
TEST_CASE_METHOD(JsonValidateFixture, "issue-143")
{
// Change the working directory to the issue path
auto path = std::filesystem::path(__FILE__).parent_path();
REQUIRE_NOTHROW(std::filesystem::current_path(path));
CHECK_THROWS_MATCHES(validate("schema.json"sv, "instance-fail-1.json"sv), std::invalid_argument,
MessageMatches(ContainsSubstring("At /ref1 of \"a\" - unexpected instance type")));
CHECK_THROWS_MATCHES(validate("schema.json"sv, "instance-fail-a.json"sv), std::invalid_argument,
MessageMatches(ContainsSubstring("At /refa of 12 - unexpected instance type")));
CHECK_NOTHROW(validate("schema.json"sv, "instance.json"sv));
}