|
| 1 | +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) |
| 2 | + |
| 3 | +include(${CPM_PATH}/CPM.cmake) |
| 4 | +include(${CPM_PATH}/testing.cmake) |
| 5 | + |
| 6 | +# Intercept underlying `FetchContent_Declare` |
| 7 | +function(FetchContent_Declare) |
| 8 | + set_property(GLOBAL PROPERTY last_FetchContent_Declare_ARGN "${ARGN}") |
| 9 | +endfunction() |
| 10 | +cpm_declare_fetch(PACKAGE VERSION INFO EMPTY "" ANOTHER) |
| 11 | + |
| 12 | +# TEST:`cpm_declare_fetch` shall forward empty arguments |
| 13 | +get_property(last_FetchContent_Declare_ARGN GLOBAL PROPERTY last_FetchContent_Declare_ARGN) |
| 14 | +assert_equal("${last_FetchContent_Declare_ARGN}" "PACKAGE;EMPTY;;ANOTHER") |
| 15 | + |
| 16 | +# TEST:`CPMDeclarePackage` shall store all including empty |
| 17 | +CPMDeclarePackage(FOO EMPTY "" ANOTHER) |
| 18 | +assert_equal("${CPM_DECLARATION_FOO}" "EMPTY;;ANOTHER") |
| 19 | + |
| 20 | +# Stub the actual fetch |
| 21 | +set(fibonacci_POPULATED YES) |
| 22 | +set(fibonacci_SOURCE_DIR ".") |
| 23 | +set(fibonacci_BINARY_DIR ".") |
| 24 | +macro(FetchContent_GetProperties) |
| 25 | + |
| 26 | +endmacro() |
| 27 | + |
| 28 | +# TEST:`CPMAddPackage` shall call `FetchContent_declare` with unmodified arguments including any |
| 29 | +# Empty-string arguments |
| 30 | +CPMAddPackage( |
| 31 | + NAME fibonacci |
| 32 | + GIT_REPOSITORY https://github.com/cpm-cmake/testpack-fibonacci.git |
| 33 | + VERSION 1.2.3 EMPTY_OPTION "" COMMAND_WITH_EMPTY_ARG foo "" bar |
| 34 | +) |
| 35 | +get_property(last_FetchContent_Declare_ARGN GLOBAL PROPERTY last_FetchContent_Declare_ARGN) |
| 36 | +assert_equal( |
| 37 | + "${last_FetchContent_Declare_ARGN}" |
| 38 | + "fibonacci;EMPTY_OPTION;;COMMAND_WITH_EMPTY_ARG;foo;;bar;GIT_REPOSITORY;https://github.com/cpm-cmake/testpack-fibonacci.git;GIT_TAG;v1.2.3" |
| 39 | +) |
| 40 | + |
| 41 | +# Intercept underlying `cpm_add_package_multi_arg` |
| 42 | +function(cpm_add_package_multi_arg) |
| 43 | + set_property(GLOBAL PROPERTY last_cpm_add_package_multi_arg_ARGN "${ARGN}") |
| 44 | +endfunction() |
| 45 | + |
| 46 | +# TEST: CPM Module file shall store all arguments including empty strings |
| 47 | +include(${CPM_MODULE_PATH}/Findfibonacci.cmake) |
| 48 | +get_property( |
| 49 | + last_cpm_add_package_multi_arg_ARGN GLOBAL PROPERTY last_cpm_add_package_multi_arg_ARGN |
| 50 | +) |
| 51 | +assert_equal( |
| 52 | + "${last_cpm_add_package_multi_arg_ARGN}" |
| 53 | + "NAME;fibonacci;GIT_REPOSITORY;https://github.com/cpm-cmake/testpack-fibonacci.git;VERSION;1.2.3;EMPTY_OPTION;;COMMAND_WITH_EMPTY_ARG;foo;;bar" |
| 54 | +) |
| 55 | + |
| 56 | +# remove generated files |
| 57 | +file(REMOVE_RECURSE ${CPM_MODULE_PATH}) |
| 58 | +file(REMOVE ${CPM_PACKAGE_LOCK_FILE}) |
0 commit comments