Selaa lähdekoodia

test-refactor: cleanup

Sam Jaffe 1 vuosi sitten
vanhempi
commit
759f304b95
3 muutettua tiedostoa jossa 30 lisäystä ja 11 poistoa
  1. 4 1
      Makefile
  2. 24 7
      tests/json_schema_test_suite.h
  3. 2 3
      tests/selfvalidate_test.cxx

+ 4 - 1
Makefile

@@ -20,6 +20,9 @@ TEST_SOURCES := $(wildcard $(TEST_DIR)*.cxx)
 TEST_OBJECTS := $(patsubst %.cxx, .build/%.o, $(TEST_SOURCES))
 TEST_BINARIES := .build/bin/selfvalidate
 
+EXCLUDED_TESTS := optional_format* content bignum non_bmp_regex float_overflow ecmascript_regex
+EXCLUDED_TESTS := $(shell printf ":*%s" $(EXCLUDED_TESTS) | cut -c2-)
+
 all: run-test
 
 debug: CXX_FLAGS := $(CXX_FLAGS) -g -fsanitize=address
@@ -33,7 +36,7 @@ test: $(TEST_BINARIES)
 
 run-test: test
 run-test:
-	.build/bin/selfvalidate --gtest_filter=-*date:*json_pointer:*idn_hostname:*uri:*uri_template:*iri_reference:*iri:*ipv4:*uri_reference:*time:*ipv6:*hostname:*email:*relative_json_pointer:*date_time:*idn_email:*content:*bignum $(CLEAN_ANSI)
+	.build/bin/selfvalidate --gtest_filter=-$(EXCLUDED_TESTS) $(CLEAN_ANSI)
 
 .build/tests/%.o: tests/%.cxx $(HEADERS) $(TEST_HEADERS)
 	@ mkdir -p .build/tests

+ 24 - 7
tests/json_schema_test_suite.h

@@ -2,9 +2,12 @@
 
 #include <gmock/gmock.h>
 
+#include <jvalidate/enum.h>
 #include <jvalidate/validation_result.h>
 #include <jvalidate/validator.h>
 
+using SchemaParams = std::tuple<jvalidate::schema::Version, std::filesystem::path>;
+
 inline std::filesystem::path const & JSONSchemaTestSuiteDir() {
   static auto const g_root =
       std::filesystem::path(__FILE__).parent_path().parent_path().parent_path();
@@ -12,14 +15,23 @@ inline std::filesystem::path const & JSONSchemaTestSuiteDir() {
   return g_path;
 }
 
-inline auto SchemaTests(std::string_view draft) {
+inline std::string to_string(jvalidate::schema::Version version) {
+  std::stringstream ss;
+  ss << version;
+  return ss.str();
+}
+
+inline auto SchemaTests(jvalidate::schema::Version version) {
   struct fs_iterator : std::filesystem::recursive_directory_iterator {
     using super = std::filesystem::recursive_directory_iterator;
-    using value_type = std::filesystem::path;
+    using value_type = SchemaParams;
+    using reference = SchemaParams;
 
-    using super::super;
+    fs_iterator() = default;
+    explicit fs_iterator(jvalidate::schema::Version version)
+        : super(JSONSchemaTestSuiteDir() / "tests" / to_string(version)), version(version) {}
 
-    std::filesystem::path operator*() const { return super::operator*().path(); }
+    SchemaParams operator*() const { return std::make_tuple(version, super::operator*().path()); }
 
     fs_iterator operator++() {
       do {
@@ -27,14 +39,19 @@ inline auto SchemaTests(std::string_view draft) {
       } while (*this != fs_iterator() && super::operator*().is_directory());
       return *this;
     }
+
+    jvalidate::schema::Version version;
   };
 
-  auto const dir = JSONSchemaTestSuiteDir() / "tests" / draft;
-  return testing::ValuesIn(fs_iterator(dir), fs_iterator());
+  return testing::ValuesIn(fs_iterator(version), fs_iterator());
 }
 
 static auto SchemaTestName = [](auto const & info) {
-  std::string name = std::get<1>(info.param).stem();
+  auto [version, file] = info.param;
+  auto base = JSONSchemaTestSuiteDir() / "tests" / to_string(version);
+
+  std::string name = std::filesystem::relative(file, base);
+  name = name.substr(0, name.rfind('.'));
   std::transform(name.begin(), name.end(), name.begin(),
                  [](char c) { return std::isalnum(c) ? c : '_'; });
   return name;

+ 2 - 3
tests/selfvalidate_test.cxx

@@ -84,7 +84,7 @@ bool load_external_for_test(jvalidate::URI const & uri, Json::Value & out) {
   }
 }
 
-class JsonSchema : public TestWithParam<std::tuple<Version, std::filesystem::path>> {
+class JsonSchema : public TestWithParam<SchemaParams> {
 private:
   static RecursiveTestFilter s_suite_filter;
   static RecursiveTestFilter s_case_filter;
@@ -156,8 +156,7 @@ TEST_P(JsonSchema, TestSuite) {
   }
 }
 
-INSTANTIATE_TEST_SUITE_P(Draft7, JsonSchema,
-                         Combine(Values(Version::Draft07), SchemaTests("draft7")), SchemaTestName);
+INSTANTIATE_TEST_SUITE_P(Draft7, JsonSchema, SchemaTests(Version::Draft07), SchemaTestName);
 
 int main(int argc, char ** argv) {
   testing::InitGoogleMock(&argc, argv);