summaryrefslogtreecommitdiffstats
path: root/Source/cmAddTestCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-03-16 14:51:30 (GMT)
committerBrad King <brad.king@kitware.com>2009-03-16 14:51:30 (GMT)
commit9862f383d09018cd9e14a6054c03b508c0ef3afa (patch)
treeb68b27adc864c2e0cfc5eab806b18b3ee223745c /Source/cmAddTestCommand.cxx
parent606e6ff9cd2d1ab6a242a38e0c3f6df7167fdff8 (diff)
downloadCMake-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/cmAddTestCommand.cxx')
-rw-r--r--Source/cmAddTestCommand.cxx111
1 files changed, 110 insertions, 1 deletions
diff --git a/Source/cmAddTestCommand.cxx b/Source/cmAddTestCommand.cxx
index e894bd8..3e735a1 100644
--- a/Source/cmAddTestCommand.cxx
+++ b/Source/cmAddTestCommand.cxx
@@ -25,6 +25,11 @@
bool cmAddTestCommand
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
+ if(!args.empty() && args[0] == "NAME")
+ {
+ return this->HandleNameMode(args);
+ }
+
// First argument is the name of the test Second argument is the name of
// the executable to run (a target or external program) Remaining arguments
// are the arguments to pass to the executable
@@ -45,12 +50,116 @@ bool cmAddTestCommand
// Create the test but add a generator only the first time it is
// seen. This preserves behavior from before test generators.
cmTest* test = this->Makefile->GetTest(args[0].c_str());
- if(!test)
+ if(test)
+ {
+ // If the test was already added by a new-style signature do not
+ // allow it to be duplicated.
+ if(!test->GetOldStyle())
+ {
+ cmOStringStream e;
+ e << " given test name \"" << args[0]
+ << "\" which already exists in this directory.";
+ this->SetError(e.str().c_str());
+ return false;
+ }
+ }
+ else
{
test = this->Makefile->CreateTest(args[0].c_str());
+ test->SetOldStyle(true);
this->Makefile->AddTestGenerator(new cmTestGenerator(test));
}
test->SetCommand(command);
return true;
}
+
+//----------------------------------------------------------------------------
+bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
+{
+ std::string name;
+ std::vector<std::string> configurations;
+ std::vector<std::string> command;
+
+ // Read the arguments.
+ enum Doing {
+ DoingName,
+ DoingCommand,
+ DoingConfigs,
+ DoingNone
+ };
+ Doing doing = DoingName;
+ for(unsigned int i=1; i < args.size(); ++i)
+ {
+ if(args[i] == "COMMAND")
+ {
+ if(!command.empty())
+ {
+ this->SetError(" may be given at most one COMMAND.");
+ return false;
+ }
+ doing = DoingCommand;
+ }
+ else if(args[i] == "CONFIGURATIONS")
+ {
+ if(!configurations.empty())
+ {
+ this->SetError(" may be given at most one set of CONFIGURATIONS.");
+ return false;
+ }
+ doing = DoingConfigs;
+ }
+ else if(doing == DoingName)
+ {
+ name = args[i];
+ doing = DoingNone;
+ }
+ else if(doing == DoingCommand)
+ {
+ command.push_back(args[i]);
+ }
+ else if(doing == DoingConfigs)
+ {
+ configurations.push_back(args[i]);
+ }
+ else
+ {
+ cmOStringStream e;
+ e << " given unknown argument:\n " << args[i] << "\n";
+ this->SetError(e.str().c_str());
+ return false;
+ }
+ }
+
+ // Require a test name.
+ if(name.empty())
+ {
+ this->SetError(" must be given non-empty NAME.");
+ return false;
+ }
+
+ // Require a command.
+ if(command.empty())
+ {
+ this->SetError(" must be given non-empty COMMAND.");
+ return false;
+ }
+
+ // Require a unique test name within the directory.
+ if(this->Makefile->GetTest(name.c_str()))
+ {
+ cmOStringStream e;
+ e << " given test NAME \"" << name
+ << "\" which already exists in this directory.";
+ this->SetError(e.str().c_str());
+ return false;
+ }
+
+ // Add the test.
+ cmTest* test = this->Makefile->CreateTest(name.c_str());
+ test->SetOldStyle(false);
+ test->SetCommand(command);
+ this->Makefile->AddTestGenerator(new cmTestGenerator(test, configurations));
+
+ return true;
+}