mirror of
https://github.com/reactos/CMake.git
synced 2025-01-07 11:40:23 +00:00
include_guard: add tests for the feature
This commit is contained in:
parent
80f1221f50
commit
c96f43b7dd
@ -215,6 +215,7 @@ add_RunCMake_test(get_property)
|
||||
add_RunCMake_test(if)
|
||||
add_RunCMake_test(include)
|
||||
add_RunCMake_test(include_directories)
|
||||
add_RunCMake_test(include_guard)
|
||||
add_RunCMake_test(list)
|
||||
add_RunCMake_test(message)
|
||||
add_RunCMake_test(project -DCMake_TEST_RESOURCES=${CMake_TEST_RESOURCES})
|
||||
|
3
Tests/RunCMake/include_guard/CMakeLists.txt
Normal file
3
Tests/RunCMake/include_guard/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
19
Tests/RunCMake/include_guard/DirectoryScope.cmake
Normal file
19
Tests/RunCMake/include_guard/DirectoryScope.cmake
Normal file
@ -0,0 +1,19 @@
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Scripts")
|
||||
|
||||
# Test include_guard with DIRECTORY scope
|
||||
|
||||
# Add subdirectory which includes DirScript three times:
|
||||
# 1. Include at inner function scope
|
||||
# 2. At directory scope
|
||||
# 3. At another subdirectory to check that the guard is checked
|
||||
# against parent directories
|
||||
add_subdirectory(sub_dir_script1)
|
||||
# Add another directory which includes DirScript
|
||||
add_subdirectory(sub_dir_script2)
|
||||
|
||||
# check inclusions count
|
||||
get_property(dir_count GLOBAL PROPERTY DIR_SCRIPT_COUNT)
|
||||
if(NOT dir_count EQUAL 2)
|
||||
message(FATAL_ERROR
|
||||
"Wrong DIR_SCRIPT_COUNT value: ${dir_count}, expected: 2")
|
||||
endif()
|
11
Tests/RunCMake/include_guard/GlobalScope.cmake
Normal file
11
Tests/RunCMake/include_guard/GlobalScope.cmake
Normal file
@ -0,0 +1,11 @@
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Scripts")
|
||||
|
||||
# Test GLOBAL include guard
|
||||
add_subdirectory(global_script_dir)
|
||||
include(GlobScript)
|
||||
|
||||
get_property(glob_count GLOBAL PROPERTY GLOB_SCRIPT_COUNT)
|
||||
if(NOT glob_count EQUAL 1)
|
||||
message(FATAL_ERROR
|
||||
"Wrong GLOB_SCRIPT_COUNT value: ${glob_count}, expected: 1")
|
||||
endif()
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,5 @@
|
||||
CMake Error at InvalidArgumentsNumber.cmake:1 \(include_guard\):
|
||||
include_guard given an invalid number of arguments. The command takes at
|
||||
most 1 argument.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
@ -0,0 +1 @@
|
||||
include_guard(ARG1 ARG2)
|
1
Tests/RunCMake/include_guard/InvalidScope-result.txt
Normal file
1
Tests/RunCMake/include_guard/InvalidScope-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/include_guard/InvalidScope-stderr.txt
Normal file
4
Tests/RunCMake/include_guard/InvalidScope-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
CMake Error at InvalidScope.cmake:1 \(include_guard\):
|
||||
include_guard given an invalid scope: INVALID
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
1
Tests/RunCMake/include_guard/InvalidScope.cmake
Normal file
1
Tests/RunCMake/include_guard/InvalidScope.cmake
Normal file
@ -0,0 +1 @@
|
||||
include_guard(INVALID)
|
7
Tests/RunCMake/include_guard/RunCMakeTest.cmake
Normal file
7
Tests/RunCMake/include_guard/RunCMakeTest.cmake
Normal file
@ -0,0 +1,7 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(VariableScope)
|
||||
run_cmake(DirectoryScope)
|
||||
run_cmake(GlobalScope)
|
||||
run_cmake(InvalidScope)
|
||||
run_cmake(InvalidArgumentsNumber)
|
12
Tests/RunCMake/include_guard/Scripts/DirScript.cmake
Normal file
12
Tests/RunCMake/include_guard/Scripts/DirScript.cmake
Normal file
@ -0,0 +1,12 @@
|
||||
include_guard(DIRECTORY)
|
||||
|
||||
set(prop_name DIR_SCRIPT_COUNT)
|
||||
get_property(count_is_set GLOBAL PROPERTY ${prop_name} SET)
|
||||
|
||||
if(NOT count_is_set)
|
||||
set_property(GLOBAL PROPERTY ${prop_name} 1)
|
||||
else()
|
||||
get_property(count GLOBAL PROPERTY ${prop_name})
|
||||
math(EXPR count "${count} + 1")
|
||||
set_property(GLOBAL PROPERTY ${prop_name} ${count})
|
||||
endif()
|
12
Tests/RunCMake/include_guard/Scripts/GlobScript.cmake
Normal file
12
Tests/RunCMake/include_guard/Scripts/GlobScript.cmake
Normal file
@ -0,0 +1,12 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
set(prop_name GLOB_SCRIPT_COUNT)
|
||||
get_property(count_is_set GLOBAL PROPERTY ${prop_name} SET)
|
||||
|
||||
if(NOT count_is_set)
|
||||
set_property(GLOBAL PROPERTY ${prop_name} 1)
|
||||
else()
|
||||
get_property(count GLOBAL PROPERTY ${prop_name})
|
||||
math(EXPR count "${count} + 1")
|
||||
set_property(GLOBAL PROPERTY ${prop_name} ${count})
|
||||
endif()
|
12
Tests/RunCMake/include_guard/Scripts/VarScript.cmake
Normal file
12
Tests/RunCMake/include_guard/Scripts/VarScript.cmake
Normal file
@ -0,0 +1,12 @@
|
||||
include_guard()
|
||||
|
||||
set(prop_name VAR_SCRIPT_COUNT)
|
||||
get_property(count_is_set GLOBAL PROPERTY ${prop_name} SET)
|
||||
|
||||
if(NOT count_is_set)
|
||||
set_property(GLOBAL PROPERTY ${prop_name} 1)
|
||||
else()
|
||||
get_property(count GLOBAL PROPERTY ${prop_name})
|
||||
math(EXPR count "${count} + 1")
|
||||
set_property(GLOBAL PROPERTY ${prop_name} ${count})
|
||||
endif()
|
24
Tests/RunCMake/include_guard/VariableScope.cmake
Normal file
24
Tests/RunCMake/include_guard/VariableScope.cmake
Normal file
@ -0,0 +1,24 @@
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Scripts")
|
||||
|
||||
# Test include_guard with VARIABLE scope
|
||||
function(var_include_func)
|
||||
# Include twice in the same scope
|
||||
include(VarScript)
|
||||
include(VarScript)
|
||||
get_property(var_count GLOBAL PROPERTY VAR_SCRIPT_COUNT)
|
||||
if(NOT var_count EQUAL 1)
|
||||
message(FATAL_ERROR
|
||||
"Wrong VAR_SCRIPT_COUNT value: ${var_count}, expected: 1")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
var_include_func()
|
||||
|
||||
# Check again that include_guard has been reset
|
||||
include(VarScript)
|
||||
|
||||
get_property(var_count GLOBAL PROPERTY VAR_SCRIPT_COUNT)
|
||||
if(NOT var_count EQUAL 2)
|
||||
message(FATAL_ERROR
|
||||
"Wrong VAR_SCRIPT_COUNT value: ${var_count}, expected: 2")
|
||||
endif()
|
@ -0,0 +1 @@
|
||||
include(GlobScript)
|
@ -0,0 +1,9 @@
|
||||
function(dir_check)
|
||||
include(DirScript)
|
||||
endfunction()
|
||||
|
||||
dir_check()
|
||||
|
||||
include(DirScript)
|
||||
|
||||
add_subdirectory(sub_dir_script3)
|
@ -0,0 +1 @@
|
||||
include(DirScript)
|
@ -0,0 +1 @@
|
||||
include(DirScript)
|
Loading…
Reference in New Issue
Block a user