Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/extras
diff options
context:
space:
mode:
authorChris Thrasher2025-04-07 22:09:59 -0600
committerChris Thrasher2025-04-26 10:38:36 -0600
commit8cfca70ae879ba59699b224e8d371b8bb9fa12ff (patch)
treee53b243d3d2b7acc41c27cbd21624e1e28b655cb /extras
parent6aac11e17d4fe662e430a8bbfd4bf6886ca7f935 (diff)
downloadcatch3-8cfca70ae879ba59699b224e8d371b8bb9fa12ff.tar.gz
Fix formatting of CMake files
2 spaces seems to be the more common indentation level so that's what I unified around.
Diffstat (limited to 'extras')
-rw-r--r--extras/Catch.cmake6
-rw-r--r--extras/CatchAddTests.cmake6
-rw-r--r--extras/CatchShardTests.cmake6
-rw-r--r--extras/CatchShardTestsImpl.cmake4
-rw-r--r--extras/ParseAndAddCatchTests.cmake304
5 files changed, 161 insertions, 165 deletions
diff --git a/extras/Catch.cmake b/extras/Catch.cmake
index 3d93fe20..fcdebd60 100644
--- a/extras/Catch.cmake
+++ b/extras/Catch.cmake
@@ -165,7 +165,7 @@ function(catch_discover_tests TARGET)
${ARGN}
)
- if (${CMAKE_VERSION} VERSION_LESS "3.19")
+ if(${CMAKE_VERSION} VERSION_LESS "3.19")
message(FATAL_ERROR "This script requires JSON support from CMake version 3.19 or greater.")
endif()
@@ -187,7 +187,7 @@ function(catch_discover_tests TARGET)
endif()
set(_DISCOVERY_MODE ${CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE})
endif()
- if (NOT _DISCOVERY_MODE MATCHES "^(POST_BUILD|PRE_TEST)$")
+ if(NOT _DISCOVERY_MODE MATCHES "^(POST_BUILD|PRE_TEST)$")
message(FATAL_ERROR "Unknown DISCOVERY_MODE: ${_DISCOVERY_MODE}")
endif()
@@ -204,7 +204,7 @@ function(catch_discover_tests TARGET)
TARGET ${TARGET}
PROPERTY CROSSCOMPILING_EMULATOR
)
- if (NOT _SKIP_IS_FAILURE)
+ if(NOT _SKIP_IS_FAILURE)
set(_PROPERTIES ${_PROPERTIES} SKIP_RETURN_CODE 4)
endif()
diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake
index 25342139..90fbd5e3 100644
--- a/extras/CatchAddTests.cmake
+++ b/extras/CatchAddTests.cmake
@@ -136,7 +136,7 @@ function(catch_discover_tests_impl)
# Parse JSON output for list of tests/class names/tags
string(JSON version GET "${listing_output}" "version")
- if (NOT version STREQUAL "1")
+ if(NOT version STREQUAL "1")
message(FATAL_ERROR "Unsupported catch output version: '${version}'")
endif()
@@ -186,11 +186,11 @@ function(catch_discover_tests_impl)
${properties}
)
- if (add_tags)
+ if(add_tags)
string(JSON num_tags LENGTH "${test_tags}")
math(EXPR num_tags "${num_tags} - 1")
set(tag_list "")
- if (num_tags GREATER_EQUAL "0")
+ if(num_tags GREATER_EQUAL "0")
foreach(tag_idx RANGE ${num_tags})
string(JSON a_tag GET "${test_tags}" "${tag_idx}")
# Catch2's tags can contain semicolons, which are list element separators
diff --git a/extras/CatchShardTests.cmake b/extras/CatchShardTests.cmake
index 68228f5a..89666d66 100644
--- a/extras/CatchShardTests.cmake
+++ b/extras/CatchShardTests.cmake
@@ -11,7 +11,7 @@
# * REPORTER - reporter spec to use for tests
# * TEST_SPEC - test spec used for filtering tests
function(catch_add_sharded_tests TARGET)
- if (${CMAKE_VERSION} VERSION_LESS "3.10.0")
+ if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
message(FATAL_ERROR "add_sharded_catch_tests only supports CMake versions 3.10.0 and up")
endif()
@@ -23,7 +23,7 @@ function(catch_add_sharded_tests TARGET)
${ARGN}
)
- if (NOT DEFINED _SHARD_COUNT)
+ if(NOT DEFINED _SHARD_COUNT)
set(_SHARD_COUNT 2)
endif()
@@ -61,8 +61,6 @@ function(catch_add_sharded_tests TARGET)
-P "${shard_impl_script_file}"
VERBATIM
)
-
-
endfunction()
diff --git a/extras/CatchShardTestsImpl.cmake b/extras/CatchShardTestsImpl.cmake
index bb2fc3ef..83fac688 100644
--- a/extras/CatchShardTestsImpl.cmake
+++ b/extras/CatchShardTestsImpl.cmake
@@ -25,10 +25,10 @@ if(NOT EXISTS "${TEST_BINARY}")
endif()
set(other_args "")
-if (TEST_SPEC)
+if(TEST_SPEC)
set(other_args "${other_args} ${TEST_SPEC}")
endif()
-if (REPORTER_SPEC)
+if(REPORTER_SPEC)
set(other_args "${other_args} --reporter ${REPORTER_SPEC}")
endif()
diff --git a/extras/ParseAndAddCatchTests.cmake b/extras/ParseAndAddCatchTests.cmake
index 31fc193a..d7c17ace 100644
--- a/extras/ParseAndAddCatchTests.cmake
+++ b/extras/ParseAndAddCatchTests.cmake
@@ -56,7 +56,7 @@
# #
#==================================================================================================#
-if (CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
+if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
message(FATAL_ERROR "ParseAndAddCatchTests requires CMake 2.8.8 or newer")
endif()
@@ -67,9 +67,9 @@ option(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME "Add target name to the test na
option(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS "Add test file to CMAKE_CONFIGURE_DEPENDS property" OFF)
function(ParseAndAddCatchTests_PrintDebugMessage)
- if(PARSE_CATCH_TESTS_VERBOSE)
- message(STATUS "ParseAndAddCatchTests: ${ARGV}")
- endif()
+ if(PARSE_CATCH_TESTS_VERBOSE)
+ message(STATUS "ParseAndAddCatchTests: ${ARGV}")
+ endif()
endfunction()
# This removes the contents between
@@ -90,163 +90,161 @@ endfunction()
# Worker function
function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
- # If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
- if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
- ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
- return()
- endif()
- # According to CMake docs EXISTS behavior is well-defined only for full paths.
- get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
- if(NOT EXISTS ${SourceFile})
- message(WARNING "Cannot find source file: ${SourceFile}")
- return()
+ # If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
+ if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
+ ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
+ return()
+ endif()
+ # According to CMake docs EXISTS behavior is well-defined only for full paths.
+ get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
+ if(NOT EXISTS ${SourceFile})
+ message(WARNING "Cannot find source file: ${SourceFile}")
+ return()
+ endif()
+ ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
+ file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
+
+ # Remove block and fullline comments
+ ParseAndAddCatchTests_RemoveComments(Contents)
+
+ # Find definition of test names
+ # https://regex101.com/r/JygOND/1
+ string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
+
+ if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
+ ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
+ set_property(
+ DIRECTORY
+ APPEND
+ PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
+ )
+ endif()
+
+ # check CMP0110 policy for new add_test() behavior
+ if(POLICY CMP0110)
+ cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior
+ else()
+ # just to be thorough explicitly set the variable
+ set(_cmp0110_value)
+ endif()
+
+ foreach(TestName ${Tests})
+ # Strip newlines
+ string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
+
+ # Get test type and fixture if applicable
+ string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
+ string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
+ string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}")
+
+ # Get string parts of test definition
+ string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}")
+
+ # Strip wrapping quotation marks
+ string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}")
+ string(REPLACE "\";\"" ";" TestStrings "${TestStrings}")
+
+ # Validate that a test name and tags have been provided
+ list(LENGTH TestStrings TestStringsLength)
+ if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1)
+ message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}")
endif()
- ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
- file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
-
- # Remove block and fullline comments
- ParseAndAddCatchTests_RemoveComments(Contents)
-
- # Find definition of test names
- # https://regex101.com/r/JygOND/1
- string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
- if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
- ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
- set_property(
- DIRECTORY
- APPEND
- PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
- )
+ # Assign name and tags
+ list(GET TestStrings 0 Name)
+ if("${TestType}" STREQUAL "SCENARIO")
+ set(Name "Scenario: ${Name}")
endif()
-
- # check CMP0110 policy for new add_test() behavior
- if(POLICY CMP0110)
- cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior
+ if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture)
+ set(CTestName "${TestFixture}:${Name}")
+ else()
+ set(CTestName "${Name}")
+ endif()
+ if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME)
+ set(CTestName "${TestTarget}:${CTestName}")
+ endif()
+ # add target to labels to enable running all tests added from this target
+ set(Labels ${TestTarget})
+ if(TestStringsLength EQUAL 2)
+ list(GET TestStrings 1 Tags)
+ string(TOLOWER "${Tags}" Tags)
+ # remove target from labels if the test is hidden
+ if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*")
+ list(REMOVE_ITEM Labels ${TestTarget})
+ endif()
+ string(REPLACE "]" ";" Tags "${Tags}")
+ string(REPLACE "[" "" Tags "${Tags}")
else()
- # just to be thorough explicitly set the variable
- set(_cmp0110_value)
+ # unset tags variable from previous loop
+ unset(Tags)
endif()
- foreach(TestName ${Tests})
- # Strip newlines
- string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
-
- # Get test type and fixture if applicable
- string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
- string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
- string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}")
-
- # Get string parts of test definition
- string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}")
-
- # Strip wrapping quotation marks
- string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}")
- string(REPLACE "\";\"" ";" TestStrings "${TestStrings}")
-
- # Validate that a test name and tags have been provided
- list(LENGTH TestStrings TestStringsLength)
- if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1)
- message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}")
- endif()
-
- # Assign name and tags
- list(GET TestStrings 0 Name)
- if("${TestType}" STREQUAL "SCENARIO")
- set(Name "Scenario: ${Name}")
- endif()
- if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture )
- set(CTestName "${TestFixture}:${Name}")
- else()
- set(CTestName "${Name}")
- endif()
- if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME)
- set(CTestName "${TestTarget}:${CTestName}")
- endif()
- # add target to labels to enable running all tests added from this target
- set(Labels ${TestTarget})
- if(TestStringsLength EQUAL 2)
- list(GET TestStrings 1 Tags)
- string(TOLOWER "${Tags}" Tags)
- # remove target from labels if the test is hidden
- if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*")
- list(REMOVE_ITEM Labels ${TestTarget})
- endif()
- string(REPLACE "]" ";" Tags "${Tags}")
- string(REPLACE "[" "" Tags "${Tags}")
- else()
- # unset tags variable from previous loop
- unset(Tags)
- endif()
-
- list(APPEND Labels ${Tags})
-
- set(HiddenTagFound OFF)
- foreach(label ${Labels})
- string(REGEX MATCH "^!hide|^\\." result ${label})
- if(result)
- set(HiddenTagFound ON)
- break()
- endif()
- endforeach(label)
- if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9")
- ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label")
- else()
- ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"")
- if(Labels)
- ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}")
- endif()
-
- # Escape commas in the test spec
- string(REPLACE "," "\\," Name ${Name})
-
- # Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were necessary,
- # only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1
- # And properly introduced in 3.19 with the CMP0110 policy
- if(_cmp0110_value STREQUAL "NEW" OR ${CMAKE_VERSION} VERSION_EQUAL "3.18")
- ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to NEW, no need for add_test(\"\") workaround")
- else()
- ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to OLD adding \"\" for add_test() workaround")
- set(CTestName "\"${CTestName}\"")
- endif()
-
- # Handle template test cases
- if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*")
- set(Name "${Name} - *")
- endif()
-
- # Add the test and set its properties
- add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
- # Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead
- if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8")
- ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property")
- set_tests_properties("${CTestName}" PROPERTIES DISABLED ON)
- else()
- set_tests_properties("${CTestName}" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran"
- LABELS "${Labels}")
- endif()
- set_property(
- TARGET ${TestTarget}
- APPEND
- PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
- set_property(
- SOURCE ${SourceFile}
- APPEND
- PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
- endif()
-
-
- endforeach()
+ list(APPEND Labels ${Tags})
+
+ set(HiddenTagFound OFF)
+ foreach(label ${Labels})
+ string(REGEX MATCH "^!hide|^\\." result ${label})
+ if(result)
+ set(HiddenTagFound ON)
+ break()
+ endif()
+ endforeach(label)
+ if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9")
+ ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label")
+ else()
+ ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"")
+ if(Labels)
+ ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}")
+ endif()
+
+ # Escape commas in the test spec
+ string(REPLACE "," "\\," Name ${Name})
+
+ # Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were necessary,
+ # only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1
+ # And properly introduced in 3.19 with the CMP0110 policy
+ if(_cmp0110_value STREQUAL "NEW" OR ${CMAKE_VERSION} VERSION_EQUAL "3.18")
+ ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to NEW, no need for add_test(\"\") workaround")
+ else()
+ ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to OLD adding \"\" for add_test() workaround")
+ set(CTestName "\"${CTestName}\"")
+ endif()
+
+ # Handle template test cases
+ if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*")
+ set(Name "${Name} - *")
+ endif()
+
+ # Add the test and set its properties
+ add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
+ # Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead
+ if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8")
+ ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property")
+ set_tests_properties("${CTestName}" PROPERTIES DISABLED ON)
+ else()
+ set_tests_properties("${CTestName}" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran"
+ LABELS "${Labels}")
+ endif()
+ set_property(
+ TARGET ${TestTarget}
+ APPEND
+ PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
+ set_property(
+ SOURCE ${SourceFile}
+ APPEND
+ PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
+ endif()
+ endforeach()
endfunction()
# entry point
function(ParseAndAddCatchTests TestTarget)
- message(DEPRECATION "ParseAndAddCatchTest: function deprecated because of possibility of missed test cases. Consider using 'catch_discover_tests' from 'Catch.cmake'")
- ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}")
- get_target_property(SourceFiles ${TestTarget} SOURCES)
- ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}")
- foreach(SourceFile ${SourceFiles})
- ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget})
- endforeach()
- ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}")
+ message(DEPRECATION "ParseAndAddCatchTest: function deprecated because of possibility of missed test cases. Consider using 'catch_discover_tests' from 'Catch.cmake'")
+ ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}")
+ get_target_property(SourceFiles ${TestTarget} SOURCES)
+ ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}")
+ foreach(SourceFile ${SourceFiles})
+ ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget})
+ endforeach()
+ ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}")
endfunction()