summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/get_filename_component
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-04-16 13:27:51 (GMT)
committerBrad King <brad.king@kitware.com>2013-04-16 13:35:29 (GMT)
commitec1ba9b0ae27a5731b98fecab648fa3edcfcffa2 (patch)
tree92bf0ea6452a8f76035dc75ecf3972e0934c8a01 /Tests/RunCMake/get_filename_component
parentdf71f968cd269854ab15147b012b6f07b1da6109 (diff)
downloadCMake-ec1ba9b0ae27a5731b98fecab648fa3edcfcffa2.zip
CMake-ec1ba9b0ae27a5731b98fecab648fa3edcfcffa2.tar.gz
CMake-ec1ba9b0ae27a5731b98fecab648fa3edcfcffa2.tar.bz2
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.
Diffstat (limited to 'Tests/RunCMake/get_filename_component')
-rw-r--r--Tests/RunCMake/get_filename_component/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/get_filename_component/KnownComponents.cmake32
-rw-r--r--Tests/RunCMake/get_filename_component/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/get_filename_component/UnknownComponent-result.txt1
-rw-r--r--Tests/RunCMake/get_filename_component/UnknownComponent-stderr.txt4
-rw-r--r--Tests/RunCMake/get_filename_component/UnknownComponent.cmake1
6 files changed, 45 insertions, 0 deletions
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..d5becc0
--- /dev/null
+++ b/Tests/RunCMake/get_filename_component/KnownComponents.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")
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)