From 55b2aa884cdb3df9a32152ee1df60e708d2c5ec9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 9 Mar 2012 16:47:19 -0500 Subject: [PATCH] Use generalized RunCMake test infrastrucure for build_command test The CMakeCommands.build_command test performs output/error checking so move it over to RunCMake to re-use the generalized infrastrucure. This is the only test left using Tests/CMakeCommands/CMakeLists.txt so remove it. --- Tests/CMakeCommands/CMakeLists.txt | 10 --- Tests/CMakeCommands/build_command/test.cmake | 86 ------------------- Tests/CMakeLists.txt | 1 - Tests/RunCMake/CMakeLists.txt | 1 + .../build_command/CMakeLists.txt | 7 +- .../build_command/ErrorsOFF-stderr.txt | 1 + .../build_command/ErrorsOFF-stdout.txt | 1 + Tests/RunCMake/build_command/ErrorsOFF.cmake | 1 + .../build_command/ErrorsON-result.txt | 1 + .../build_command/ErrorsON-stderr.txt | 12 +++ .../build_command/ErrorsON-stdout.txt | 1 + Tests/RunCMake/build_command/ErrorsON.cmake | 1 + .../RunCMake/build_command/RunCMakeTest.cmake | 4 + 13 files changed, 27 insertions(+), 100 deletions(-) delete mode 100644 Tests/CMakeCommands/CMakeLists.txt delete mode 100644 Tests/CMakeCommands/build_command/test.cmake rename Tests/{CMakeCommands => RunCMake}/build_command/CMakeLists.txt (96%) create mode 100644 Tests/RunCMake/build_command/ErrorsOFF-stderr.txt create mode 100644 Tests/RunCMake/build_command/ErrorsOFF-stdout.txt create mode 100644 Tests/RunCMake/build_command/ErrorsOFF.cmake create mode 100644 Tests/RunCMake/build_command/ErrorsON-result.txt create mode 100644 Tests/RunCMake/build_command/ErrorsON-stderr.txt create mode 100644 Tests/RunCMake/build_command/ErrorsON-stdout.txt create mode 100644 Tests/RunCMake/build_command/ErrorsON.cmake create mode 100644 Tests/RunCMake/build_command/RunCMakeTest.cmake diff --git a/Tests/CMakeCommands/CMakeLists.txt b/Tests/CMakeCommands/CMakeLists.txt deleted file mode 100644 index e9e4020e1..000000000 --- a/Tests/CMakeCommands/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -macro(add_CMakeCommands_test test) - add_test(CMakeCommands.${test} ${CMAKE_CMAKE_COMMAND} - -DCMake_SOURCE_DIR=${CMake_SOURCE_DIR} # TODO: Remove - -Ddir=${CMAKE_CURRENT_BINARY_DIR}/${test} - -Dgen=${CMAKE_TEST_GENERATOR} - -P "${CMAKE_CURRENT_SOURCE_DIR}/${test}/test.cmake" - ) -endmacro() - -add_CMakeCommands_test(build_command) diff --git a/Tests/CMakeCommands/build_command/test.cmake b/Tests/CMakeCommands/build_command/test.cmake deleted file mode 100644 index 55d935960..000000000 --- a/Tests/CMakeCommands/build_command/test.cmake +++ /dev/null @@ -1,86 +0,0 @@ -if(NOT DEFINED CMake_SOURCE_DIR) - message(FATAL_ERROR "CMake_SOURCE_DIR not defined") -endif() - -if(NOT DEFINED dir) - message(FATAL_ERROR "dir not defined") -endif() - -if(NOT DEFINED gen) - message(FATAL_ERROR "gen not defined") -endif() - -message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") - -# Run cmake: -# -function(run_cmake build_dir extra_args expected_result expected_output expected_error) - message(STATUS "run_cmake build_dir='${build_dir}' extra_args='${extra_args}'") - - # Ensure build_dir exists: - # - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${build_dir}) - - # Run cmake: - # - execute_process(COMMAND ${CMAKE_COMMAND} - ${extra_args} - -G ${gen} ${CMake_SOURCE_DIR}/Tests/CMakeCommands/build_command - RESULT_VARIABLE result - OUTPUT_VARIABLE stdout - ERROR_VARIABLE stderr - WORKING_DIRECTORY ${build_dir} - ) - - message(STATUS "result='${result}'") - message(STATUS "stdout='${stdout}'") - message(STATUS "stderr='${stderr}'") - message(STATUS "") - - # Verify result and output match expectations: - # - if("0" STREQUAL "${expected_result}") - if(NOT "${result}" STREQUAL "0") - message(FATAL_ERROR - "error: result='${result}' is non-zero and different than expected_result='${expected_result}'") - endif() - else() - if("${result}" STREQUAL "0") - message(FATAL_ERROR - "error: result='${result}' is zero and different than expected_result='${expected_result}'") - endif() - endif() - - foreach(e ${expected_output}) - if(NOT stdout MATCHES "${e}") - message(FATAL_ERROR - "error: stdout does not match expected_output item e='${e}'") - else() - message(STATUS "info: stdout matches '${e}'") - endif() - endforeach() - - foreach(e ${expected_error}) - if(NOT stderr MATCHES "${e}") - message(FATAL_ERROR - "error: stderr does not match expected_error item e='${e}'") - else() - message(STATUS "info: stderr matches '${e}'") - endif() - endforeach() - - message(STATUS "result, stdout and stderr match all expectations: test passes") - message(STATUS "") -endfunction() - - -# Expect this case to succeed: -run_cmake("${dir}/b1" "" 0 - "Build files have been written to:" - "skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF") - - -# Expect this one to fail: -run_cmake("${dir}/b2" "-DTEST_ERROR_CONDITIONS:BOOL=ON" 1 - "Configuring incomplete, errors occurred!" - "build_command requires at least one argument naming a CMake variable;build_command unknown argument ") diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 0eb48597e..cf4dc446e 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -53,7 +53,6 @@ IF(BUILD_TESTING) ADD_SUBDIRECTORY(CMakeLib) ADD_SUBDIRECTORY(CMakeOnly) - ADD_SUBDIRECTORY(CMakeCommands) ADD_SUBDIRECTORY(RunCMake) ADD_SUBDIRECTORY(FindPackageModeMakefileTest) diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 2dbb08e6f..63fc9f8f3 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -40,4 +40,5 @@ macro(add_RunCMake_test test) ) endmacro() +add_RunCMake_test(build_command) add_RunCMake_test(find_package) diff --git a/Tests/CMakeCommands/build_command/CMakeLists.txt b/Tests/RunCMake/build_command/CMakeLists.txt similarity index 96% rename from Tests/CMakeCommands/build_command/CMakeLists.txt rename to Tests/RunCMake/build_command/CMakeLists.txt index 990ac90ce..0fbb94803 100644 --- a/Tests/CMakeCommands/build_command/CMakeLists.txt +++ b/Tests/RunCMake/build_command/CMakeLists.txt @@ -1,3 +1,7 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) + # This CMakeLists file is *sometimes expected* to result in a configure error. # # expect this to succeed: @@ -12,12 +16,9 @@ # ...even purposefully calling it with known-bad argument lists to cover # error handling code. # -cmake_minimum_required(VERSION 2.8) -project(test_build_command) set(cmd "initial") -message("CTEST_FULL_OUTPUT") message("0. begin") if(TEST_ERROR_CONDITIONS) diff --git a/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt b/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt new file mode 100644 index 000000000..331885b94 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt @@ -0,0 +1 @@ +skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF diff --git a/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt b/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt new file mode 100644 index 000000000..cf66a9d7a --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt @@ -0,0 +1 @@ +Build files have been written to: diff --git a/Tests/RunCMake/build_command/ErrorsOFF.cmake b/Tests/RunCMake/build_command/ErrorsOFF.cmake new file mode 100644 index 000000000..a243fab01 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsOFF.cmake @@ -0,0 +1 @@ +set(TEST_ERROR_CONDITIONS OFF) diff --git a/Tests/RunCMake/build_command/ErrorsON-result.txt b/Tests/RunCMake/build_command/ErrorsON-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/build_command/ErrorsON-stderr.txt b/Tests/RunCMake/build_command/ErrorsON-stderr.txt new file mode 100644 index 000000000..0be7475d7 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON-stderr.txt @@ -0,0 +1,12 @@ +CMake Error at CMakeLists.txt:[0-9]+ \(build_command\): + build_command requires at least one argument naming a CMake variable + ++ +1. cmd='initial' +CMake Error at CMakeLists.txt:[0-9]+ \(build_command\): + build_command unknown argument "BOGUS" + ++ +2. cmd='initial' +CMake Error at CMakeLists.txt:[0-9]+ \(build_command\): + build_command unknown argument "STUFF" diff --git a/Tests/RunCMake/build_command/ErrorsON-stdout.txt b/Tests/RunCMake/build_command/ErrorsON-stdout.txt new file mode 100644 index 000000000..841dd0d88 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON-stdout.txt @@ -0,0 +1 @@ +Configuring incomplete, errors occurred! diff --git a/Tests/RunCMake/build_command/ErrorsON.cmake b/Tests/RunCMake/build_command/ErrorsON.cmake new file mode 100644 index 000000000..27814bf64 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON.cmake @@ -0,0 +1 @@ +set(TEST_ERROR_CONDITIONS ON) diff --git a/Tests/RunCMake/build_command/RunCMakeTest.cmake b/Tests/RunCMake/build_command/RunCMakeTest.cmake new file mode 100644 index 000000000..4525c5725 --- /dev/null +++ b/Tests/RunCMake/build_command/RunCMakeTest.cmake @@ -0,0 +1,4 @@ +include(RunCMake) + +run_cmake(ErrorsOFF) +run_cmake(ErrorsON)