summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/cmake_language/CallInvalidCommand.cmake2
-rw-r--r--Tests/RunCMake/cmake_language/CheckIncludeGuard.cmake4
-rw-r--r--Tests/RunCMake/cmake_language/CheckProject/CMakeLists.txt19
-rw-r--r--Tests/RunCMake/cmake_language/CheckProject/lib.c0
-rw-r--r--Tests/RunCMake/cmake_language/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/cmake_language/call_invalid_command.cmake14
-rw-r--r--Tests/RunCMake/cmake_language/call_valid_command.cmake99
-rw-r--r--Tests/RunCMake/ctest_test/RunCMakeTest.cmake38
-rw-r--r--Tests/RunCMake/ctest_test/TestRepeatNotRun-result.txt1
-rw-r--r--Tests/RunCMake/ctest_test/TestRepeatNotRun-stderr.txt1
-rw-r--r--Tests/RunCMake/ctest_test/TestRepeatNotRun-stdout.txt5
-rw-r--r--Tests/RunCMake/ctest_test/TestRepeatNotRun.cmake10
13 files changed, 190 insertions, 7 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 983f7e4..868eb24 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -416,7 +416,7 @@ endif()
if(TARGET ctresalloc)
add_RunCMake_test(CTestResourceAllocation -DCTRESALLOC_COMMAND=$<TARGET_FILE:ctresalloc>)
else()
- message(WARNING "Could not find or build ctresalloc")
+ message(STATUS "Could not find ctresalloc")
endif()
find_package(Qt4 QUIET)
diff --git a/Tests/RunCMake/cmake_language/CallInvalidCommand.cmake b/Tests/RunCMake/cmake_language/CallInvalidCommand.cmake
new file mode 100644
index 0000000..8bee6f2
--- /dev/null
+++ b/Tests/RunCMake/cmake_language/CallInvalidCommand.cmake
@@ -0,0 +1,2 @@
+
+cmake_language(CALL ${COMMAND})
diff --git a/Tests/RunCMake/cmake_language/CheckIncludeGuard.cmake b/Tests/RunCMake/cmake_language/CheckIncludeGuard.cmake
new file mode 100644
index 0000000..902c1e4
--- /dev/null
+++ b/Tests/RunCMake/cmake_language/CheckIncludeGuard.cmake
@@ -0,0 +1,4 @@
+
+cmake_language (CALL "include_guard")
+
+set (GUARD_VALUE 1)
diff --git a/Tests/RunCMake/cmake_language/CheckProject/CMakeLists.txt b/Tests/RunCMake/cmake_language/CheckProject/CMakeLists.txt
new file mode 100644
index 0000000..9a27692
--- /dev/null
+++ b/Tests/RunCMake/cmake_language/CheckProject/CMakeLists.txt
@@ -0,0 +1,19 @@
+
+cmake_language (CALL cmake_minimum_required VERSION 3.17...3.18)
+
+cmake_language (CALL project CheckProject VERSION 1.2.3 LANGUAGES C)
+
+if (NOT PROJECT_NAME STREQUAL "CheckProject")
+ message (SEND_ERROR "error on project() usage.")
+endif()
+
+if (NOT CheckProject_VERSION VERSION_EQUAL "1.2.3")
+ message (SEND_ERROR "error on project() usage.")
+endif()
+
+get_property (languages GLOBAL PROPERTY ENABLED_LANGUAGES)
+if (NOT "C" IN_LIST languages)
+ message (SEND_ERROR "error on project() usage.")
+endif()
+
+add_library (lib SHARED lib.c)
diff --git a/Tests/RunCMake/cmake_language/CheckProject/lib.c b/Tests/RunCMake/cmake_language/CheckProject/lib.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/cmake_language/CheckProject/lib.c
diff --git a/Tests/RunCMake/cmake_language/RunCMakeTest.cmake b/Tests/RunCMake/cmake_language/RunCMakeTest.cmake
index c556e42..5fb93c8 100644
--- a/Tests/RunCMake/cmake_language/RunCMakeTest.cmake
+++ b/Tests/RunCMake/cmake_language/RunCMakeTest.cmake
@@ -2,6 +2,8 @@ include(RunCMake)
run_cmake(no_parameters)
run_cmake(unknown_meta_operation)
+run_cmake(call_invalid_command)
+run_cmake(call_valid_command)
run_cmake(call_double_evaluation)
run_cmake(call_expanded_command)
run_cmake(call_expanded_command_and_arguments)
diff --git a/Tests/RunCMake/cmake_language/call_invalid_command.cmake b/Tests/RunCMake/cmake_language/call_invalid_command.cmake
new file mode 100644
index 0000000..88bf08c
--- /dev/null
+++ b/Tests/RunCMake/cmake_language/call_invalid_command.cmake
@@ -0,0 +1,14 @@
+
+foreach (command IN ITEMS "function" "ENDFUNCTION"
+ "macro" "endMACRO"
+ "if" "elseif" "else" "endif"
+ "while" "endwhile"
+ "foreach" "endforeach")
+ execute_process(COMMAND "${CMAKE_COMMAND}" -DCOMMAND=${command}
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/CallInvalidCommand.cmake"
+ OUTPUT_QUIET ERROR_QUIET
+ RESULT_VARIABLE result)
+ if (NOT result)
+ message (SEND_ERROR "cmake_language(CALL ${command}) unexpectedly successfull.")
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/cmake_language/call_valid_command.cmake b/Tests/RunCMake/cmake_language/call_valid_command.cmake
new file mode 100644
index 0000000..2e965dc
--- /dev/null
+++ b/Tests/RunCMake/cmake_language/call_valid_command.cmake
@@ -0,0 +1,99 @@
+
+## check continue() usage
+set (VALUE 0)
+foreach (i RANGE 1 4)
+ set (VALUE "${i}")
+ cmake_language (CALL "continue")
+ set (VALUE "0")
+endforeach()
+if (NOT VALUE EQUAL "4")
+ message (SEND_ERROR "error on continue() usage.")
+endif()
+
+
+## check break() usage
+set (VALUE 0)
+foreach (i RANGE 1 4)
+ set (VALUE "${i}")
+ cmake_language (CALL "break")
+ set (VALUE 0)
+endforeach()
+if (NOT VALUE EQUAL "1")
+ message (SEND_ERROR "error on break() usage.")
+endif()
+
+
+## check return() usage in macro
+macro (call_return_in_macro)
+ cmake_language (CALL "return")
+ set (VALUE 1)
+endmacro()
+function (wrapper)
+ call_return_in_macro()
+ set (VALUE 1 PARENT_SCOPE)
+endfunction()
+
+set (VALUE 0)
+wrapper()
+if (NOT VALUE EQUAL "0")
+ message (SEND_ERROR "error on return() usage in macro.")
+endif()
+
+set (VALUE 0)
+cmake_language (CALL "wrapper")
+if (NOT VALUE EQUAL "0")
+ message (SEND_ERROR "error on return() usage in macro.")
+endif()
+
+function (wrapper2)
+ cmake_language (CALL "call_return_in_macro")
+ set (VALUE 1 PARENT_SCOPE)
+endfunction()
+
+set (VALUE 0)
+wrapper2()
+if (NOT VALUE EQUAL "0")
+ message (SEND_ERROR "error on return() usage in macro.")
+endif()
+
+set (VALUE 0)
+cmake_language (CALL "wrapper2")
+if (NOT VALUE EQUAL "0")
+ message (SEND_ERROR "error on return() usage in macro.")
+endif()
+
+## check return() usage in function
+function (call_return_in_function)
+ cmake_language (CALL "return")
+ set (VALUE 1 PARENT_SCOPE)
+endfunction()
+
+set (VALUE 0)
+call_return_in_function()
+if (NOT VALUE EQUAL "0")
+ message (SEND_ERROR "error on return() usage in function.")
+endif()
+
+set (VALUE 0)
+cmake_language (CALL "call_return_in_function")
+if (NOT VALUE EQUAL "0")
+ message (SEND_ERROR "error on return() usage in function.")
+endif()
+
+
+## check usage of include_guard()
+set (GUARD_VALUE 0)
+include ("${CMAKE_CURRENT_SOURCE_DIR}/CheckIncludeGuard.cmake")
+if (NOT GUARD_VALUE EQUAL "1")
+ message (SEND_ERROR "error on include_guard() on first include.")
+endif()
+
+set (GUARD_VALUE 0)
+include ("${CMAKE_CURRENT_SOURCE_DIR}/CheckIncludeGuard.cmake")
+if (NOT GUARD_VALUE EQUAL "0")
+ message (SEND_ERROR "error on include_guard() on second include.")
+endif()
+
+
+## check usage of cmake_minimum_required() and project()
+add_subdirectory (CheckProject)
diff --git a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
index 18ae793..b82335f 100644
--- a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
@@ -81,20 +81,46 @@ run_TestOutputSize()
run_ctest_test(TestRepeatBad1 REPEAT UNKNOWN:3)
run_ctest_test(TestRepeatBad2 REPEAT UNTIL_FAIL:-1)
-function(run_TestRepeat case)
- set(CASE_CTEST_TEST_ARGS EXCLUDE RunCMakeVersion ${ARGN})
- string(CONCAT CASE_CMAKELISTS_SUFFIX_CODE [[
+function(run_TestRepeat case return_value )
+ set(CASE_CTEST_TEST_ARGS RETURN_VALUE result EXCLUDE RunCMakeVersion ${ARGN})
+ string(CONCAT suffix_code [[
add_test(NAME testRepeat
COMMAND ${CMAKE_COMMAND} -D COUNT_FILE=${CMAKE_CURRENT_BINARY_DIR}/count.cmake
-P "]] "${RunCMake_SOURCE_DIR}/TestRepeat${case}" [[.cmake")
set_property(TEST testRepeat PROPERTY TIMEOUT 5)
]])
+ string(APPEND CASE_CMAKELISTS_SUFFIX_CODE "${suffix_code}")
run_ctest(TestRepeat${case})
+
+ #write to end of the test file logic to Verify we get the expected
+ #return code
+ string(REPLACE "RETURN_VALUE:" "" return_value "${return_value}" )
+ file(APPEND "${RunCMake_BINARY_DIR}/TestRepeat${case}/test.cmake"
+"
+
+ set(expected_result ${return_value})
+ message(STATUS \${result})
+ if(NOT result EQUAL expected_result)
+ message(FATAL_ERROR \"expected a return value of: \${expected_result},
+ instead got: \${result}\")
+ endif()
+"
+ )
endfunction()
-run_TestRepeat(UntilFail REPEAT UNTIL_FAIL:3)
-run_TestRepeat(UntilPass REPEAT UNTIL_PASS:3)
-run_TestRepeat(AfterTimeout REPEAT AFTER_TIMEOUT:3)
+
+run_TestRepeat(UntilFail RETURN_VALUE:1 REPEAT UNTIL_FAIL:3)
+run_TestRepeat(UntilPass RETURN_VALUE:0 REPEAT UNTIL_PASS:3)
+run_TestRepeat(AfterTimeout RETURN_VALUE:0 REPEAT AFTER_TIMEOUT:3)
+
+# test repeat and not run tests interact correctly
+set(CASE_CMAKELISTS_SUFFIX_CODE [[
+add_test(NAME testNotRun
+ COMMAND ${CMAKE_COMMAND}/doesnt_exist)
+ set_property(TEST testNotRun PROPERTY TIMEOUT 5)
+ ]])
+run_TestRepeat(NotRun RETURN_VALUE:1 REPEAT UNTIL_PASS:3)
+unset(CASE_CMAKELISTS_SUFFIX_CODE)
# test --stop-on-failure
function(run_stop_on_failure)
diff --git a/Tests/RunCMake/ctest_test/TestRepeatNotRun-result.txt b/Tests/RunCMake/ctest_test/TestRepeatNotRun-result.txt
new file mode 100644
index 0000000..b57e2de
--- /dev/null
+++ b/Tests/RunCMake/ctest_test/TestRepeatNotRun-result.txt
@@ -0,0 +1 @@
+(-1|255)
diff --git a/Tests/RunCMake/ctest_test/TestRepeatNotRun-stderr.txt b/Tests/RunCMake/ctest_test/TestRepeatNotRun-stderr.txt
new file mode 100644
index 0000000..a69932d
--- /dev/null
+++ b/Tests/RunCMake/ctest_test/TestRepeatNotRun-stderr.txt
@@ -0,0 +1 @@
+.*Unable to find executable.*
diff --git a/Tests/RunCMake/ctest_test/TestRepeatNotRun-stdout.txt b/Tests/RunCMake/ctest_test/TestRepeatNotRun-stdout.txt
new file mode 100644
index 0000000..72c98bc
--- /dev/null
+++ b/Tests/RunCMake/ctest_test/TestRepeatNotRun-stdout.txt
@@ -0,0 +1,5 @@
+.*
+50% tests passed, 1 tests failed out of 2
+.*
+The following tests FAILED:
+.*testNotRun.*Not Run.*
diff --git a/Tests/RunCMake/ctest_test/TestRepeatNotRun.cmake b/Tests/RunCMake/ctest_test/TestRepeatNotRun.cmake
new file mode 100644
index 0000000..abde4f0
--- /dev/null
+++ b/Tests/RunCMake/ctest_test/TestRepeatNotRun.cmake
@@ -0,0 +1,10 @@
+include("${COUNT_FILE}" OPTIONAL)
+if(NOT COUNT)
+ set(COUNT 0)
+endif()
+math(EXPR COUNT "${COUNT} + 1")
+file(WRITE "${COUNT_FILE}" "set(COUNT ${COUNT})\n")
+if(NOT COUNT EQUAL 2)
+ message("this test times out except on the 2nd run")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 10)
+endif()