فهرست منبع

fix: make it so test cases will properly be filtered if either of IDNA and/or ICU are missing

Sam Jaffe 2 هفته پیش
والد
کامیت
40d5876d14
2فایلهای تغییر یافته به همراه40 افزوده شده و 11 حذف شده
  1. 7 1
      include/jvalidate/format.h
  2. 33 10
      tests/CMakeLists.txt

+ 7 - 1
include/jvalidate/format.h

@@ -15,7 +15,7 @@
 #include <unordered_set>
 #include <utility>
 
-#ifdef JVALIDATE_HAS_IDNA
+#if JVALIDATE_HAS_IDNA
 #include <ada/idna/to_unicode.h>
 #include <ada/idna/validity.h>
 #endif
@@ -701,9 +701,11 @@ template <typename T> inline bool ctor_as_valid(std::string_view str) {
   } catch (std::exception const &) { return false; }
 }
 
+#if JVALIDATE_HAS_IDNA
 template <auto Predicate> bool utf32(std::string_view str) {
   return Predicate(detail::to_u32(str));
 }
+#endif
 }
 
 namespace jvalidate {
@@ -737,7 +739,11 @@ private:
       {"time", &format::time},
       {"uri", &format::uri},
       {"uri-reference", &format::uri_reference},
+#if JVALIDATE_HAS_IDNA
       {"uri-template", &format::utf32<format::uri_template>},
+#else
+      {"uri-template", nullptr},
+#endif
       {"uuid", &format::uuid},
   };
 

+ 33 - 10
tests/CMakeLists.txt

@@ -28,11 +28,11 @@ FetchContent_MakeAvailable(json_schema_test_suite)
 include(GoogleTest)
 
 add_executable(annotation_test annotation_test.cxx)
-target_link_libraries(annotation_test GTest::gtest GTest::gmock ada-idna jsoncpp_lib)
+target_link_libraries(annotation_test GTest::gtest GTest::gmock jsoncpp_lib)
 gtest_discover_tests(annotation_test)
 
 add_executable(extension_test extension_test.cxx)
-target_link_libraries(extension_test GTest::gtest GTest::gmock ada-idna jsoncpp_lib)
+target_link_libraries(extension_test GTest::gtest GTest::gmock jsoncpp_lib)
 gtest_discover_tests(extension_test)
 
 add_executable(selfvalidate_test selfvalidate_test.cxx)
@@ -43,14 +43,16 @@ target_compile_definitions(selfvalidate_test
     JVALIDATE_JSON_SCHEMA_TEST_SUITE_DIR="${json_schema_test_suite_SOURCE_DIR}"
 )
 endif()
-target_link_libraries(selfvalidate_test GTest::gtest GTest::gmock ada-idna jsoncpp_lib CURL::libcurl)
+target_link_libraries(selfvalidate_test GTest::gtest GTest::gmock jsoncpp_lib CURL::libcurl)
 
 if (ICU_FOUND)
-  target_link_libraries(annotation_test ICU::uc ICU::i18n)
-  target_link_libraries(extension_test ICU::uc ICU::i18n)
   target_link_libraries(selfvalidate_test ICU::uc ICU::i18n)
 endif()
 
+if (IDNA_POPULATED)
+  target_link_libraries(selfvalidate_test ada-idna)
+endif()
+
 string(
   JOIN ":"
   SelfValidateTest_Unsupported
@@ -58,16 +60,37 @@ string(
   "*optional_*ecmascript_regex"
   "*optional_zeroTerminatedFloats"
 )
+
 if (NOT ${ICU_FOUND})
   string(
-    JOIN ":"
-    SelfValidateTest_Unsupported
-    ${SelfValidateTest_Unsupported}
-    "*optional_non_bmp_regex"
+    APPEND SelfValidateTest_Unsupported
+    ":*optional_non_bmp_regex"
   )
 endif()
+
+set(SelfValidateTest_Unsupported_Suites "")
 set(SelfValidateTest_Unsupported_Cases "*leap second")
 
+if (NOT ${IDNA_POPULATED})
+  string(
+    APPEND SelfValidateTest_Unsupported
+    ":*optional_*iri*"
+    ":*optional_*idn*"
+    ":*optional_*uri_template*"
+  )
+  string(
+    APPEND SelfValidateTest_Unsupported_Suites
+    ":*punycode*"
+    ":*puny-code"
+  )
+  string(
+    APPEND SelfValidateTest_Unsupported_Cases
+    ":*punycode*"
+    ":*puny-code"
+  )
+endif()
+
 gtest_discover_tests(selfvalidate_test
-                     EXTRA_ARGS --json_case_filter=-${SelfValidateTest_Unsupported_Cases}
+                     EXTRA_ARGS --json_suite_filter=-${SelfValidateTest_Unsupported_Suites}
+                                --json_case_filter=-${SelfValidateTest_Unsupported_Cases}
                      TEST_FILTER -${SelfValidateTest_Unsupported})