diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2023-11-11 16:33:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-12-13 15:20:43 (GMT) |
commit | 1ec0372ed4b450e242fdb8f6a7d2862baa61b501 (patch) | |
tree | 2ae040a6f48ea682b62f72b56b593b72f3f286c5 /Tests/RunCMake | |
parent | 478a5f4e044d253971e71a41ad6fc6b8aa4e1c07 (diff) | |
download | CMake-1ec0372ed4b450e242fdb8f6a7d2862baa61b501.zip CMake-1ec0372ed4b450e242fdb8f6a7d2862baa61b501.tar.gz CMake-1ec0372ed4b450e242fdb8f6a7d2862baa61b501.tar.bz2 |
add_test: Optionally use a launcher for tests running in-project targets
Add a `CMAKE_TEST_LAUNCHER` variable and corresponding `TEST_LAUNCHER`
target property.
Issue: #23672
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/CrosscompilingEmulator/AddTest-check.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/CrosscompilingEmulator/AddTest.cmake | 6 | ||||
-rw-r--r-- | Tests/RunCMake/add_test/RunCMakeTest.cmake | 6 | ||||
-rw-r--r-- | Tests/RunCMake/add_test/TestLauncher-check.cmake | 28 | ||||
-rw-r--r-- | Tests/RunCMake/add_test/TestLauncher.cmake | 22 | ||||
-rw-r--r-- | Tests/RunCMake/add_test/TestLauncher/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Tests/RunCMake/add_test/TestLauncherProperty.cmake | 41 | ||||
-rw-r--r-- | Tests/RunCMake/add_test/simple_src_exiterror.cxx | 4 |
8 files changed, 120 insertions, 0 deletions
diff --git a/Tests/RunCMake/CrosscompilingEmulator/AddTest-check.cmake b/Tests/RunCMake/CrosscompilingEmulator/AddTest-check.cmake index 588b77b..459e922 100644 --- a/Tests/RunCMake/CrosscompilingEmulator/AddTest-check.cmake +++ b/Tests/RunCMake/CrosscompilingEmulator/AddTest-check.cmake @@ -26,3 +26,7 @@ endif() if(testfile_contents MATCHES "add_test[(]DoesNotUseEmulatorWithExecTargetFromSubdirAddedWithGenex [^\n]+pseudo_emulator[^\n]+\n") message(SEND_ERROR "Used emulator when it should not be used. ${error_details}") endif() + +if(NOT testfile_contents MATCHES "add_test[(]UsesTestLauncherAndEmulator[^\n]+pseudo_test_launcher.*pseudo_emulator[^\n]+\n") + message(SEND_ERROR "Did not use test launcher and emulator when they should be used. ${error_details}") +endif() diff --git a/Tests/RunCMake/CrosscompilingEmulator/AddTest.cmake b/Tests/RunCMake/CrosscompilingEmulator/AddTest.cmake index 23e2e8d..4bcb2cf 100644 --- a/Tests/RunCMake/CrosscompilingEmulator/AddTest.cmake +++ b/Tests/RunCMake/CrosscompilingEmulator/AddTest.cmake @@ -18,3 +18,9 @@ add_test(NAME UsesEmulatorWithExecTargetFromSubdirAddedWithoutGenex add_test(NAME DoesNotUseEmulatorWithExecTargetFromSubdirAddedWithGenex COMMAND $<TARGET_FILE:generated_exe_in_subdir_added_to_test_with_genex>) + +add_executable(generated_exe_test_launcher simple_src_exiterror.cxx) +set_property(TARGET generated_exe_test_launcher PROPERTY TEST_LAUNCHER "pseudo_test_launcher") + +add_test(NAME UsesTestLauncherAndEmulator + COMMAND generated_exe_test_launcher) diff --git a/Tests/RunCMake/add_test/RunCMakeTest.cmake b/Tests/RunCMake/add_test/RunCMakeTest.cmake index ec6f6dd..8b5c915 100644 --- a/Tests/RunCMake/add_test/RunCMakeTest.cmake +++ b/Tests/RunCMake/add_test/RunCMakeTest.cmake @@ -41,3 +41,9 @@ block() set(RunCMake_TEST_NO_CLEAN 1) run_cmake_command(EmptyArgument-ctest ${CMAKE_CTEST_COMMAND} -C Debug) endblock() + +set(RunCMake_TEST_OPTIONS + "-DCMAKE_TEST_LAUNCHER=/path/to/pseudo_test_launcher") + +run_cmake(TestLauncherProperty) +run_cmake(TestLauncher) diff --git a/Tests/RunCMake/add_test/TestLauncher-check.cmake b/Tests/RunCMake/add_test/TestLauncher-check.cmake new file mode 100644 index 0000000..78020a6 --- /dev/null +++ b/Tests/RunCMake/add_test/TestLauncher-check.cmake @@ -0,0 +1,28 @@ +set(testfile "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake") +if(EXISTS "${testfile}") + file(READ "${testfile}" testfile_contents) +else() + message(FATAL_ERROR "Could not find expected CTestTestfile.cmake.") +endif() + +set(error_details "There is a problem with generated test file: ${testfile}") + +if(testfile_contents MATCHES "add_test[(]DoesNotUseTestLauncher [^\n]+pseudo_test_launcher[^\n]+\n") + message(SEND_ERROR "Used test launcher when it should not be used. ${error_details}") +endif() + +if(NOT testfile_contents MATCHES "add_test[(]UsesTestLauncher [^\n]+pseudo_test_launcher[^\n]+\n") + message(SEND_ERROR "Did not use test launcher when it should be used. ${error_details}") +endif() + +if(testfile_contents MATCHES "add_test[(]DoesNotUseTestLauncherWithGenex [^\n]+pseudo_test_launcher[^\n]+\n") + message(SEND_ERROR "Used test launcher when it should not be used. ${error_details}") +endif() + +if(NOT testfile_contents MATCHES "add_test[(]UsesTestLauncherWithExecTargetFromSubdirAddedWithoutGenex [^\n]+pseudo_test_launcher[^\n]+\n") + message(SEND_ERROR "Did not use test launcher when it should be used. ${error_details}") +endif() + +if(testfile_contents MATCHES "add_test[(]DoesNotUseTestLauncherWithExecTargetFromSubdirAddedWithGenex [^\n]+pseudo_test_launcher[^\n]+\n") + message(SEND_ERROR "Used test launcher when it should not be used. ${error_details}") +endif() diff --git a/Tests/RunCMake/add_test/TestLauncher.cmake b/Tests/RunCMake/add_test/TestLauncher.cmake new file mode 100644 index 0000000..8ad3be9 --- /dev/null +++ b/Tests/RunCMake/add_test/TestLauncher.cmake @@ -0,0 +1,22 @@ +project(test_launcher LANGUAGES C) + +enable_testing() +add_test(NAME DoesNotUseLauncher + COMMAND ${CMAKE_COMMAND} -E echo "Hi") + +add_executable(generated_exe simple_src_exiterror.cxx) +set_target_properties(generated_exe PROPERTIES LINKER_LANGUAGE C) + +add_test(NAME UsesTestLauncher + COMMAND generated_exe) + +add_test(NAME DoesNotUseTestLauncherWithGenex + COMMAND $<TARGET_FILE:generated_exe>) + +add_subdirectory(TestLauncher) + +add_test(NAME UsesTestLauncherWithExecTargetFromSubdirAddedWithoutGenex + COMMAND generated_exe_in_subdir_added_to_test_without_genex) + +add_test(NAME DoesNotUseTestLauncherWithExecTargetFromSubdirAddedWithGenex + COMMAND $<TARGET_FILE:generated_exe_in_subdir_added_to_test_with_genex>) diff --git a/Tests/RunCMake/add_test/TestLauncher/CMakeLists.txt b/Tests/RunCMake/add_test/TestLauncher/CMakeLists.txt new file mode 100644 index 0000000..fb40a59 --- /dev/null +++ b/Tests/RunCMake/add_test/TestLauncher/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable(generated_exe_in_subdir_added_to_test_without_genex + ${CMAKE_CURRENT_SOURCE_DIR}/../simple_src_exiterror.cxx) +set_target_properties(generated_exe_in_subdir_added_to_test_without_genex + PROPERTIES LINKER_LANGUAGE C) + +add_executable(generated_exe_in_subdir_added_to_test_with_genex + ${CMAKE_CURRENT_SOURCE_DIR}/../simple_src_exiterror.cxx) +set_target_properties(generated_exe_in_subdir_added_to_test_with_genex + PROPERTIES LINKER_LANGUAGE C) diff --git a/Tests/RunCMake/add_test/TestLauncherProperty.cmake b/Tests/RunCMake/add_test/TestLauncherProperty.cmake new file mode 100644 index 0000000..e86f42b --- /dev/null +++ b/Tests/RunCMake/add_test/TestLauncherProperty.cmake @@ -0,0 +1,41 @@ + +# This tests setting the TEST_LAUNCHER target property from the +# CMAKE_TEST_LAUNCHER variable. + +# -DCMAKE_TEST_LAUNCHER=/path/to/pseudo_test_launcher is passed to this +# test + +project(test_launcher LANGUAGES C) + +add_executable(target_with_test_launcher simple_src_exiterror.cxx) +set_target_properties(target_with_test_launcher PROPERTIES LINKER_LANGUAGE C) +get_property(launcher TARGET target_with_test_launcher + PROPERTY TEST_LAUNCHER) +if(NOT "${launcher}" MATCHES "pseudo_test_launcher") + message(SEND_ERROR "Default TEST_LAUNCHER property not set") +endif() + +set_property(TARGET target_with_test_launcher + PROPERTY TEST_LAUNCHER "another_test_launcher") +get_property(launcher TARGET target_with_test_launcher + PROPERTY TEST_LAUNCHER) +if(NOT "${launcher}" MATCHES "another_test_launcher") + message(SEND_ERROR + "set_property/get_property TEST_LAUNCHER is not consistent") +endif() + +unset(CMAKE_TEST_LAUNCHER CACHE) +add_executable(target_without_test_launcher simple_src_exiterror.cxx) +set_target_properties(target_without_test_launcher PROPERTIES LINKER_LANGUAGE C) +get_property(launcher TARGET target_without_test_launcher + PROPERTY TEST_LAUNCHER) +if(NOT "${launcher}" STREQUAL "") + message(SEND_ERROR "Default TEST_LAUNCHER property not set to null") +endif() + +add_executable(target_with_empty_test_launcher simple_src_exiterror.cxx) +set_target_properties(target_with_empty_test_launcher PROPERTIES LINKER_LANGUAGE C) +set_property(TARGET target_with_empty_test_launcher PROPERTY TEST_LAUNCHER "") + +enable_testing() +add_test(NAME test_target_with_empty_test_launcher COMMAND target_with_empty_test_launcher) diff --git a/Tests/RunCMake/add_test/simple_src_exiterror.cxx b/Tests/RunCMake/add_test/simple_src_exiterror.cxx new file mode 100644 index 0000000..6ce7183 --- /dev/null +++ b/Tests/RunCMake/add_test/simple_src_exiterror.cxx @@ -0,0 +1,4 @@ +int main(int, char**) +{ + return 13; +} |