From a49fa0edbe6d25a5f6b92721beb3f5d2ca10ecc3 Mon Sep 17 00:00:00 2001 From: dvirtz Date: Thu, 18 May 2017 15:51:44 +0300 Subject: [PATCH 1/3] use absolute path to test files - accroding to CMake docs EXISTS behavior is well-defined only for full paths. --- contrib/ParseAndAddCatchTests.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/ParseAndAddCatchTests.cmake b/contrib/ParseAndAddCatchTests.cmake index a81de4b8..1b96802f 100644 --- a/contrib/ParseAndAddCatchTests.cmake +++ b/contrib/ParseAndAddCatchTests.cmake @@ -47,6 +47,8 @@ endfunction() # Worker function function(ParseFile SourceFile TestTarget) + # accroding 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() From aac594aae3697badc32142fa14f87ef26af357b6 Mon Sep 17 00:00:00 2001 From: dvirtz Date: Thu, 18 May 2017 15:53:35 +0300 Subject: [PATCH 2/3] add option to print debug messages --- contrib/ParseAndAddCatchTests.cmake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/contrib/ParseAndAddCatchTests.cmake b/contrib/ParseAndAddCatchTests.cmake index 1b96802f..42c6f34f 100644 --- a/contrib/ParseAndAddCatchTests.cmake +++ b/contrib/ParseAndAddCatchTests.cmake @@ -25,10 +25,24 @@ # # # include(ParseAndAddCatchTests) # # ParseAndAddCatchTests(${PROJECT_NAME}) # +# # +# The following variables affect the behavior of the script: # +# # +# PARSE_CATCH_TESTS_VERBOSE (Default OFF) # +# -- enabels debug messages # +# # #==================================================================================================# cmake_minimum_required(VERSION 2.8.8) +option(PARSE_CATCH_TESTS_VERBOSE "Print Catch to CTest parser debug messages" OFF) + +function(PrintDebugMessage) + if(PARSE_CATCH_TESTS_VERBOSE) + message(STATUS "ParseAndAddCatchTests: ${ARGV}") + endif() +endfunction() + # This removes the contents between # - block comments (i.e. /* ... */) # - full line comments (i.e. // ... ) @@ -53,6 +67,7 @@ function(ParseFile SourceFile TestTarget) message(WARNING "Cannot find source file: ${SourceFile}") return() endif() + PrintDebugMessage("parsing ${SourceFile}") file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME) # Remove block and fullline comments @@ -99,6 +114,8 @@ function(ParseFile SourceFile TestTarget) string(REPLACE "]" ";" Tags "${Tags}") string(REPLACE "[" "" Tags "${Tags}") endif() + + PrintDebugMessage("Adding test \"${CTestName}\"") # Add the test and set its properties add_test(NAME "\"${CTestName}\"" COMMAND ${TestTarget} ${Name} ${AdditionalCatchParameters}) @@ -110,8 +127,11 @@ endfunction() # entry point function(ParseAndAddCatchTests TestTarget) + PrintDebugMessage("Started parsing ${TestTarget}") get_target_property(SourceFiles ${TestTarget} SOURCES) + PrintDebugMessage("Found the following sources: ${SourceFiles}") foreach(SourceFile ${SourceFiles}) ParseFile(${SourceFile} ${TestTarget}) endforeach() + PrintDebugMessage("Finished parsing ${TestTarget}") endfunction() From 4b086bd5b5e2e03a60f59b3e3101baab996f2c7c Mon Sep 17 00:00:00 2001 From: dvirtz Date: Thu, 18 May 2017 16:00:18 +0300 Subject: [PATCH 3/3] added target name to test name and labels --- contrib/ParseAndAddCatchTests.cmake | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/contrib/ParseAndAddCatchTests.cmake b/contrib/ParseAndAddCatchTests.cmake index 42c6f34f..6c3e6632 100644 --- a/contrib/ParseAndAddCatchTests.cmake +++ b/contrib/ParseAndAddCatchTests.cmake @@ -108,19 +108,31 @@ function(ParseFile SourceFile TestTarget) else() set(CTestName "${Name}") endif() + set(CTestName "${TestTarget}:${CTestName}") + # 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}") endif() + list(APPEND Labels ${Tags}) + PrintDebugMessage("Adding test \"${CTestName}\"") + if(Labels) + PrintDebugMessage("Setting labels to ${Labels}") + endif() # Add the test and set its properties add_test(NAME "\"${CTestName}\"" COMMAND ${TestTarget} ${Name} ${AdditionalCatchParameters}) set_tests_properties("\"${CTestName}\"" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran" - LABELS "${Tags}") + LABELS "${Labels}") endforeach() endfunction()