diff options
author | Brad King <brad.king@kitware.com> | 2009-03-16 14:51:30 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-03-16 14:51:30 (GMT) |
commit | 9862f383d09018cd9e14a6054c03b508c0ef3afa (patch) | |
tree | b68b27adc864c2e0cfc5eab806b18b3ee223745c /Source/cmTestGenerator.cxx | |
parent | 606e6ff9cd2d1ab6a242a38e0c3f6df7167fdff8 (diff) | |
download | CMake-9862f383d09018cd9e14a6054c03b508c0ef3afa.zip CMake-9862f383d09018cd9e14a6054c03b508c0ef3afa.tar.gz CMake-9862f383d09018cd9e14a6054c03b508c0ef3afa.tar.bz2 |
ENH: Add NAME mode to ADD_TEST command
This creates command mode add_test(NAME ...). This signature is
extensible with more keyword arguments later. The main purpose is to
enable automatic replacement of target names with built target file
locations. A side effect of this feature is support for tests that only
run under specific configurations.
Diffstat (limited to 'Source/cmTestGenerator.cxx')
-rw-r--r-- | Source/cmTestGenerator.cxx | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 8581c96..7f4c2d1 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -16,7 +16,10 @@ =========================================================================*/ #include "cmTestGenerator.h" +#include "cmLocalGenerator.h" +#include "cmMakefile.h" #include "cmSystemTools.h" +#include "cmTarget.h" #include "cmTest.h" //---------------------------------------------------------------------------- @@ -26,7 +29,7 @@ cmTestGenerator cmScriptGenerator("CTEST_CONFIGURATION_TYPE", configurations), Test(test) { - this->ActionsPerConfig = false; + this->ActionsPerConfig = !test->GetOldStyle(); this->TestGenerated = false; } @@ -92,9 +95,70 @@ void cmTestGenerator::GenerateScriptConfigs(std::ostream& os, } //---------------------------------------------------------------------------- -void cmTestGenerator::GenerateScriptActions(std::ostream& fout, +void cmTestGenerator::GenerateScriptActions(std::ostream& os, Indent const& indent) { + if(this->ActionsPerConfig) + { + // This is the per-config generation in a single-configuration + // build generator case. The superclass will call our per-config + // method. + this->cmScriptGenerator::GenerateScriptActions(os, indent); + } + else + { + // This is an old-style test, so there is only one config. + //assert(this->Test->GetOldStyle()); + this->GenerateOldStyle(os, indent); + } +} + +//---------------------------------------------------------------------------- +void cmTestGenerator::GenerateScriptForConfig(std::ostream& os, + const char* config, + Indent const& indent) +{ + this->TestGenerated = true; + + // Start the test command. + os << indent << "ADD_TEST(" << this->Test->GetName() << " "; + + // Get the test command line to be executed. + std::vector<std::string> const& command = this->Test->GetCommand(); + + // Check whether the command executable is a target whose name is to + // be translated. + std::string exe = command[0]; + cmMakefile* mf = this->Test->GetMakefile(); + cmTarget* target = mf->FindTargetToUse(exe.c_str()); + if(target && target->GetType() == cmTarget::EXECUTABLE) + { + // Use the target file on disk. + exe = target->GetFullPath(config); + } + else + { + // Use the command name given. + cmSystemTools::ConvertToUnixSlashes(exe); + } + + // Generate the command line with full escapes. + cmLocalGenerator* lg = mf->GetLocalGenerator(); + os << lg->EscapeForCMake(exe.c_str()); + for(std::vector<std::string>::const_iterator ci = command.begin()+1; + ci != command.end(); ++ci) + { + os << " " << lg->EscapeForCMake(ci->c_str()); + } + + // Finish the test command. + os << ")\n"; +} + +//---------------------------------------------------------------------------- +void cmTestGenerator::GenerateOldStyle(std::ostream& fout, + Indent const& indent) +{ this->TestGenerated = true; // Get the test command line to be executed. |