Add TEST_INCLUDE_DIR[S] unit test

Add a unit test for the TEST_INCLUDE_DIR and (new) TEST_INCLUDE_DIRS
directory properties.
This commit is contained in:
Matthew Woehlke 2017-07-10 12:09:24 -04:00
parent ed5bde30f7
commit 117033c1d9
7 changed files with 79 additions and 0 deletions

View File

@ -223,6 +223,7 @@ add_RunCMake_test(return)
add_RunCMake_test(separate_arguments)
add_RunCMake_test(set_property)
add_RunCMake_test(string)
add_RunCMake_test(test_include_dirs)
foreach(var
CMAKE_C_COMPILER_ID
CMAKE_C_COMPILER_VERSION

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.6)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@ -0,0 +1,17 @@
include(RunCMake)
function(run_TID)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TID-build)
set(RunCMake_TEST_NO_CLEAN 1)
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(TID)
run_cmake_command(TID-build ${CMAKE_COMMAND} --build . --config Debug)
run_cmake_command(TID-test ${CMAKE_CTEST_COMMAND} -C Debug)
endfunction()
run_TID()

View File

@ -0,0 +1,17 @@
Test project .*
Start 1: house\.dog
1/6 Test #1: house\.dog \.+ +Passed +[0-9.]+ sec
Start 2: house\.cat
2/6 Test #2: house\.cat \.+ +Passed +[0-9.]+ sec
Start 3: farm\.cow
3/6 Test #3: farm\.cow \.+ +Passed +[0-9.]+ sec
Start 4: farm\.pig
4/6 Test #4: farm\.pig \.+ +Passed +[0-9.]+ sec
Start 5: zoo\.fox
5/6 Test #5: zoo\.fox \.+ +Passed +[0-9.]+ sec
Start 6: zoo\.emu
6/6 Test #6: zoo\.emu \.+ +Passed +[0-9.]+ sec
100% tests passed, 0 tests failed out of 6
Total Test time \(real\) = +[0-9.]+ sec

View File

@ -0,0 +1,29 @@
project(test_include_dirs)
include(CTest)
enable_testing()
add_executable(dummy dummy.cpp)
function(generate_tests NAME)
set(ctest_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_tests.cmake")
add_custom_command(
OUTPUT "${ctest_file}"
COMMAND "${CMAKE_COMMAND}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:dummy>"
-D "TEST_SUITE=${NAME}"
-D "TEST_NAMES=${ARGN}"
-D "CTEST_FILE=${ctest_file}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/add-tests.cmake"
VERBATIM
)
add_custom_target(${NAME}_tests ALL DEPENDS "${ctest_file}")
endfunction()
generate_tests(house dog cat)
generate_tests(farm cow pig)
generate_tests(zoo fox emu)
set_property(DIRECTORY PROPERTY TEST_INCLUDE_FILE "house_tests.cmake")
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES "farm_tests.cmake")
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES "zoo_tests.cmake")

View File

@ -0,0 +1,8 @@
set(script)
foreach(TEST_NAME ${TEST_NAMES})
set(script "${script}add_test(\"${TEST_SUITE}.${TEST_NAME}\"")
set(script "${script} \"${TEST_EXECUTABLE}\")\n")
endforeach()
file(WRITE "${CTEST_FILE}" "${script}")

View File

@ -0,0 +1,4 @@
int main()
{
return 0;
}