CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. enable_testing()
  2. # MUST do this before including IDNA
  3. # because it will otherwise poison GTest with BUILD_GMOCK=OFF
  4. find_package(GTest CONFIG REQUIRED COMPONENTS gtest gmock)
  5. find_package(jsoncpp REQUIRED)
  6. find_package(CURL REQUIRED)
  7. # ICU Components Reference:
  8. # https://cmake.org/cmake/help/latest/module/FindICU.html
  9. # ICU components = data, i18n, io, le, lx, test, tu and uc.
  10. find_package(ICU 77.1 COMPONENTS uc i18n)
  11. FetchContent_Declare(
  12. IDNA
  13. GIT_REPOSITORY https://github.com/ada-url/idna.git
  14. GIT_TAG 0.5.0
  15. )
  16. FetchContent_MakeAvailable(IDNA)
  17. FetchContent_Declare(
  18. json_schema_test_suite
  19. GIT_REPOSITORY https://github.com/json-schema-org/JSON-Schema-Test-Suite.git
  20. GIT_TAG Test-JSON-Schema-Acceptance-1.037
  21. )
  22. FetchContent_MakeAvailable(json_schema_test_suite)
  23. include(GoogleTest)
  24. set(JVALIDATE_UNIT_TESTS
  25. annotation_test extension_test validation_visitor_test enum_test detail_test
  26. regex_test adapter_test jsoncpp_adapter_test)
  27. set(JVALIDATE_TESTS selfvalidate_test ${JVALIDATE_UNIT_TESTS})
  28. # Each test executable matches with its filename.
  29. foreach(CASE IN LISTS JVALIDATE_TESTS)
  30. add_executable(${CASE} ${CASE}.cxx)
  31. endforeach()
  32. if (JVALIDATE_COVERAGE)
  33. # Include all test files in a single executable for coverage purposes
  34. add_executable(jvalidate_mono_test $<LIST:TRANSFORM,${JVALIDATE_TESTS},APPEND,.cxx>)
  35. # Disable main() in other source files
  36. target_compile_definitions(jvalidate_mono_test PRIVATE JVALIDATE_MONOTEST)
  37. # Enable coverage
  38. target_compile_options(jvalidate_mono_test PRIVATE -fprofile-instr-generate -fcoverage-mapping)
  39. target_link_options(jvalidate_mono_test PRIVATE -fprofile-instr-generate -fcoverage-mapping)
  40. # Add to the list of tests in order to perform the rest of the test setup...
  41. list(APPEND JVALIDATE_TESTS jvalidate_mono_test)
  42. endif()
  43. foreach(CASE IN LISTS JVALIDATE_TESTS)
  44. target_link_libraries(${CASE} GTest::gtest GTest::gmock jsoncpp_lib CURL::libcurl)
  45. target_compile_definitions(${CASE} PRIVATE JVALIDATE_USE_EXCEPTIONS)
  46. if (${json_schema_test_suite_POPULATED})
  47. target_compile_definitions(${CASE}
  48. PUBLIC
  49. JVALIDATE_JSON_SCHEMA_TEST_SUITE_DIR="${json_schema_test_suite_SOURCE_DIR}"
  50. )
  51. endif()
  52. if (ICU_FOUND)
  53. target_compile_definitions(${CASE} PUBLIC JVALIDATE_HAS_ICU=1)
  54. target_link_libraries(${CASE} ICU::uc ICU::i18n)
  55. else()
  56. target_compile_definitions(${CASE} PUBLIC JVALIDATE_HAS_ICU=0)
  57. endif()
  58. if (idna_POPULATED)
  59. target_compile_definitions(${CASE} PUBLIC JVALIDATE_HAS_IDNA=1)
  60. target_link_libraries(${CASE} ada-idna)
  61. else()
  62. target_compile_definitions(${CASE} PUBLIC JVALIDATE_HAS_IDNA=0)
  63. endif()
  64. endforeach()
  65. string(
  66. JOIN ":"
  67. SelfValidateTest_Unsupported
  68. "*optional_content"
  69. "*optional_*ecmascript_regex"
  70. "*optional_zeroTerminatedFloats"
  71. )
  72. set(SelfValidateTest_Unsupported_Suites "")
  73. set(SelfValidateTest_Unsupported_Cases "*leap second")
  74. if (NOT ICU_FOUND)
  75. string(
  76. APPEND SelfValidateTest_Unsupported
  77. ":*optional_non_bmp_regex"
  78. )
  79. endif()
  80. if (NOT idna_POPULATED)
  81. string(
  82. APPEND SelfValidateTest_Unsupported
  83. ":*optional_*iri*"
  84. ":*optional_*idn*"
  85. ":*optional_*uri_template*"
  86. )
  87. string(
  88. APPEND SelfValidateTest_Unsupported_Suites
  89. ":*punycode*"
  90. ":*puny-code"
  91. )
  92. string(
  93. APPEND SelfValidateTest_Unsupported_Cases
  94. ":*punycode*"
  95. ":*puny-code"
  96. )
  97. endif()
  98. foreach(CASE IN LISTS JVALIDATE_UNIT_TESTS)
  99. gtest_discover_tests(${CASE})
  100. endforeach()
  101. gtest_discover_tests(selfvalidate_test
  102. EXTRA_ARGS --json_suite_filter=-${SelfValidateTest_Unsupported_Suites}
  103. --json_case_filter=-${SelfValidateTest_Unsupported_Cases}
  104. TEST_FILTER -${SelfValidateTest_Unsupported})