summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2013-08-07 21:07:30 (GMT)
committerBrad King <brad.king@kitware.com>2013-09-20 12:18:22 (GMT)
commitd331292c121269ccfceee302a0f9bbb960b9f02d (patch)
treebe5575ff1ac79b79fbd63d2bef957a8c17692f2f
parent6fe5c4afc0a8363927ecd48bea4cc822894f97db (diff)
downloadCMake-d331292c121269ccfceee302a0f9bbb960b9f02d.zip
CMake-d331292c121269ccfceee302a0f9bbb960b9f02d.tar.gz
CMake-d331292c121269ccfceee302a0f9bbb960b9f02d.tar.bz2
cmTestGenerator: Evaluate generator expressions in test properties
This is useful for cases like: add_test(NAME mytest COMMAND mydriver $<TARGET_FILE:myexe>) set_tests_properties(mytest PROPERTIES REQUIRED_FILES "$<TARGET_FILE:myexe>" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>" ) In this example we require the actual test executable to exist to run the test in addition to the test driver at argv[0]. Also the $<CONFIGURATION> expression improves over \${CTEST_CONFIGURATION_TYPE} because the latter is not normalized for case-sensitive filesystems.
-rw-r--r--Source/cmSetTestsPropertiesCommand.h3
-rw-r--r--Source/cmTestGenerator.cxx3
-rw-r--r--Tests/CMakeLists.txt1
-rw-r--r--Tests/GeneratorExpression/CMakeLists.txt32
-rw-r--r--Tests/GeneratorExpression/echo.c8
-rw-r--r--Tests/GeneratorExpression/pwd.c34
6 files changed, 78 insertions, 3 deletions
diff --git a/Source/cmSetTestsPropertiesCommand.h b/Source/cmSetTestsPropertiesCommand.h
index 3a59218..f2f2611 100644
--- a/Source/cmSetTestsPropertiesCommand.h
+++ b/Source/cmSetTestsPropertiesCommand.h
@@ -51,7 +51,8 @@ public:
" set_tests_properties(test1 [test2...] PROPERTIES prop1 value1 prop2"
" value2)\n"
"Set a property for the tests. If the property is not found, CMake "
- "will report an error. The properties include:\n"
+ "will report an error. Generator expressions will be expanded the same "
+ "as supported by the test's add_test call. The properties include:\n"
"WILL_FAIL: If set to true, this will invert the pass/fail flag of the"
" test.\n"
"PASS_REGULAR_EXPRESSION: If set, the test output will be checked "
diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx
index 3167362..e5984a8 100644
--- a/Source/cmTestGenerator.cxx
+++ b/Source/cmTestGenerator.cxx
@@ -117,7 +117,8 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
i != pm.end(); ++i)
{
os << " " << i->first
- << " " << lg->EscapeForCMake(i->second.GetValue());
+ << " " << lg->EscapeForCMake(
+ ge.Parse(i->second.GetValue())->Evaluate(mf, config));
}
os << ")" << std::endl;
}
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 9c3ed59..a5ad58c 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -604,6 +604,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
${build_generator_args}
--build-project GeneratorExpression
--build-options -DCMAKE_BUILD_TYPE=\${CTEST_CONFIGURATION_TYPE}
+ --test-command ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} -V
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/GeneratorExpression")
diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt
index 4d8d7ed..89d8780 100644
--- a/Tests/GeneratorExpression/CMakeLists.txt
+++ b/Tests/GeneratorExpression/CMakeLists.txt
@@ -1,5 +1,7 @@
cmake_minimum_required (VERSION 2.8.8)
-project(GeneratorExpression CXX)
+project(GeneratorExpression)
+
+include(CTest)
# This test is split into multiple parts as needed to avoid NMake command
# length limits.
@@ -190,3 +192,31 @@ add_custom_target(check-part3 ALL
COMMAND ${CMAKE_COMMAND} -E echo "check done (part 3 of 3)"
VERBATIM
)
+
+#-----------------------------------------------------------------------------
+# Cover test properties with generator expressions.
+add_executable(echo echo.c)
+add_executable(pwd pwd.c)
+
+add_test(NAME echo-configuration COMMAND echo $<CONFIGURATION>)
+set_property(TEST echo-configuration PROPERTY
+ PASS_REGULAR_EXPRESSION "^$<CONFIGURATION>\n$")
+
+add_test(NAME echo-target-file COMMAND echo $<TARGET_FILE:echo>)
+set_property(TEST echo-target-file PROPERTY
+ PASS_REGULAR_EXPRESSION "/echo${CMAKE_EXECUTABLE_SUFFIX}\n$")
+set_property(TEST echo-target-file PROPERTY
+ REQUIRED_FILES "$<TARGET_FILE:echo>")
+
+add_test(NAME working-dir-arg
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/WorkingDirectory/$<CONFIGURATION>"
+ COMMAND pwd)
+set_property(TEST working-dir-arg PROPERTY
+ PASS_REGULAR_EXPRESSION "WorkingDirectory/$<CONFIGURATION>\n$")
+foreach(c ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/WorkingDirectory/${c}")
+endforeach()
+
+add_test(echo-old-style echo "\$<CONFIGURATION>")
+set_property(TEST echo-old-style PROPERTY
+ PASS_REGULAR_EXPRESSION "^\\$<CONFIGURATION>\n$")
diff --git a/Tests/GeneratorExpression/echo.c b/Tests/GeneratorExpression/echo.c
new file mode 100644
index 0000000..06b0844
--- /dev/null
+++ b/Tests/GeneratorExpression/echo.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char* argv[])
+{
+ printf("%s\n", argv[1]);
+ return EXIT_SUCCESS;
+}
diff --git a/Tests/GeneratorExpression/pwd.c b/Tests/GeneratorExpression/pwd.c
new file mode 100644
index 0000000..054b1af
--- /dev/null
+++ b/Tests/GeneratorExpression/pwd.c
@@ -0,0 +1,34 @@
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef _WIN32
+#include <direct.h>
+#define getcurdir _getcwd
+#else
+#include <unistd.h>
+#define getcurdir getcwd
+#endif
+
+int main(int argc, char* argv[])
+{
+#define BUFSZ 20000
+ char buf[BUFSZ + 1];
+#ifdef _WIN32
+ char *pos;
+#endif
+ getcurdir(buf, BUFSZ);
+#ifdef _WIN32
+ pos = buf;
+ while (*pos)
+ {
+ if (*pos == '\\')
+ {
+ *pos = '/';
+ }
+ ++pos;
+ }
+#endif
+ printf("%s\n", buf);
+ return EXIT_SUCCESS;
+}