Commit 73a058f8 authored by Brad King's avatar Brad King

Tests: Add RunCMake.BuildDepends test

This will allow more granular checks than the main BuildDepends test.
Start with a simple single-source C program.
parent 438fabf2
enable_language(C)
add_executable(main ${CMAKE_CURRENT_BINARY_DIR}/main.c)
file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
set(check_pairs
\"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/main.c\"
)
set(check_exes
\"$<TARGET_FILE:main>\"
)
")
file(WRITE "${RunCMake_TEST_BINARY_DIR}/main.c" [[
int main(void) { return 1; }
]])
file(WRITE "${RunCMake_TEST_BINARY_DIR}/main.c" [[
int main(void) { return 2; }
]])
cmake_minimum_required(VERSION 3.3)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
include(RunCMake)
function(run_BuildDepends CASE)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${CASE}-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}")
include(${RunCMake_SOURCE_DIR}/${CASE}.step1.cmake OPTIONAL)
run_cmake(${CASE})
set(RunCMake-check-file check.cmake)
set(check_step 1)
run_cmake_command(${CASE}-build1 ${CMAKE_COMMAND} --build . --config Debug)
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1.125) # handle 1s resolution
include(${RunCMake_SOURCE_DIR}/${CASE}.step2.cmake OPTIONAL)
set(check_step 2)
run_cmake_command(${CASE}-build2 ${CMAKE_COMMAND} --build . --config Debug)
endfunction()
run_BuildDepends(C-Exe)
if(EXISTS ${RunCMake_TEST_BINARY_DIR}/check-debug.cmake)
include(${RunCMake_TEST_BINARY_DIR}/check-debug.cmake)
foreach(exe IN LISTS check_exes)
execute_process(COMMAND ${exe} RESULT_VARIABLE res)
if(NOT res EQUAL ${check_step})
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}
'${exe}' returned '${res}' but expected '${check_step}'
")
endif()
endforeach()
foreach(p IN LISTS check_pairs)
if("${p}" MATCHES "^(.*)\\|(.*)$")
set(lhs "${CMAKE_MATCH_1}")
set(rhs "${CMAKE_MATCH_2}")
if(NOT EXISTS "${lhs}")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}
'${lhs}' missing
")
elseif(NOT EXISTS "${rhs}")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}
'${rhs}' missing
")
elseif(NOT "${lhs}" IS_NEWER_THAN "${rhs}")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}
'${lhs}' is not newer than '${rhs}'
")
endif()
endif()
endforeach()
else()
set(RunCMake_TEST_FAILED "
'${RunCMake_TEST_BINARY_DIR}/check-debug.cmake' missing
")
endif()
......@@ -124,6 +124,7 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
)
endif()
add_RunCMake_test(BuildDepends)
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
add_RunCMake_test(CompilerChange)
endif()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment