get_filename_component: Add explicit unit tests
Add test RunCMake.get_filename_component to cover cases of the command. Remove redundant coverage of these cases from the "complex" tests.
This commit is contained in:
parent
df71f968cd
commit
ec1ba9b0ae
|
@ -634,86 +634,6 @@ int main()
|
||||||
cmPassed("WHILE command is working");
|
cmPassed("WHILE command is working");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// 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
|
// Test LOAD_CACHE
|
||||||
|
|
||||||
|
|
|
@ -182,17 +182,3 @@ set(FOREACH_CONCAT "")
|
||||||
foreach (INDEX a;b;c;d;e;f;g)
|
foreach (INDEX a;b;c;d;e;f;g)
|
||||||
set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
|
set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
|
||||||
endforeach()
|
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)
|
|
||||||
|
|
|
@ -15,15 +15,6 @@
|
||||||
// Test WHILE
|
// Test WHILE
|
||||||
#define WHILE_VALUE ${while_var}
|
#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
|
// Test LOAD_CACHE
|
||||||
|
|
||||||
#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
|
#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
|
||||||
|
|
|
@ -634,86 +634,6 @@ int main()
|
||||||
cmPassed("WHILE command is working");
|
cmPassed("WHILE command is working");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// 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
|
// Test LOAD_CACHE
|
||||||
|
|
||||||
|
|
|
@ -182,17 +182,3 @@ set(FOREACH_CONCAT "")
|
||||||
foreach (INDEX a;b;c;d;e;f;g)
|
foreach (INDEX a;b;c;d;e;f;g)
|
||||||
set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
|
set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
|
||||||
endforeach()
|
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)
|
|
||||||
|
|
|
@ -15,15 +15,6 @@
|
||||||
// Test WHILE
|
// Test WHILE
|
||||||
#define WHILE_VALUE ${while_var}
|
#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
|
// Test LOAD_CACHE
|
||||||
|
|
||||||
#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
|
#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
|
||||||
|
|
|
@ -71,6 +71,7 @@ add_RunCMake_test(CompatibleInterface)
|
||||||
add_RunCMake_test(add_dependencies)
|
add_RunCMake_test(add_dependencies)
|
||||||
add_RunCMake_test(build_command)
|
add_RunCMake_test(build_command)
|
||||||
add_RunCMake_test(find_package)
|
add_RunCMake_test(find_package)
|
||||||
|
add_RunCMake_test(get_filename_component)
|
||||||
add_RunCMake_test(include)
|
add_RunCMake_test(include)
|
||||||
add_RunCMake_test(include_directories)
|
add_RunCMake_test(include_directories)
|
||||||
add_RunCMake_test(list)
|
add_RunCMake_test(list)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
project(${RunCMake_TEST} NONE)
|
||||||
|
include(${RunCMake_TEST}.cmake)
|
|
@ -0,0 +1,32 @@
|
||||||
|
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_PATH "/path/to")
|
||||||
|
set(expect_NAME "filename.ext.in")
|
||||||
|
set(expect_EXT ".ext.in")
|
||||||
|
set(expect_NAME_WE "filename")
|
||||||
|
foreach(c PATH NAME EXT NAME_WE)
|
||||||
|
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" PATH)
|
||||||
|
check("PATH from backslashes" "${test_slashes}" "c:/path/to")
|
||||||
|
|
||||||
|
get_filename_component(test_winroot "c:\\filename.ext.in" PATH)
|
||||||
|
check("PATH 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" PATH CACHE)
|
||||||
|
check("CACHE 1" "${test_cache}" "/path/to")
|
||||||
|
get_filename_component(test_cache "/path/to/other/filename.ext.in" PATH CACHE)
|
||||||
|
check("CACHE 2" "${test_cache}" "/path/to")
|
||||||
|
unset(test_cache CACHE)
|
||||||
|
get_filename_component(test_cache "/path/to/other/filename.ext.in" PATH CACHE)
|
||||||
|
check("CACHE 3" "${test_cache}" "/path/to/other")
|
|
@ -0,0 +1,4 @@
|
||||||
|
include(RunCMake)
|
||||||
|
|
||||||
|
run_cmake(KnownComponents)
|
||||||
|
run_cmake(UnknownComponent)
|
|
@ -0,0 +1 @@
|
||||||
|
1
|
|
@ -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\)
|
|
@ -0,0 +1 @@
|
||||||
|
get_filename_component(var "/path/to/filename.ext.in" BOGUS)
|
Loading…
Reference in New Issue