diff options
author | Brad King <brad.king@kitware.com> | 2013-05-16 18:36:49 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2013-05-16 18:36:49 (GMT) |
commit | 7a198773f3edd384ad79cdf8dfbd09e3b564322d (patch) | |
tree | 8c354b4ebe16a1672ee1eef6808e633f866093af /Tests | |
parent | 3a0014a1fe0166846db026f9b715a52142c056bf (diff) | |
parent | 7d1590e6f98a48d1d4f8f95413710e37f01b6026 (diff) | |
download | CMake-7a198773f3edd384ad79cdf8dfbd09e3b564322d.zip CMake-7a198773f3edd384ad79cdf8dfbd09e3b564322d.tar.gz CMake-7a198773f3edd384ad79cdf8dfbd09e3b564322d.tar.bz2 |
Merge topic 'improve-get_filename_component-names'
7d1590e get_filename_component: Add DIRECTORY option (#14091)
ec1ba9b get_filename_component: Add explicit unit tests
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/Complex/Executable/complex.cxx | 80 | ||||
-rw-r--r-- | Tests/Complex/VarTests.cmake | 14 | ||||
-rw-r--r-- | Tests/Complex/cmTestConfigure.h.in | 9 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/Executable/complex.cxx | 80 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/VarTests.cmake | 14 | ||||
-rw-r--r-- | Tests/ComplexOneConfig/cmTestConfigure.h.in | 9 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/get_filename_component/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/get_filename_component/KnownComponents.cmake | 33 | ||||
-rw-r--r-- | Tests/RunCMake/get_filename_component/RunCMakeTest.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/get_filename_component/UnknownComponent-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt | 4 | ||||
-rw-r--r-- | Tests/RunCMake/get_filename_component/UnknownComponent.cmake | 1 |
13 files changed, 47 insertions, 206 deletions
diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx index 27d70ad..e904f28 100644 --- a/Tests/Complex/Executable/complex.cxx +++ b/Tests/Complex/Executable/complex.cxx @@ -635,86 +635,6 @@ int main() } // ---------------------------------------------------------------------- - // Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations - -#ifndef FILENAME_VAR_PATH_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_PATH_NAME is not defined."); -#else - if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0)) - { - cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); - } - else - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); - } -#endif - -#ifndef FILENAME_VAR_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME is not defined."); -#else - if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); - } - else - { - cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); - } -#endif - -#ifndef FILENAME_VAR_EXT - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_EXT is not defined."); -#else - if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); - } - else - { - cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); - } -#endif - -#ifndef FILENAME_VAR_NAME_WE - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME_WE is not defined."); -#else - if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); - } - else - { - cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); - } -#endif - -#ifndef PATH_VAR_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "PATH_VAR_NAME is not defined."); -#else - if((strcmp(PATH_VAR_NAME, "Complex") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0)) - { - cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME); - } - else - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "PATH_VAR_NAME == ", PATH_VAR_NAME); - } -#endif - - // ---------------------------------------------------------------------- // Test LOAD_CACHE #ifndef CACHE_TEST_VAR1 diff --git a/Tests/Complex/VarTests.cmake b/Tests/Complex/VarTests.cmake index 52ec1fc..70b803a 100644 --- a/Tests/Complex/VarTests.cmake +++ b/Tests/Complex/VarTests.cmake @@ -182,17 +182,3 @@ set(FOREACH_CONCAT "") foreach (INDEX a;b;c;d;e;f;g) set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}") endforeach() - -# -# Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations -# -find_file(FILENAME_VAR "VarTests.cmake" ${Complex_SOURCE_DIR}) - -get_filename_component(FILENAME_VAR_PATH ${FILENAME_VAR} PATH) -get_filename_component(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME) -get_filename_component(FILENAME_VAR_NAME ${FILENAME_VAR} NAME) -get_filename_component(FILENAME_VAR_EXT ${FILENAME_VAR} EXT) -get_filename_component(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE CACHE) - -find_path(PATH_VAR "cmTestConfigure.h.in" ${Complex_SOURCE_DIR}) -get_filename_component(PATH_VAR_NAME ${PATH_VAR} NAME) diff --git a/Tests/Complex/cmTestConfigure.h.in b/Tests/Complex/cmTestConfigure.h.in index 7741b6f..d7424b1 100644 --- a/Tests/Complex/cmTestConfigure.h.in +++ b/Tests/Complex/cmTestConfigure.h.in @@ -15,15 +15,6 @@ // Test WHILE #define WHILE_VALUE ${while_var} -// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations - -#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}" -#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}" -#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}" -#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}" - -#define PATH_VAR_NAME "${PATH_VAR_NAME}" - // Test LOAD_CACHE #define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}" diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx index 27d70ad..e904f28 100644 --- a/Tests/ComplexOneConfig/Executable/complex.cxx +++ b/Tests/ComplexOneConfig/Executable/complex.cxx @@ -635,86 +635,6 @@ int main() } // ---------------------------------------------------------------------- - // Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations - -#ifndef FILENAME_VAR_PATH_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_PATH_NAME is not defined."); -#else - if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0)) - { - cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); - } - else - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); - } -#endif - -#ifndef FILENAME_VAR_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME is not defined."); -#else - if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); - } - else - { - cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); - } -#endif - -#ifndef FILENAME_VAR_EXT - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_EXT is not defined."); -#else - if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); - } - else - { - cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); - } -#endif - -#ifndef FILENAME_VAR_NAME_WE - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME_WE is not defined."); -#else - if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); - } - else - { - cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); - } -#endif - -#ifndef PATH_VAR_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "PATH_VAR_NAME is not defined."); -#else - if((strcmp(PATH_VAR_NAME, "Complex") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0)) - { - cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME); - } - else - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "PATH_VAR_NAME == ", PATH_VAR_NAME); - } -#endif - - // ---------------------------------------------------------------------- // Test LOAD_CACHE #ifndef CACHE_TEST_VAR1 diff --git a/Tests/ComplexOneConfig/VarTests.cmake b/Tests/ComplexOneConfig/VarTests.cmake index 52ec1fc..70b803a 100644 --- a/Tests/ComplexOneConfig/VarTests.cmake +++ b/Tests/ComplexOneConfig/VarTests.cmake @@ -182,17 +182,3 @@ set(FOREACH_CONCAT "") foreach (INDEX a;b;c;d;e;f;g) set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}") endforeach() - -# -# Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations -# -find_file(FILENAME_VAR "VarTests.cmake" ${Complex_SOURCE_DIR}) - -get_filename_component(FILENAME_VAR_PATH ${FILENAME_VAR} PATH) -get_filename_component(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME) -get_filename_component(FILENAME_VAR_NAME ${FILENAME_VAR} NAME) -get_filename_component(FILENAME_VAR_EXT ${FILENAME_VAR} EXT) -get_filename_component(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE CACHE) - -find_path(PATH_VAR "cmTestConfigure.h.in" ${Complex_SOURCE_DIR}) -get_filename_component(PATH_VAR_NAME ${PATH_VAR} NAME) diff --git a/Tests/ComplexOneConfig/cmTestConfigure.h.in b/Tests/ComplexOneConfig/cmTestConfigure.h.in index 7741b6f..d7424b1 100644 --- a/Tests/ComplexOneConfig/cmTestConfigure.h.in +++ b/Tests/ComplexOneConfig/cmTestConfigure.h.in @@ -15,15 +15,6 @@ // Test WHILE #define WHILE_VALUE ${while_var} -// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations - -#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}" -#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}" -#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}" -#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}" - -#define PATH_VAR_NAME "${PATH_VAR_NAME}" - // Test LOAD_CACHE #define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}" diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 402c8a9..f676107 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -71,6 +71,7 @@ add_RunCMake_test(CompatibleInterface) add_RunCMake_test(add_dependencies) add_RunCMake_test(build_command) add_RunCMake_test(find_package) +add_RunCMake_test(get_filename_component) add_RunCMake_test(include) add_RunCMake_test(include_directories) add_RunCMake_test(list) diff --git a/Tests/RunCMake/get_filename_component/CMakeLists.txt b/Tests/RunCMake/get_filename_component/CMakeLists.txt new file mode 100644 index 0000000..e8db6b0 --- /dev/null +++ b/Tests/RunCMake/get_filename_component/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/get_filename_component/KnownComponents.cmake b/Tests/RunCMake/get_filename_component/KnownComponents.cmake new file mode 100644 index 0000000..a4ef8ff --- /dev/null +++ b/Tests/RunCMake/get_filename_component/KnownComponents.cmake @@ -0,0 +1,33 @@ +macro(check desc actual expect) + if(NOT "x${actual}" STREQUAL "x${expect}") + message(SEND_ERROR "${desc}: got \"${actual}\", not \"${expect}\"") + endif() +endmacro() + +set(filename "/path/to/filename.ext.in") +set(expect_DIRECTORY "/path/to") +set(expect_NAME "filename.ext.in") +set(expect_EXT ".ext.in") +set(expect_NAME_WE "filename") +set(expect_PATH "/path/to") +foreach(c DIRECTORY NAME EXT NAME_WE PATH) + get_filename_component(actual_${c} "${filename}" ${c}) + check("${c}" "${actual_${c}}" "${expect_${c}}") +endforeach() + +get_filename_component(test_slashes "c:\\path\\to\\filename.ext.in" DIRECTORY) +check("DIRECTORY from backslashes" "${test_slashes}" "c:/path/to") + +get_filename_component(test_winroot "c:\\filename.ext.in" DIRECTORY) +check("DIRECTORY in windows root" "${test_winroot}" "c:/") + +get_filename_component(test_absolute "/path/to/a/../filename.ext.in" ABSOLUTE) +check("ABSOLUTE" "${test_absolute}" "/path/to/filename.ext.in") + +get_filename_component(test_cache "/path/to/filename.ext.in" DIRECTORY CACHE) +check("CACHE 1" "${test_cache}" "/path/to") +get_filename_component(test_cache "/path/to/other/filename.ext.in" DIRECTORY CACHE) +check("CACHE 2" "${test_cache}" "/path/to") +unset(test_cache CACHE) +get_filename_component(test_cache "/path/to/other/filename.ext.in" DIRECTORY CACHE) +check("CACHE 3" "${test_cache}" "/path/to/other") diff --git a/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake b/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake new file mode 100644 index 0000000..156fc8f --- /dev/null +++ b/Tests/RunCMake/get_filename_component/RunCMakeTest.cmake @@ -0,0 +1,4 @@ +include(RunCMake) + +run_cmake(KnownComponents) +run_cmake(UnknownComponent) diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent-result.txt b/Tests/RunCMake/get_filename_component/UnknownComponent-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/get_filename_component/UnknownComponent-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt b/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt new file mode 100644 index 0000000..b146e5b --- /dev/null +++ b/Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at UnknownComponent.cmake:1 \(get_filename_component\): + get_filename_component unknown component BOGUS +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/get_filename_component/UnknownComponent.cmake b/Tests/RunCMake/get_filename_component/UnknownComponent.cmake new file mode 100644 index 0000000..06abc51 --- /dev/null +++ b/Tests/RunCMake/get_filename_component/UnknownComponent.cmake @@ -0,0 +1 @@ +get_filename_component(var "/path/to/filename.ext.in" BOGUS) |