diff options
Diffstat (limited to 'Tests')
33 files changed, 1288 insertions, 9 deletions
diff --git a/Tests/BuildDepends/CMakeLists.txt b/Tests/BuildDepends/CMakeLists.txt index d8f8360..8714640 100644 --- a/Tests/BuildDepends/CMakeLists.txt +++ b/Tests/BuildDepends/CMakeLists.txt @@ -28,6 +28,12 @@ function(help_xcode_depends) endif(HELP_XCODE) endfunction(help_xcode_depends) +# The Intel compiler causes the MSVC linker to crash during +# incremental linking, so avoid the /INCREMENTAL:YES flag. +if(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel") + set(_cmake_options "-DCMAKE_EXE_LINKER_FLAGS=") +endif() + file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project) message("Creating Project/foo.cxx") write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx @@ -49,6 +55,7 @@ try_compile(RESULT ${BuildDepends_BINARY_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project testRebuild + CMAKE_FLAGS ${_cmake_options} OUTPUT_VARIABLE OUTPUT) if(HELP_XCODE) try_compile(RESULT @@ -63,8 +70,9 @@ if(HELP_XCODE) OUTPUT_VARIABLE OUTPUT) endif(HELP_XCODE) +message("Output from first build:\n${OUTPUT}") if(NOT RESULT) - message(SEND_ERROR "Could not build test project: ${OUTPUT}") + message(SEND_ERROR "Could not build test project (1)!") endif(NOT RESULT) set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX}) @@ -130,6 +138,7 @@ try_compile(RESULT ${BuildDepends_BINARY_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project testRebuild + CMAKE_FLAGS ${_cmake_options} OUTPUT_VARIABLE OUTPUT) # Xcode is in serious need of help here @@ -146,8 +155,9 @@ if(HELP_XCODE) OUTPUT_VARIABLE OUTPUT) endif(HELP_XCODE) +message("Output from second build:\n${OUTPUT}") if(NOT RESULT) - message(SEND_ERROR "Could not build test project: ${OUTPUT}") + message(SEND_ERROR "Could not build test project (2)!") endif(NOT RESULT) if(EXISTS "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" ) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index f21efd7..357b0c6 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -35,6 +35,11 @@ IF(BUILD_TESTING) "Should the tests that run a full sub ctest process be run?" OFF) MARK_AS_ADVANCED(CTEST_TEST_CTEST) + + OPTION(TEST_KDE4_STABLE_BRANCH + "Should the KDE4 stable branch test be run?" + OFF) + MARK_AS_ADVANCED(TEST_KDE4_STABLE_BRANCH) ENDIF (CMAKE_RUN_LONG_TESTS) # Should tests that use CVS be run? @@ -410,14 +415,15 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel set(CTEST_RUN_CPackComponents ${CTEST_TEST_CPACK}) set(CTEST_package_X11_TEST ${CTEST_TEST_CPACK}) + find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis + PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS] + DOC "makensis program location" + ) + # But on Windows, only run the CPackComponents test if the NSIS # installer builder is available: # if(WIN32) - find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis - PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS] - DOC "makensis.exe location" - ) if(NSIS_MAKENSIS_EXECUTABLE) set(CTEST_RUN_CPackComponents ON) else(NSIS_MAKENSIS_EXECUTABLE) @@ -431,6 +437,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel if(APPLE) set(CPackComponents_EXTRA_OPTIONS -DCPACK_BINARY_DRAGNDROP:BOOL=ON) endif(APPLE) + if(NSIS_MAKENSIS_EXECUTABLE) + set(CPackComponents_EXTRA_OPTIONS ${CPackComponents_EXTRA_OPTIONS} + -DCPACK_BINARY_NSIS:BOOL=ON) + endif(NSIS_MAKENSIS_EXECUTABLE) ADD_TEST(CPackComponents ${CMAKE_CTEST_COMMAND} --build-and-test @@ -445,12 +455,47 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel -DCPACK_BINARY_DEB:BOOL=${CPACK_BINARY_DEB} -DCPACK_BINARY_RPM:BOOL=${CPACK_BINARY_RPM} ${CPackComponents_EXTRA_OPTIONS} + --graphviz=CPackComponents.dot --test-command ${CMAKE_CMAKE_COMMAND} "-DCPackComponents_BINARY_DIR:PATH=${CMake_BINARY_DIR}/Tests/CPackComponents" -P "${CMake_SOURCE_DIR}/Tests/CPackComponents/VerifyResult.cmake") LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackComponents") ENDIF(CTEST_RUN_CPackComponents) + # By default, turn this test off (because it takes a long time...) + # + if(NOT DEFINED CTEST_RUN_CPackTestAllGenerators) + set(CTEST_RUN_CPackTestAllGenerators OFF) + + # ...but: if it appears to be a coverage dashboard, or long tests are + # on, then set it to the generic CTEST_TEST_CPACK setting. + # + if(CMAKE_CXX_FLAGS MATCHES "-ftest-coverage" OR + NOT "$ENV{COVFILE}" STREQUAL "" OR + CMAKE_RUN_LONG_TESTS) + set(CTEST_RUN_CPackTestAllGenerators ${CTEST_TEST_CPACK}) + endif(CMAKE_CXX_FLAGS MATCHES "-ftest-coverage" OR + NOT "$ENV{COVFILE}" STREQUAL "" OR + CMAKE_RUN_LONG_TESTS) + endif(NOT DEFINED CTEST_RUN_CPackTestAllGenerators) + + IF(CTEST_RUN_CPackTestAllGenerators) + ADD_TEST(CPackTestAllGenerators ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/CPackTestAllGenerators" + "${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project CPackTestAllGenerators + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --test-command + ${CMAKE_CMAKE_COMMAND} + -D dir=${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators + -D cpack=${CMAKE_CPACK_COMMAND} + -P ${CMake_SOURCE_DIR}/Tests/CPackTestAllGenerators/RunCPack.cmake + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackTestAllGenerators") + ENDIF(CTEST_RUN_CPackTestAllGenerators) + IF(CTEST_package_X11_TEST) SET(X11_build_target_arg --build-target package) ELSE(CTEST_package_X11_TEST) @@ -469,6 +514,50 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel --test-command UseX11) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/X11") + if(NOT DEFINED CTEST_RUN_CMakeTestAllGenerators) + set(CTEST_RUN_CMakeTestAllGenerators ON) + endif(NOT DEFINED CTEST_RUN_CMakeTestAllGenerators) + + IF(CTEST_RUN_CMakeTestAllGenerators) + ADD_TEST(CMakeTestAllGenerators ${CMAKE_CMAKE_COMMAND} + -D dir=${CMake_BINARY_DIR}/Tests/CMakeTestAllGenerators + -D CMake_SOURCE_DIR=${CMake_SOURCE_DIR} + -P ${CMake_SOURCE_DIR}/Tests/CMakeTestAllGenerators/RunCMake.cmake + ) + LIST(APPEND TEST_BUILD_DIRS + "${CMake_BINARY_DIR}/Tests/CMakeTestAllGenerators") + ENDIF(CTEST_RUN_CMakeTestAllGenerators) + + if(NOT DEFINED CTEST_RUN_CMakeTestBadCommandLines) + set(CTEST_RUN_CMakeTestBadCommandLines ON) + endif(NOT DEFINED CTEST_RUN_CMakeTestBadCommandLines) + + IF(CTEST_RUN_CMakeTestBadCommandLines) + ADD_TEST(CMakeTestBadCommandLines ${CMAKE_CMAKE_COMMAND} + -D dir=${CMake_BINARY_DIR}/Tests/CMakeTestBadCommandLines + -D gen=${CMAKE_TEST_GENERATOR} + -D CMake_SOURCE_DIR=${CMake_SOURCE_DIR} + -P ${CMake_SOURCE_DIR}/Tests/CMakeTestBadCommandLines/RunCMake.cmake + ) + LIST(APPEND TEST_BUILD_DIRS + "${CMake_BINARY_DIR}/Tests/CMakeTestBadCommandLines") + ENDIF(CTEST_RUN_CMakeTestBadCommandLines) + + if(NOT DEFINED CTEST_RUN_CMakeTestMultipleConfigures) + set(CTEST_RUN_CMakeTestMultipleConfigures ON) + endif(NOT DEFINED CTEST_RUN_CMakeTestMultipleConfigures) + + IF(CTEST_RUN_CMakeTestMultipleConfigures) + ADD_TEST(CMakeTestMultipleConfigures ${CMAKE_CMAKE_COMMAND} + -D dir=${CMake_BINARY_DIR}/Tests/CMakeTestMultipleConfigures + -D gen=${CMAKE_TEST_GENERATOR} + -D CMake_SOURCE_DIR=${CMake_SOURCE_DIR} + -P ${CMake_SOURCE_DIR}/Tests/CMakeTestMultipleConfigures/RunCMake.cmake + ) + LIST(APPEND TEST_BUILD_DIRS + "${CMake_BINARY_DIR}/Tests/CMakeTestMultipleConfigures") + ENDIF(CTEST_RUN_CMakeTestMultipleConfigures) + ADD_TEST(LoadedCommandOneConfig ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/LoadCommandOneConfig" @@ -1100,6 +1189,15 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel ) CONFIGURE_FILE( + "${CMake_SOURCE_DIR}/Tests/CTestTestSubdir/test.cmake.in" + "${CMake_BINARY_DIR}/Tests/CTestTestSubdir/test.cmake" + @ONLY ESCAPE_QUOTES) + ADD_TEST(CTestTestSubdir ${CMAKE_CTEST_COMMAND} + -S "${CMake_BINARY_DIR}/Tests/CTestTestSubdir/test.cmake" -V + --output-log "${CMake_BINARY_DIR}/Tests/CTestTestSubdir/testOutput.log" + ) + + CONFIGURE_FILE( "${CMake_SOURCE_DIR}/Tests/CTestTestTimeout/test.cmake.in" "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/test.cmake" @ONLY ESCAPE_QUOTES) @@ -1110,8 +1208,69 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel SET_TESTS_PROPERTIES(CTestTestTimeout PROPERTIES PASS_REGULAR_EXPRESSION "\\*\\*\\*Timeout") + CONFIGURE_FILE( + "${CMake_SOURCE_DIR}/Tests/CTestTestRunScript/test.cmake" + "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/test.cmake" + @ONLY ESCAPE_QUOTES) + CONFIGURE_FILE( + "${CMake_SOURCE_DIR}/Tests/CTestTestRunScript/hello.cmake" + "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/hello.cmake" + @ONLY ESCAPE_QUOTES) + #ADD_TEST(CTestTestRunScript ${CMAKE_CTEST_COMMAND} + # -S "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/test.cmake" -V + # --output-log "${CMake_BINARY_DIR}/Tests/CTestTestRunScript/testOutput.log" + # ) + ADD_TEST(CTestTestShowOnly ${CMAKE_CTEST_COMMAND} -N) + ADD_TEST(CTestBatchTest ${CMAKE_CTEST_COMMAND} -B) + + # Use macro, not function so that build can still be driven by CMake 2.4. + # After 2.6 is required, this could be a function without the extra 'set' + # calls. + # + macro(add_failed_submit_test name source build in out log regex) + # Have variables named source, build and drop_method because the + # configure_file call expects those variables to be defined. + # + set(source "${source}") + set(build "${build}") + configure_file("${in}" "${out}" @ONLY) + add_test(${name} ${CMAKE_CTEST_COMMAND} -S "${out}" -V --output-log "${log}") + set_tests_properties(${name} PROPERTIES PASS_REGULAR_EXPRESSION "${regex}") + endmacro() + + set(regex "(Problems when submitting via S*CP") + set(regex "${regex}|Error message was: ") + set(regex "${regex}(Couldn.t resolve host ") + set(regex "${regex}|couldn.t connect to host") + set(regex "${regex}|libcurl was built with SSL disabled. https: not supported)") + set(regex "${regex}|Submission method .xmlrpc. not compiled into CTest") + set(regex "${regex}|Submission successful)") + + set(ctest_coverage_labels_args "") + + foreach(drop_method cp ftp http https scp xmlrpc) + # Cycle through these values each time through the loop: + if(ctest_coverage_labels_args STREQUAL "") + set(ctest_coverage_labels_args "LABELS Everything") + elseif(ctest_coverage_labels_args STREQUAL "LABELS Everything") + set(ctest_coverage_labels_args "LABELS 0ArgTest") + else() + set(ctest_coverage_labels_args "") + endif() + + add_failed_submit_test(CTestTestFailedSubmit-${drop_method} + "${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast" + "${CMake_BINARY_DIR}/Tests/CTestTestFailedSubmits/${drop_method}" + "${CMake_SOURCE_DIR}/Tests/CTestTestFailedSubmits/test.cmake.in" + "${CMake_BINARY_DIR}/Tests/CTestTestFailedSubmits/test-${drop_method}.cmake" + "${CMake_BINARY_DIR}/Tests/CTestTestFailedSubmits/test-${drop_method}.log" + "${regex}" + ) + endforeach() + + IF (CTEST_TEST_CTEST AND CMAKE_RUN_LONG_TESTS) CONFIGURE_FILE("${CMake_SOURCE_DIR}/Tests/CTestTest/test.cmake.in" "${CMake_BINARY_DIR}/Tests/CTestTest/test.cmake" @ONLY ESCAPE_QUOTES) @@ -1152,6 +1311,43 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT}) ENDIF ("${PREVIOUS_TIMEOUT}" MATCHES NOTFOUND) ENDIF (CTEST_TEST_CTEST AND CMAKE_RUN_LONG_TESTS) + + IF (CMAKE_RUN_LONG_TESTS AND TEST_KDE4_STABLE_BRANCH) + IF(UNIX) + IF(NOT QT4_FOUND) + FIND_PACKAGE(Qt4) + ENDIF(NOT QT4_FOUND) + + SET(TRY_BUILD_KDE4 TRUE) + IF(QT4_FOUND) + # check whether it's Qt 4.5 in a cmake 2.4. compatible way: + IF(NOT EXISTS "${QT_QTNETWORK_INCLUDE_DIR}/QAbstractNetworkCache") + SET(TRY_BUILD_KDE4 FALSE) + ENDIF(NOT EXISTS "${QT_QTNETWORK_INCLUDE_DIR}/QAbstractNetworkCache") + ELSE(QT4_FOUND) + SET(TRY_BUILD_KDE4 FALSE) + ENDIF(QT4_FOUND) + + FIND_PACKAGE(Perl) + IF(NOT PERL_FOUND) + SET(TRY_BUILD_KDE4 FALSE) + ENDIF(NOT PERL_FOUND) + + FIND_PACKAGE(ZLIB) + IF(NOT ZLIB_FOUND) + SET(TRY_BUILD_KDE4 FALSE) + ENDIF(NOT ZLIB_FOUND) + + IF(TRY_BUILD_KDE4) + FILE(MAKE_DIRECTORY ${CMake_BINARY_DIR}/Tests/KDE4StableBranchTest) + SET(TEST_KDE4_BASE_DIR ${CMake_BINARY_DIR}/Tests/KDE4StableBranchTest) + CONFIGURE_FILE(${CMake_SOURCE_DIR}/Tests/KDE4StableBranchTest/test_kde4.sh.in ${CMake_BINARY_DIR}/Tests/KDE4StableBranchTest/test_kde4.sh @ONLY) + EXECUTE_PROCESS(COMMAND chmod 755 ${CMake_BINARY_DIR}/Tests/KDE4StableBranchTest/test_kde4.sh ) + ADD_TEST(KDE4StableBranchTest ${CMake_BINARY_DIR}/Tests/KDE4StableBranchTest/test_kde4.sh) + ENDIF(TRY_BUILD_KDE4) + + ENDIF(UNIX) + ENDIF (CMAKE_RUN_LONG_TESTS AND TEST_KDE4_STABLE_BRANCH) IF("${CMAKE_TEST_GENERATOR}" MATCHES Xcode) SET(CMAKE_SKIP_BOOTSTRAP_TEST 1) diff --git a/Tests/CMakeTestAllGenerators/RunCMake.cmake b/Tests/CMakeTestAllGenerators/RunCMake.cmake new file mode 100644 index 0000000..dcf4a23 --- /dev/null +++ b/Tests/CMakeTestAllGenerators/RunCMake.cmake @@ -0,0 +1,95 @@ +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() + +# Analyze 'cmake --help' output for list of available generators: +# +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}) +execute_process(COMMAND ${CMAKE_COMMAND} --help + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}) + +string(REPLACE ";" "\\;" stdout "${stdout}") +string(REPLACE "\n" "E;" stdout "${stdout}") + +set(collecting 0) +set(generators) +foreach(eline ${stdout}) + string(REGEX REPLACE "^(.*)E$" "\\1" line "${eline}") + if(collecting AND NOT line STREQUAL "") + if(line MATCHES "=") + string(REGEX REPLACE "^ (.+)= (.*)$" "\\1" gen "${line}") + if(gen MATCHES "[A-Za-z]") + string(REGEX REPLACE "^(.*[^ ]) +$" "\\1" gen "${gen}") + if(gen) + set(generators ${generators} ${gen}) + endif() + endif() + else() + if(line MATCHES "^ [A-Za-z0-9]") + string(REGEX REPLACE "^ (.+)$" "\\1" gen "${line}") + string(REGEX REPLACE "^(.*[^ ]) +$" "\\1" gen "${gen}") + if(gen) + set(generators ${generators} ${gen}) + endif() + endif() + endif() + endif() + if(line STREQUAL "The following generators are available on this platform:") + set(collecting 1) + endif() +endforeach() + +# Also call with one non-existent generator: +# +set(generators ${generators} "BOGUS_CMAKE_GENERATOR") + +# Call cmake with -G on each available generator. We do not care if this +# succeeds or not. We expect it *not* to succeed if the underlying packaging +# tools are not installed on the system... This test is here simply to add +# coverage for the various cmake generators, even/especially to test ones +# where the tools are not installed. +# +message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") + +message(STATUS "CMake generators='${generators}'") + +# First setup a source tree to run CMake on. +# +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast + ${dir}/Source +) + +foreach(g ${generators}) + message(STATUS "cmake -G \"${g}\" ..") + + # Create a binary directory for each generator: + # + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory + ${dir}/Source/${g} + ) + + # Run cmake: + # + execute_process(COMMAND ${CMAKE_COMMAND} -G ${g} .. + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}/Source/${g} + ) + + message(STATUS "result='${result}'") + message(STATUS "stdout='${stdout}'") + message(STATUS "stderr='${stderr}'") + message(STATUS "") +endforeach() + +message(STATUS "CMake generators='${generators}'") +message(STATUS "CMAKE_COMMAND='${CMAKE_COMMAND}'") diff --git a/Tests/CMakeTestBadCommandLines/RunCMake.cmake b/Tests/CMakeTestBadCommandLines/RunCMake.cmake new file mode 100644 index 0000000..08549cc --- /dev/null +++ b/Tests/CMakeTestBadCommandLines/RunCMake.cmake @@ -0,0 +1,79 @@ +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)") + +# First setup a source tree to run CMake on. +# +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast + ${dir}/Source +) + +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory + ${dir}/Build + ) + +function(RunCMakeWithArgs) + message(STATUS "info: running cmake with ARGN='${ARGN}'") + + execute_process(COMMAND ${CMAKE_COMMAND} ${ARGN} + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}/Build + ) + + message(STATUS "result='${result}'") + message(STATUS "stdout='${stdout}'") + message(STATUS "stderr='${stderr}'") + message(STATUS "") +endfunction() + +# Run cmake once with no errors to get a good build tree: +# +RunCMakeWithArgs(-G ${gen} ../Source) + +# Run cmake with args that produce some sort of problem to cover the error +# cases in cmake.cxx... +# +# (These are not good examples of cmake command lines. Do not copy and +# paste them elsewhere and expect them to work... See the cmake +# documentation or other real examples of usage instead.) +# +RunCMakeWithArgs() +RunCMakeWithArgs(-C) +RunCMakeWithArgs(-C nosuchcachefile.txt) +RunCMakeWithArgs(--check-stamp-file nostampfile) +RunCMakeWithArgs(--check-stamp-list nostamplist) +RunCMakeWithArgs(nosuchsubdir/CMakeCache.txt) +RunCMakeWithArgs(nosuchsubdir/CMakeLists.txt) +RunCMakeWithArgs(-D) +RunCMakeWithArgs(--debug-output .) +RunCMakeWithArgs(--debug-trycompile .) +RunCMakeWithArgs(-E) +RunCMakeWithArgs(-E create_symlink) +RunCMakeWithArgs(-E echo_append) +RunCMakeWithArgs(-E rename) +RunCMakeWithArgs(-E touch_nocreate) +RunCMakeWithArgs(-G) +RunCMakeWithArgs(--graphviz= ../Source) +RunCMakeWithArgs(--graphviz=g.dot .) +RunCMakeWithArgs(-P) +RunCMakeWithArgs(-P nosuchscriptfile.cmake) +RunCMakeWithArgs(--trace .) +RunCMakeWithArgs(-U) +RunCMakeWithArgs(-U nosuchvariable .) +RunCMakeWithArgs(-V) +RunCMakeWithArgs(-V .) +RunCMakeWithArgs(-Wno-dev .) +RunCMakeWithArgs(-Wdev .) diff --git a/Tests/CMakeTestMultipleConfigures/RunCMake.cmake b/Tests/CMakeTestMultipleConfigures/RunCMake.cmake new file mode 100644 index 0000000..19391d7 --- /dev/null +++ b/Tests/CMakeTestMultipleConfigures/RunCMake.cmake @@ -0,0 +1,165 @@ +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() + +# Call cmake once to get a baseline/reference output build tree: "Build". +# Then call cmake N more times, each time making a copy of the entire +# build tree after cmake is done configuring/generating. At the end, +# analyze the diffs in the generated build trees. Expect no diffs. +# +message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") + +set(N 7) + +# First setup source and binary trees: +# +execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory + ${dir}/Source +) + +execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory + ${dir}/Build +) + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMake_SOURCE_DIR}/Tests/CTestTest/SmallAndFast + ${dir}/Source +) + +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory + ${dir}/Build +) + +# Patch SmallAndFast to build a .cxx executable too: +# +execute_process(COMMAND ${CMAKE_COMMAND} -E copy + ${dir}/Source/echoargs.c + ${dir}/Source/echoargs.cxx +) +file(APPEND "${dir}/Source/CMakeLists.txt" "\nadd_executable(echoargsCXX echoargs.cxx)\n") + +# Loop N times, saving a copy of the configured/generated build tree each time: +# +foreach(i RANGE 1 ${N}) + # Equivalent sequence of shell commands: + # + message(STATUS "${i}: cd Build && cmake -G \"${gen}\" ../Source && cd .. && cp -r Build b${i}") + + # Run cmake: + # + execute_process(COMMAND ${CMAKE_COMMAND} -G ${gen} ../Source + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}/Build + ) + + message(STATUS "result='${result}'") + message(STATUS "stdout='${stdout}'") + message(STATUS "stderr='${stderr}'") + message(STATUS "") + + # Save this iteration of the Build directory: + # + execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory + ${dir}/b${i} + ) + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory + ${dir}/Build + ${dir}/b${i} + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + ) + + message(STATUS "result='${result}'") + message(STATUS "stdout='${stdout}'") + message(STATUS "stderr='${stderr}'") + message(STATUS "") +endforeach() + + +# Function to analyze diffs between two directories. +# Set DIFF_EXECUTABLE before calling if 'diff' is available. +# +function(analyze_directory_diffs d1 d2 diff_count_var) + set(diffs 0) + + message(STATUS "Analyzing directory diffs between:") + message(STATUS " d1='${d1}'") + message(STATUS " d2='${d2}'") + + if(NOT "${d1}" STREQUAL "" AND NOT "${d2}" STREQUAL "") + message(STATUS "info: analyzing directories") + + file(GLOB_RECURSE files1 RELATIVE "${d1}" "${d1}/*") + file(GLOB_RECURSE files2 RELATIVE "${d2}" "${d2}/*") + + if("${files1}" STREQUAL "${files2}") + message(STATUS "info: file lists the same") + #message(STATUS " files='${files1}'") + + foreach(f ${files1}) + execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files + ${d1}/${f} + ${d2}/${f} + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + ) + if(result STREQUAL 0) + #message(STATUS "info: file '${f}' the same") + else() + math(EXPR diffs "${diffs} + 1") + message(STATUS "warning: file '${f}' differs from d1 to d2") + file(READ "${d1}/${f}" f1contents) + message(STATUS "contents of file '${d1}/${f}' +[===[${f1contents}]===]") + file(READ "${d2}/${f}" f2contents) + message(STATUS "contents of file '${d2}/${f}' +[===[${f2contents}]===]") + if(DIFF_EXECUTABLE) + message(STATUS "diff of files '${d1}/${f}' '${d2}/${f}'") + message(STATUS "[====[") + execute_process(COMMAND ${DIFF_EXECUTABLE} "${d1}/${f}" "${d2}/${f}") + message(STATUS "]====]") + endif() + endif() + endforeach() + else() + math(EXPR diffs "${diffs} + 1") + message(STATUS "warning: file *lists* differ - some files exist in d1/not-d2 or not-d1/d2...") + message(STATUS " files1='${files1}'") + message(STATUS " files2='${files2}'") + endif() + endif() + + set(${diff_count_var} ${diffs} PARENT_SCOPE) +endfunction(analyze_directory_diffs) + + +# Analyze diffs between b1:b2, b2:b3, b3:b4, b4:b5 ... bN-1:bN. +# Expect no diffs. +# +find_program(DIFF_EXECUTABLE diff) +set(total_diffs 0) + +foreach(i RANGE 2 ${N}) + math(EXPR prev "${i} - 1") + set(count 0) + analyze_directory_diffs(${dir}/b${prev} ${dir}/b${i} count) + message(STATUS "diff count='${count}'") + message(STATUS "") + math(EXPR total_diffs "${total_diffs} + ${count}") +endforeach() + +message(STATUS "CMAKE_COMMAND='${CMAKE_COMMAND}'") +message(STATUS "total_diffs='${total_diffs}'") diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt index 456e2e9..adaf247 100644 --- a/Tests/CMakeTests/CMakeLists.txt +++ b/Tests/CMakeTests/CMakeLists.txt @@ -22,10 +22,15 @@ AddCMakeTest(ConfigureFile "") AddCMakeTest(SeparateArguments "") AddCMakeTest(ImplicitLinkInfo "") AddCMakeTest(ModuleNotices "") +AddCMakeTest(If "") AddCMakeTest(String "") AddCMakeTest(Math "") AddCMakeTest(CMakeMinimumRequired "") +if(HAVE_ELF_H) + AddCMakeTest(ELF "") +endif() + SET(EndStuff_PreArgs "-Ddir:STRING=${CMAKE_CURRENT_BINARY_DIR}/EndStuffTest" ) diff --git a/Tests/CMakeTests/ELF/elf32lsb.bin b/Tests/CMakeTests/ELF/elf32lsb.bin Binary files differnew file mode 100644 index 0000000..803ac43 --- /dev/null +++ b/Tests/CMakeTests/ELF/elf32lsb.bin diff --git a/Tests/CMakeTests/ELF/elf32msb.bin b/Tests/CMakeTests/ELF/elf32msb.bin Binary files differnew file mode 100644 index 0000000..d04aaf7 --- /dev/null +++ b/Tests/CMakeTests/ELF/elf32msb.bin diff --git a/Tests/CMakeTests/ELF/elf64lsb.bin b/Tests/CMakeTests/ELF/elf64lsb.bin Binary files differnew file mode 100644 index 0000000..a21e3ea --- /dev/null +++ b/Tests/CMakeTests/ELF/elf64lsb.bin diff --git a/Tests/CMakeTests/ELF/elf64msb.bin b/Tests/CMakeTests/ELF/elf64msb.bin Binary files differnew file mode 100644 index 0000000..bbe2551 --- /dev/null +++ b/Tests/CMakeTests/ELF/elf64msb.bin diff --git a/Tests/CMakeTests/ELFTest.cmake.in b/Tests/CMakeTests/ELFTest.cmake.in new file mode 100644 index 0000000..0271abb --- /dev/null +++ b/Tests/CMakeTests/ELFTest.cmake.in @@ -0,0 +1,48 @@ +set(names + elf32lsb.bin + elf32msb.bin + elf64lsb.bin + elf64msb.bin + ) + +# Prepare binaries on which to operate. +set(in "@CMAKE_CURRENT_SOURCE_DIR@/ELF") +set(out "@CMAKE_CURRENT_BINARY_DIR@/ELF-Out") +file(REMOVE_RECURSE "${out}") +file(MAKE_DIRECTORY "${out}") +foreach(f ${names}) + file(COPY ${in}/${f} DESTINATION ${out}) + list(APPEND files "${out}/${f}") +endforeach() + +foreach(f ${files}) + # Check for the initial RPATH. + file(RPATH_CHECK FILE "${f}" RPATH "/sample/rpath") + if(NOT EXISTS "${f}") + message(FATAL_ERROR "RPATH_CHECK removed ${f}") + endif() + + # Change the RPATH. + file(RPATH_CHANGE FILE "${f}" + OLD_RPATH "/sample/rpath" + NEW_RPATH "/rpath/sample") + set(rpath) + file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1) + if(NOT rpath) + message(FATAL_ERROR "RPATH not changed in ${f}") + endif() + + # Remove the RPATH. + file(RPATH_REMOVE FILE "${f}") + set(rpath) + file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1) + if(rpath) + message(FATAL_ERROR "RPATH not removed from ${f}") + endif() + + # Check again...this should remove the file. + file(RPATH_CHECK FILE "${f}" RPATH "/sample/rpath") + if(EXISTS "${f}") + message(FATAL_ERROR "RPATH_CHECK did not remove ${f}") + endif() +endforeach() diff --git a/Tests/CMakeTests/FileTest.cmake.in b/Tests/CMakeTests/FileTest.cmake.in index b19ad0a..721f311 100644 --- a/Tests/CMakeTests/FileTest.cmake.in +++ b/Tests/CMakeTests/FileTest.cmake.in @@ -23,3 +23,22 @@ check_cmake_test(File Copy-NoDest Copy-NoFile ) + +# Also execute each test listed in FileTestScript.cmake: +# +set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/FileTestScript.cmake") +set(number_of_tests_expected 56) + +include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake") +execute_all_script_tests(${scriptname} number_of_tests_executed) + +# And verify that number_of_tests_executed is at least as many as we know +# about as of this writing... +# +message(STATUS "scriptname='${scriptname}'") +message(STATUS "number_of_tests_executed='${number_of_tests_executed}'") +message(STATUS "number_of_tests_expected='${number_of_tests_expected}'") + +if(number_of_tests_executed LESS number_of_tests_expected) + message(FATAL_ERROR "error: some test cases were skipped") +endif() diff --git a/Tests/CMakeTests/FileTestScript.cmake b/Tests/CMakeTests/FileTestScript.cmake new file mode 100644 index 0000000..c4e27bd --- /dev/null +++ b/Tests/CMakeTests/FileTestScript.cmake @@ -0,0 +1,207 @@ +message(STATUS "testname='${testname}'") + +if(testname STREQUAL empty) # fail + file() + +elseif(testname STREQUAL bogus) # fail + file(BOGUS ffff) + +elseif(testname STREQUAL different_not_enough_args) # fail + file(DIFFERENT ffff) + +elseif(testname STREQUAL download_not_enough_args) # fail + file(DOWNLOAD ffff) + +elseif(testname STREQUAL read_not_enough_args) # fail + file(READ ffff) + +elseif(testname STREQUAL rpath_check_not_enough_args) # fail + file(RPATH_CHECK ffff) + +elseif(testname STREQUAL rpath_remove_not_enough_args) # fail + file(RPATH_REMOVE ffff) + +elseif(testname STREQUAL strings_not_enough_args) # fail + file(STRINGS ffff) + +elseif(testname STREQUAL to_native_path_not_enough_args) # fail + file(TO_NATIVE_PATH ffff) + +elseif(testname STREQUAL read_with_offset) # pass + file(READ ${CMAKE_CURRENT_LIST_FILE} v OFFSET 42 LIMIT 30) + message("v='${v}'") + +elseif(testname STREQUAL strings_bad_length_minimum) # fail + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LENGTH_MINIMUM bogus) + +elseif(testname STREQUAL strings_bad_length_maximum) # fail + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LENGTH_MAXIMUM bogus) + +elseif(testname STREQUAL strings_bad_limit_count) # fail + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_COUNT bogus) + +elseif(testname STREQUAL strings_bad_limit_input) # fail + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_INPUT bogus) + +elseif(testname STREQUAL strings_bad_limit_output) # fail + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_OUTPUT bogus) + +elseif(testname STREQUAL strings_bad_regex) # fail + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v REGEX "(") + +elseif(testname STREQUAL strings_unknown_arg) # fail + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v BOGUS) + +elseif(testname STREQUAL strings_bad_filename) # fail + file(STRINGS ffff v LIMIT_COUNT 10) + +elseif(testname STREQUAL strings_use_limit_count) # pass + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v LIMIT_COUNT 10) + message("v='${v}'") + +elseif(testname STREQUAL strings_use_no_hex_conversion) # pass + file(STRINGS ${CMAKE_CURRENT_LIST_FILE} v NO_HEX_CONVERSION) + message("v='${v}'") + +elseif(testname STREQUAL glob_recurse_follow_symlinks_no_expression) # fail + file(GLOB_RECURSE v FOLLOW_SYMLINKS) + +elseif(testname STREQUAL glob_recurse_relative_no_directory) # fail + file(GLOB_RECURSE v RELATIVE) + +elseif(testname STREQUAL glob_recurse_relative_no_expression) # fail + file(GLOB_RECURSE v RELATIVE dddd) + +elseif(testname STREQUAL glob_non_full_path) # pass + file(GLOB_RECURSE v ffff*.*) + message("v='${v}'") + +elseif(testname STREQUAL make_directory_non_full_path) # pass + file(MAKE_DIRECTORY FileTestScriptDDDD) + if(NOT EXISTS FileTestScriptDDDD) + message(FATAL_ERROR "error: non-full-path MAKE_DIRECTORY failed") + endif() + file(REMOVE_RECURSE FileTestScriptDDDD) + if(EXISTS FileTestScriptDDDD) + message(FATAL_ERROR "error: non-full-path REMOVE_RECURSE failed") + endif() + +elseif(testname STREQUAL different_no_variable) # fail + file(DIFFERENT FILES) + +elseif(testname STREQUAL different_no_files) # fail + file(DIFFERENT v FILES) + +elseif(testname STREQUAL different_unknown_arg) # fail + file(DIFFERENT v FILES ffffLHS ffffRHS BOGUS) + +elseif(testname STREQUAL different_different) # pass + file(DIFFERENT v FILES ffffLHS ffffRHS) + message("v='${v}'") + +elseif(testname STREQUAL different_same) # pass + file(DIFFERENT v FILES + ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_FILE}) + message("v='${v}'") + +elseif(testname STREQUAL rpath_change_unknown_arg) # fail + file(RPATH_CHANGE BOGUS) + +elseif(testname STREQUAL rpath_change_bad_file) # fail + file(RPATH_CHANGE FILE) + +elseif(testname STREQUAL rpath_change_bad_old_rpath) # fail + file(RPATH_CHANGE FILE ffff OLD_RPATH) + +elseif(testname STREQUAL rpath_change_bad_new_rpath) # fail + file(RPATH_CHANGE FILE ffff OLD_RPATH rrrr NEW_RPATH) + +elseif(testname STREQUAL rpath_change_file_does_not_exist) # fail + file(RPATH_CHANGE FILE ffff OLD_RPATH rrrr NEW_RPATH RRRR) + +elseif(testname STREQUAL rpath_change_file_is_not_executable) # fail + file(RPATH_CHANGE FILE ${CMAKE_CURRENT_LIST_FILE} + OLD_RPATH rrrr NEW_RPATH RRRR) + +elseif(testname STREQUAL rpath_remove_unknown_arg) # fail + file(RPATH_REMOVE BOGUS) + +elseif(testname STREQUAL rpath_remove_bad_file) # fail + file(RPATH_REMOVE FILE) + +elseif(testname STREQUAL rpath_remove_file_does_not_exist) # fail + file(RPATH_REMOVE FILE ffff) + +#elseif(testname STREQUAL rpath_remove_file_is_not_executable) # fail +# file(RPATH_REMOVE FILE ${CMAKE_CURRENT_LIST_FILE}) + +elseif(testname STREQUAL rpath_check_unknown_arg) # fail + file(RPATH_CHECK BOGUS) + +elseif(testname STREQUAL rpath_check_bad_file) # fail + file(RPATH_CHECK FILE) + +elseif(testname STREQUAL rpath_check_bad_rpath) # fail + file(RPATH_CHECK FILE ffff RPATH) + +elseif(testname STREQUAL rpath_check_file_does_not_exist) # pass + file(RPATH_CHECK FILE ffff RPATH rrrr) + +elseif(testname STREQUAL rpath_check_file_is_not_executable) # pass + file(WRITE ffff_rpath_check "") + + if(NOT EXISTS ffff_rpath_check) + message(FATAL_ERROR "error: non-full-path WRITE failed") + endif() + + file(RPATH_CHECK FILE ffff_rpath_check RPATH rrrr) + # careful: if the file does not have the given RPATH, it is deleted... + + if(EXISTS ffff_rpath_check) + message(FATAL_ERROR "error: non-full-path RPATH_CHECK failed") + endif() + +elseif(testname STREQUAL relative_path_wrong_number_of_args) # fail + file(RELATIVE_PATH v dir) + +elseif(testname STREQUAL relative_path_non_full_path_dir) # fail + file(RELATIVE_PATH v dir file) + +elseif(testname STREQUAL relative_path_non_full_path_file) # fail + file(RELATIVE_PATH v /dir file) + +elseif(testname STREQUAL rename_wrong_number_of_args) # fail + file(RENAME ffff) + +elseif(testname STREQUAL rename_input_file_does_not_exist) # fail + file(RENAME ffff FFFFGGGG) + +elseif(testname STREQUAL to_native_path) # pass + file(TO_NATIVE_PATH /a/b/c\;/d/e/f:/g/h/i v) + message("v='${v}'") + +elseif(testname STREQUAL download_wrong_number_of_args) # fail + file(DOWNLOAD zzzz://bogus/ffff) + +elseif(testname STREQUAL download_file_with_no_path) # fail + file(DOWNLOAD zzzz://bogus/ffff ffff) + +elseif(testname STREQUAL download_missing_time) # fail + file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT) + +elseif(testname STREQUAL download_missing_log_var) # fail + file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT 2 LOG) + +elseif(testname STREQUAL download_missing_status_var) # fail + file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT 2 LOG l STATUS) + +elseif(testname STREQUAL download_with_bogus_protocol) # pass + file(DOWNLOAD zzzz://bogus/ffff ./ffff TIMEOUT 2 LOG l STATUS s) + file(REMOVE ./ffff) + message("l='${l}'") + message("s='${s}'") + +else() # fail + message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'") + +endif() diff --git a/Tests/CMakeTests/IfTest.cmake.in b/Tests/CMakeTests/IfTest.cmake.in new file mode 100644 index 0000000..e5211b4 --- /dev/null +++ b/Tests/CMakeTests/IfTest.cmake.in @@ -0,0 +1,158 @@ +# Prepare variable definitions. +set(VAR_UNDEFINED) +set(VAR_PATH /some/path/to/a/file.txt) +set(FALSE_NAMES OFF NO FALSE N FOO-NOTFOUND IGNORE Off No False Ignore off n no false ignore) +set(TRUE_NAMES ON YES TRUE Y On Yes True on yes true y) +foreach(_arg "" 0 1 2 ${TRUE_NAMES} ${FALSE_NAMES}) + set(VAR_${_arg} "${_arg}") +endforeach() + +macro(test_vars _old) + # Variables set to false or not set. + foreach(_var "" 0 ${FALSE_NAMES} UNDEFINED) + if(VAR_${_var}) + message(FATAL_ERROR "${_old}if(VAR_${_var}) is true!") + else() + message(STATUS "${_old}if(VAR_${_var}) is false") + endif() + + if(NOT VAR_${_var}) + message(STATUS "${_old}if(NOT VAR_${_var}) is true") + else() + message(FATAL_ERROR "${_old}if(NOT VAR_${_var}) is false!") + endif() + endforeach() + + # Variables set to true. + foreach(_var 1 2 ${TRUE_NAMES} PATH) + if(VAR_${_var}) + message(STATUS "${_old}if(VAR_${_var}) is true") + else() + message(FATAL_ERROR "${_old}if(VAR_${_var}) is false!") + endif() + + if(NOT VAR_${_var}) + message(FATAL_ERROR "${_old}if(NOT VAR_${_var}) is true!") + else() + message(STATUS "${_old}if(NOT VAR_${_var}) is false") + endif() + endforeach() +endmacro() + +#----------------------------------------------------------------------------- +# Test the OLD behavior of CMP0012. +cmake_policy(SET CMP0012 OLD) + +# False constants not recognized (still false). +foreach(_false "" ${FALSE_NAMES}) + if("${_false}") + message(FATAL_ERROR "OLD if(${_false}) is true!") + else() + message(STATUS "OLD if(${_false}) is false") + endif() + + if(NOT "${_false}") + message(STATUS "OLD if(NOT ${_false}) is true") + else() + message(FATAL_ERROR "OLD if(NOT ${_false}) is false!") + endif() +endforeach() + +# True constants not recognized. +foreach(_false ${TRUE_NAMES}) + if(${_false}) + message(FATAL_ERROR "OLD if(${_false}) is true!") + else() + message(STATUS "OLD if(${_false}) is false") + endif() + + if(NOT ${_false}) + message(STATUS "OLD if(NOT ${_false}) is true") + else() + message(FATAL_ERROR "OLD if(NOT ${_false}) is false!") + endif() +endforeach() + +# Numbers not recognized properly. +foreach(_num 2 -2 2.0 -2.0 2x -2x) + if(${_num}) + message(FATAL_ERROR "OLD if(${_num}) is true!") + else() + message(STATUS "OLD if(${_num}) is false") + endif() + + if(NOT ${_num}) + message(FATAL_ERROR "OLD if(NOT ${_num}) is true!") + else() + message(STATUS "OLD if(NOT ${_num}) is false") + endif() +endforeach() + +test_vars("OLD ") + +#----------------------------------------------------------------------------- + +# Test the NEW behavior of CMP0012. +cmake_policy(SET CMP0012 NEW) + +# Test false constants. +foreach(_false "" 0 ${FALSE_NAMES}) + if("${_false}") + message(FATAL_ERROR "if(${_false}) is true!") + else() + message(STATUS "if(${_false}) is false") + endif() + + if(NOT "${_false}") + message(STATUS "if(NOT ${_false}) is true") + else() + message(FATAL_ERROR "if(NOT ${_false}) is false!") + endif() +endforeach() + +# Test true constants. +foreach(_true 1 ${TRUE_NAMES}) + if(${_true}) + message(STATUS "if(${_true}) is true") + else() + message(FATAL_ERROR "if(${_true}) is false!") + endif() + + if(NOT ${_true}) + message(FATAL_ERROR "if(NOT ${_true}) is true!") + else() + message(STATUS "if(NOT ${_true}) is false") + endif() +endforeach() + +# Numbers recognized properly. +foreach(_num 2 -2 2.0 -2.0) + if(${_num}) + message(STATUS "if(${_num}) is true") + else() + message(FATAL_ERROR "if(${_num}) is false!") + endif() + + if(NOT ${_num}) + message(FATAL_ERROR "if(NOT ${_num}) is true!") + else() + message(STATUS "if(NOT ${_num}) is false") + endif() +endforeach() + +# Bad numbers not recognized. +foreach(_bad 2x -2x) + if(${_bad}) + message(FATAL_ERROR "if(${_bad}) is true!") + else() + message(STATUS "if(${_bad}) is false") + endif() + + if(NOT ${_bad}) + message(STATUS "if(NOT ${_bad}) is true") + else() + message(FATAL_ERROR "if(NOT ${_bad}) is false!") + endif() +endforeach() + +test_vars("") diff --git a/Tests/CPackTestAllGenerators/CMakeLists.txt b/Tests/CPackTestAllGenerators/CMakeLists.txt new file mode 100644 index 0000000..5eeb7e9 --- /dev/null +++ b/Tests/CPackTestAllGenerators/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8) +project(CPackTestAllGenerators) +add_subdirectory(../CTestTest/SmallAndFast SmallAndFast) +install(FILES RunCPack.cmake DESTINATION .) +include(CPack) diff --git a/Tests/CPackTestAllGenerators/RunCPack.cmake b/Tests/CPackTestAllGenerators/RunCPack.cmake new file mode 100644 index 0000000..e0c241e --- /dev/null +++ b/Tests/CPackTestAllGenerators/RunCPack.cmake @@ -0,0 +1,55 @@ +if(NOT DEFINED cpack) + message(FATAL_ERROR "cpack not defined") +endif() + +if(NOT DEFINED dir) + message(FATAL_ERROR "dir not defined") +endif() + +# Analyze 'cpack --help' output for list of available generators: +# +execute_process(COMMAND ${cpack} --help + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}) + +string(REPLACE ";" "\\;" stdout "${stdout}") +string(REPLACE "\n" "E;" stdout "${stdout}") + +set(collecting 0) +set(generators) +foreach(eline ${stdout}) + string(REGEX REPLACE "^(.*)E$" "\\1" line "${eline}") + if(collecting AND NOT line STREQUAL "") + string(REGEX REPLACE "^ ([^ ]+) += (.*)$" "\\1" gen "${line}") + string(REGEX REPLACE "^ ([^ ]+) += (.*)$" "\\2" doc "${line}") + set(generators ${generators} ${gen}) + endif() + if(line STREQUAL "Generators") + set(collecting 1) + endif() +endforeach() + +# Call cpack with -G on each available generator. We do not care if this +# succeeds or not. We expect it *not* to succeed if the underlying packaging +# tools are not installed on the system... This test is here simply to add +# coverage for the various cpack generators, even/especially to test ones +# where the tools are not installed. +# +message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") + +message(STATUS "CPack generators='${generators}'") + +foreach(g ${generators}) + message(STATUS "Calling cpack -G ${g}...") + execute_process(COMMAND ${cpack} -G ${g} + RESULT_VARIABLE result + OUTPUT_VARIABLE stdout + ERROR_VARIABLE stderr + WORKING_DIRECTORY ${dir}) + message(STATUS "result='${result}'") + message(STATUS "stdout='${stdout}'") + message(STATUS "stderr='${stderr}'") + message(STATUS "") +endforeach() diff --git a/Tests/CTestTest/SmallAndFast/CMakeLists.txt b/Tests/CTestTest/SmallAndFast/CMakeLists.txt index 51aa887..85cb30c 100644 --- a/Tests/CTestTest/SmallAndFast/CMakeLists.txt +++ b/Tests/CTestTest/SmallAndFast/CMakeLists.txt @@ -4,7 +4,22 @@ project(SmallAndFast) include(CTest) add_executable(echoargs echoargs.c) +set_property(SOURCE echoargs.c APPEND PROPERTY LABELS SourceLabel Everything) +set_property(TARGET echoargs APPEND PROPERTY LABELS TargetLabel Everything) add_test(test0 echoargs) +set_property(TEST test0 APPEND PROPERTY LABELS TestLabel 0ArgTest Everything) + add_test(test1 echoargs 1) +set_property(TEST test1 APPEND PROPERTY LABELS TestLabel 1ArgTest Everything) + add_test(test2 echoargs 1 2) +set_property(TEST test2 APPEND PROPERTY LABELS TestLabel 2ArgTest Everything) + +if(SAF_INTENTIONAL_COMPILE_ERROR) + add_executable(ice intentional_compile_error.cxx) +endif() + +if(SAF_INTENTIONAL_COMPILE_WARNING) + add_executable(icw intentional_compile_warning.cxx) +endif() diff --git a/Tests/CTestTest/SmallAndFast/intentional_compile_error.cxx b/Tests/CTestTest/SmallAndFast/intentional_compile_error.cxx new file mode 100644 index 0000000..a8930cf --- /dev/null +++ b/Tests/CTestTest/SmallAndFast/intentional_compile_error.cxx @@ -0,0 +1 @@ +garbage - obviously this should not compile as is diff --git a/Tests/CTestTest/SmallAndFast/intentional_compile_warning.cxx b/Tests/CTestTest/SmallAndFast/intentional_compile_warning.cxx new file mode 100644 index 0000000..8ea5e40 --- /dev/null +++ b/Tests/CTestTest/SmallAndFast/intentional_compile_warning.cxx @@ -0,0 +1,11 @@ +#include <stdio.h> + +int main(int argc, const char* argv[]) +{ + unsigned int i = 0; // "i<argc" should produce a "signed/unsigned comparison" warning + for (; i<argc; ++i) + { + fprintf(stdout, "%s\n", argv[i]); + } + return 0; +} diff --git a/Tests/CTestTestFailedSubmits/test.cmake.in b/Tests/CTestTestFailedSubmits/test.cmake.in new file mode 100644 index 0000000..42bc79c --- /dev/null +++ b/Tests/CTestTestFailedSubmits/test.cmake.in @@ -0,0 +1,47 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +# CTestConfig.cmake settings: +set(CTEST_PROJECT_NAME "SmallAndFast") + +# Intentionally leave out other upload-related CTestConfig.cmake settings +# so that the ctest_submit call below fails with an error message... +# +set(CTEST_DROP_METHOD "@drop_method@") + +# Settings: +SET(CTEST_USE_LAUNCHERS 1) + +# Emit these compiler warnings: +set(ENV{CXXFLAGS} "$ENV{CXXFLAGS} -Wall") + +SET(CTEST_SITE "@SITE@") +SET(CTEST_BUILD_NAME "CTestTestLaunchers-@drop_method@") + +SET(CTEST_SOURCE_DIRECTORY "@source@") +SET(CTEST_BINARY_DIRECTORY "@build@") +SET(CTEST_CVS_COMMAND "@CVSCOMMAND@") +SET(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@") +SET(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}") +SET(CTEST_MEMORYCHECK_COMMAND "@MEMORYCHECK_COMMAND@") +SET(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "@MEMORYCHECK_SUPPRESSIONS_FILE@") +SET(CTEST_MEMORYCHECK_COMMAND_OPTIONS "@MEMORYCHECK_COMMAND_OPTIONS@") +SET(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@") +SET(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}") + +CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY}) + +CTEST_START(Experimental) + +# explicitly do not use CTEST_UPDATE - avoid network activity + +CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" + OPTIONS "-DCTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS};-DSAF_INTENTIONAL_COMPILE_ERROR:BOOL=ON;-DSAF_INTENTIONAL_COMPILE_WARNING:BOOL=ON" + RETURN_VALUE res) +CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) +CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) +CTEST_MEMCHECK(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) +CTEST_COVERAGE(BUILD "${CTEST_BINARY_DIRECTORY}" @ctest_coverage_labels_args@ RETURN_VALUE res) + +# ok to call ctest_submit - still avoids network activity because there is +# not a valid drop location given above... +CTEST_SUBMIT(RETURN_VALUE res) diff --git a/Tests/CTestTestRunScript/hello.cmake b/Tests/CTestTestRunScript/hello.cmake new file mode 100644 index 0000000..e2c652c --- /dev/null +++ b/Tests/CTestTestRunScript/hello.cmake @@ -0,0 +1,6 @@ +GET_FILENAME_COMPONENT(CTEST_COMMAND "${CMAKE_COMMAND}" PATH) +SET(CTEST_COMMAND "${CTEST_COMMAND}/ctest") +SET(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestRunScript") +SET(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestRunScript") + +message("hello world") diff --git a/Tests/CTestTestRunScript/test.cmake b/Tests/CTestTestRunScript/test.cmake new file mode 100644 index 0000000..4afcdd9 --- /dev/null +++ b/Tests/CTestTestRunScript/test.cmake @@ -0,0 +1,7 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.1) +GET_FILENAME_COMPONENT(CTEST_COMMAND "${CMAKE_COMMAND}" PATH) +SET(CTEST_COMMAND "${CTEST_COMMAND}/ctest") +SET(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestRunScript") +SET(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestRunScript") + +CTEST_RUN_SCRIPT("${CTEST_BINARY_DIRECTORY}/hello.cmake") diff --git a/Tests/CTestTestSubdir/CMakeLists.txt b/Tests/CTestTestSubdir/CMakeLists.txt new file mode 100644 index 0000000..f5a1fe2 --- /dev/null +++ b/Tests/CTestTestSubdir/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required (VERSION 2.6) +PROJECT(CTestTestSubdir) + +SET(DART_ROOT "" CACHE STRING "" FORCE) +ENABLE_TESTING() +INCLUDE (${CMAKE_ROOT}/Modules/Dart.cmake) + +GET_FILENAME_COMPONENT(CTEST_COMMAND "${CMAKE_COMMAND}" PATH) +SET(CTEST_COMMAND "${CTEST_COMMAND}/ctest") + +ADD_SUBDIRECTORY(subdir) diff --git a/Tests/CTestTestSubdir/CTestConfig.cmake b/Tests/CTestTestSubdir/CTestConfig.cmake new file mode 100644 index 0000000..4b848aa --- /dev/null +++ b/Tests/CTestTestSubdir/CTestConfig.cmake @@ -0,0 +1,7 @@ +set(CTEST_PROJECT_NAME "CTestTestSubdir") +set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT") +set(CTEST_DART_SERVER_VERSION "2") +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "www.cdash.org") +set(CTEST_DROP_LOCATION "/CDash/submit.php?project=PublicDashboard") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/Tests/CTestTestSubdir/subdir/CMakeLists.txt b/Tests/CTestTestSubdir/subdir/CMakeLists.txt new file mode 100644 index 0000000..a92e13b --- /dev/null +++ b/Tests/CTestTestSubdir/subdir/CMakeLists.txt @@ -0,0 +1,2 @@ +ADD_EXECUTABLE (main main.c) +ADD_TEST (TestMain main) diff --git a/Tests/CTestTestSubdir/subdir/main.c b/Tests/CTestTestSubdir/subdir/main.c new file mode 100644 index 0000000..8488f4e --- /dev/null +++ b/Tests/CTestTestSubdir/subdir/main.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} diff --git a/Tests/CTestTestSubdir/test.cmake.in b/Tests/CTestTestSubdir/test.cmake.in new file mode 100644 index 0000000..299f86d --- /dev/null +++ b/Tests/CTestTestSubdir/test.cmake.in @@ -0,0 +1,32 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.1) + +# Settings: +SET(CTEST_DASHBOARD_ROOT "@CMake_BINARY_DIR@/Tests/CTestTest") +SET(CTEST_SITE "@SITE@") +SET(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Subdir") + +SET(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestSubdir") +SET(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestSubdir") +SET(CTEST_CVS_COMMAND "@CVSCOMMAND@") +SET(CMAKE_TEST_MAKEPROGRAM "@CMAKE_TEST_MAKEPROGRAM@") +SET(MAKECOMMAND "@MAKECOMMAND@") +SET(CTEST_CMAKE_GENERATOR "@CMAKE_TEST_GENERATOR@") +SET(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}") +SET(CTEST_MEMORYCHECK_COMMAND "@MEMORYCHECK_COMMAND@") +SET(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE "@MEMORYCHECK_SUPPRESSIONS_FILE@") +SET(CTEST_MEMORYCHECK_COMMAND_OPTIONS "@MEMORYCHECK_COMMAND_OPTIONS@") +SET(CTEST_COVERAGE_COMMAND "@COVERAGE_COMMAND@") +SET(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}") + +#CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY}) + +FILE(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" " +CMAKE_TEST_GENERATOR:STRING=@CMAKE_TEST_GENERATOR@ +CMAKE_TEST_MAKEPROGRAM:FILEPATH=@CMAKE_TEST_MAKEPROGRAM@ +MAKECOMMAND:STRING=@MAKECOMMAND@ +") + +CTEST_START(Experimental) +CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) +CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) +CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt index adcadd4..709ea5f 100644 --- a/Tests/Fortran/CMakeLists.txt +++ b/Tests/Fortran/CMakeLists.txt @@ -7,8 +7,25 @@ message("CMAKE_Fortran_COMPILER_INIT = ${CMAKE_Fortran_COMPILER_INIT}") message("CMAKE_Fortran_COMPILER_FULLPATH = ${CMAKE_Fortran_COMPILER_FULLPATH}") message("CMAKE_Fortran_COMPILER = ${CMAKE_Fortran_COMPILER}") message("CMAKE_Fortran_FLAGS = ${CMAKE_Fortran_FLAGS}") -add_executable(testf hello.f) +set(_SHARED SHARED) +if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "^(XL|VisualAge)$") + # We do not implement SHARED Fortran libs on AIX yet! + # Workaround: Set LINKER_LANGUAGE to C, which uses 'xlc' and Fortran implicits. + set(_SHARED STATIC) +elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU") + # g77 2.96 does not support shared libs on Itanium because g2c is not -fPIC + execute_process(COMMAND ${CMAKE_Fortran_COMPILER} --version + OUTPUT_VARIABLE output ERROR_VARIABLE output) + if("${output}" MATCHES "Red Hat .* 2\\.96") + set(_SHARED STATIC) + endif() +endif() + +add_library(hello STATIC hello.f) +add_library(world ${_SHARED} world.f world.def) +add_executable(testf testf.f) +target_link_libraries(testf hello world) function(test_fortran_c_interface_module) message(STATUS "Testing FortranCInterface module") diff --git a/Tests/Fortran/hello.f b/Tests/Fortran/hello.f index c9ee3c2..aa0de77 100644 --- a/Tests/Fortran/hello.f +++ b/Tests/Fortran/hello.f @@ -1,6 +1,6 @@ - PROGRAM GREETINGS + SUBROUTINE HELLO - PRINT *, 'Real programmers write Fortran!' + PRINT *, 'Hello' END diff --git a/Tests/Fortran/testf.f b/Tests/Fortran/testf.f new file mode 100644 index 0000000..abf6c6d --- /dev/null +++ b/Tests/Fortran/testf.f @@ -0,0 +1,7 @@ + PROGRAM TESTF + + CALL HELLO() + CALL WORLD() + + END + diff --git a/Tests/Fortran/world.def b/Tests/Fortran/world.def new file mode 100644 index 0000000..ead7710 --- /dev/null +++ b/Tests/Fortran/world.def @@ -0,0 +1,2 @@ +EXPORTS + WORLD diff --git a/Tests/Fortran/world.f b/Tests/Fortran/world.f new file mode 100644 index 0000000..0487dff --- /dev/null +++ b/Tests/Fortran/world.f @@ -0,0 +1,6 @@ + SUBROUTINE WORLD + + PRINT *, 'World!' + + END + diff --git a/Tests/KDE4StableBranchTest/test_kde4.sh.in b/Tests/KDE4StableBranchTest/test_kde4.sh.in new file mode 100755 index 0000000..81badcd --- /dev/null +++ b/Tests/KDE4StableBranchTest/test_kde4.sh.in @@ -0,0 +1,62 @@ +#!/bin/sh + +# This shell script tests whether cmake is able to build the latest +# stable KDE4 release, or at least some part of it. +# It downloads automoc from KDE svn, builds and installs it, then it +# downloads phonon from KDE svn, builds and installs it, and finally +# it downloads kdelibs (currently from the 4.3 branch), and builds +# a (small) part of it, i.e. libkdecore and one unit test depending on it. +# +# <neundorf AT kde.org> + +CMAKE="@CMAKE_CMAKE_COMMAND@" +BASEDIR="@TEST_KDE4_BASE_DIR@" +INSTALLDIR="$BASEDIR/install" +QMAKE="@QT_QMAKE_EXECUTABLE@" + +cd "$BASEDIR" || exit -1 +echo "Removing old install dir " $INSTALLDIR + +rm -rf install || exit -1 +rm -rf build-automoc || exit -1 +rm -rf build-phonon || exit -1 +rm -rf build-kdelibs || exit -1 + + + +# build and install automoc +cd "$BASEDIR" || exit -1 +svn co svn://anonsvn.kde.org/home/kde/tags/kdesupport-for-4.3/kdesupport/automoc || exit -1 + +mkdir -p build-automoc || exit -1 + +cd build-automoc || exit -1 +"$CMAKE" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DQT_QMAKE_EXECUTABLE:STRING="$QMAKE" ../automoc || exit -1 +"$CMAKE" --build . || exit -1 +"$CMAKE" -P cmake_install.cmake || exit -1 + +export CMAKE_PREFIX_PATH="$INSTALLDIR:$CMAKE_PREFIX_PATH" + + +# build and install phonon +cd "$BASEDIR" || exit -1 +svn co svn://anonsvn.kde.org/home/kde/tags/kdesupport-for-4.3/kdesupport/phonon || exit -1 + +mkdir -p build-phonon || exit -1 + +cd build-phonon || exit -1 +"$CMAKE" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DQT_QMAKE_EXECUTABLE:STRING="$QMAKE" -DWITH_GLIB2=FALSE -DWITH_GObject=FALSE -DWITH_GStreamer=FALSE -DWITH_GStreamerPlugins=FALSE -DWITH_OpenGL=FALSE -DWITH_XCB=FALSE -DWITH_Xine=FALSE ../phonon || exit -1 +"$CMAKE" --build . || exit -1 +"$CMAKE" -P cmake_install.cmake || exit -1 + + +# finally build kdelibs/kdecore +cd "$BASEDIR" || exit -1 + +svn co svn://anonsvn.kde.org/home/kde/branches/KDE/4.3/kdelibs/ || exit -1 +mkdir -p build-kdelibs || exit -1 +cd build-kdelibs || exit -1 +# trick cmake into not searching strigi and not searching sharedmimeinfo +"$CMAKE" -DCMAKE_INSTALL_PREFIX="$INSTALLDIR" -DQT_QMAKE_EXECUTABLE:STRING="$QMAKE" -DSTRIGI_FOUND=TRUE -DSTRIGI_INCLUDE_DIR=/usr/include -DSTRIGI_STREAMANALYZER_LIBRARY=-lc -DSTRIGI_STREAMS_LIBRARY=-lc -DSTRIGI_STRIGIQTDBUSCLIENT_LIBRARY=-lc -DSTRIGI_NEEDS_SIGNED_CHAR=TRUE -DSTRIGI_NEEDS_CHAR=FALSE -DUPDATE_MIME_DATABASE_EXECUTABLE=/bin/sh ../kdelibs || exit -1 +make -C kdecore/tests kurltest || exit -1 + |