Merge topic 'test-property-genex'
6a47c37
add_test: Mention generator expressions in old-style add_test docsd331292
cmTestGenerator: Evaluate generator expressions in test properties6fe5c4a
cmTestGenerator: Separate test properties for each configuration
This commit is contained in:
commit
9939c99bc6
|
@ -66,7 +66,8 @@ public:
|
|||
"built by this project or an arbitrary executable on the "
|
||||
"system (like tclsh). The test will be run with the current working "
|
||||
"directory set to the CMakeList.txt files corresponding directory "
|
||||
"in the binary tree.\n"
|
||||
"in the binary tree. Tests added using this signature do not support "
|
||||
"generator expressions.\n"
|
||||
"\n"
|
||||
" add_test(NAME <name> [CONFIGURATIONS [Debug|Release|...]]\n"
|
||||
" [WORKING_DIRECTORY dir]\n"
|
||||
|
|
|
@ -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 "
|
||||
|
|
|
@ -39,29 +39,8 @@ cmTestGenerator
|
|||
void cmTestGenerator::GenerateScriptConfigs(std::ostream& os,
|
||||
Indent const& indent)
|
||||
{
|
||||
// First create the tests.
|
||||
// Create the tests.
|
||||
this->cmScriptGenerator::GenerateScriptConfigs(os, indent);
|
||||
|
||||
// Now generate the test properties.
|
||||
if(this->TestGenerated)
|
||||
{
|
||||
cmTest* test = this->Test;
|
||||
cmMakefile* mf = test->GetMakefile();
|
||||
cmLocalGenerator* lg = mf->GetLocalGenerator();
|
||||
std::ostream& fout = os;
|
||||
cmPropertyMap::const_iterator pit;
|
||||
cmPropertyMap* mpit = &test->GetProperties();
|
||||
if ( mpit->size() )
|
||||
{
|
||||
fout << "SET_TESTS_PROPERTIES(" << test->GetName() << " PROPERTIES ";
|
||||
for ( pit = mpit->begin(); pit != mpit->end(); ++ pit )
|
||||
{
|
||||
fout << " " << pit->first
|
||||
<< " " << lg->EscapeForCMake(pit->second.GetValue());
|
||||
}
|
||||
fout << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -127,6 +106,22 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||
|
||||
// Finish the test command.
|
||||
os << ")\n";
|
||||
|
||||
// Output properties for the test.
|
||||
cmPropertyMap& pm = this->Test->GetProperties();
|
||||
if(!pm.empty())
|
||||
{
|
||||
os << indent << "set_tests_properties(" << this->Test->GetName()
|
||||
<< " PROPERTIES ";
|
||||
for(cmPropertyMap::const_iterator i = pm.begin();
|
||||
i != pm.end(); ++i)
|
||||
{
|
||||
os << " " << i->first
|
||||
<< " " << lg->EscapeForCMake(
|
||||
ge.Parse(i->second.GetValue())->Evaluate(mf, config));
|
||||
}
|
||||
os << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -181,4 +176,21 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout,
|
|||
fout << "\"";
|
||||
}
|
||||
fout << ")" << std::endl;
|
||||
|
||||
// Output properties for the test.
|
||||
cmMakefile* mf = this->Test->GetMakefile();
|
||||
cmLocalGenerator* lg = mf->GetLocalGenerator();
|
||||
cmPropertyMap& pm = this->Test->GetProperties();
|
||||
if(!pm.empty())
|
||||
{
|
||||
fout << indent << "set_tests_properties(" << this->Test->GetName()
|
||||
<< " PROPERTIES ";
|
||||
for(cmPropertyMap::const_iterator i = pm.begin();
|
||||
i != pm.end(); ++i)
|
||||
{
|
||||
fout << " " << i->first
|
||||
<< " " << lg->EscapeForCMake(i->second.GetValue());
|
||||
}
|
||||
fout << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -195,3 +197,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$")
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
printf("%s\n", argv[1]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue