summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/cmake_language
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/RunCMake/cmake_language')
-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
7 files changed, 140 insertions, 0 deletions
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)