2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-06-06 04:32:33 +04:00
|
|
|
#include "cmAddTestCommand.h"
|
|
|
|
|
2009-03-16 17:40:46 +03:00
|
|
|
#include "cmTestGenerator.h"
|
|
|
|
|
2005-04-24 23:59:51 +04:00
|
|
|
#include "cmTest.h"
|
|
|
|
|
2001-06-06 04:32:33 +04:00
|
|
|
// cmExecutableCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmAddTestCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-06-06 04:32:33 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!args.empty() && args[0] == "NAME") {
|
2009-03-16 17:51:30 +03:00
|
|
|
return this->HandleNameMode(args);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-16 17:51:30 +03:00
|
|
|
|
2006-05-10 21:50:44 +04:00
|
|
|
// 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
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < 2) {
|
2001-06-06 04:32:33 +04:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2002-02-26 19:46:01 +03:00
|
|
|
|
2009-03-16 17:42:40 +03:00
|
|
|
// Collect the command with arguments.
|
|
|
|
std::vector<std::string> command;
|
2014-11-22 13:00:45 +03:00
|
|
|
command.insert(command.end(), args.begin() + 1, args.end());
|
2001-06-06 21:58:18 +04:00
|
|
|
|
2009-03-16 17:40:46 +03:00
|
|
|
// Create the test but add a generator only the first time it is
|
|
|
|
// seen. This preserves behavior from before test generators.
|
2014-03-11 03:04:11 +04:00
|
|
|
cmTest* test = this->Makefile->GetTest(args[0]);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (test) {
|
2009-03-16 17:51:30 +03:00
|
|
|
// If the test was already added by a new-style signature do not
|
|
|
|
// allow it to be duplicated.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!test->GetOldStyle()) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-03-16 17:51:30 +03:00
|
|
|
e << " given test name \"" << args[0]
|
|
|
|
<< "\" which already exists in this directory.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2009-03-16 17:51:30 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-03-11 03:04:11 +04:00
|
|
|
test = this->Makefile->CreateTest(args[0]);
|
2009-03-16 17:51:30 +03:00
|
|
|
test->SetOldStyle(true);
|
2009-03-16 17:40:46 +03:00
|
|
|
this->Makefile->AddTestGenerator(new cmTestGenerator(test));
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-16 17:42:40 +03:00
|
|
|
test->SetCommand(command);
|
2001-06-06 21:58:18 +04:00
|
|
|
|
2005-04-24 23:59:51 +04:00
|
|
|
return true;
|
2001-06-06 04:32:33 +04:00
|
|
|
}
|
2009-03-16 17:51:30 +03:00
|
|
|
|
|
|
|
bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::string> configurations;
|
2011-01-20 22:05:39 +03:00
|
|
|
std::string working_directory;
|
2009-03-16 17:51:30 +03:00
|
|
|
std::vector<std::string> command;
|
|
|
|
|
|
|
|
// Read the arguments.
|
2016-05-16 17:34:04 +03:00
|
|
|
enum Doing
|
|
|
|
{
|
2009-03-16 17:51:30 +03:00
|
|
|
DoingName,
|
|
|
|
DoingCommand,
|
|
|
|
DoingConfigs,
|
2010-12-17 00:48:27 +03:00
|
|
|
DoingWorkingDirectory,
|
2009-03-16 17:51:30 +03:00
|
|
|
DoingNone
|
|
|
|
};
|
|
|
|
Doing doing = DoingName;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 1; i < args.size(); ++i) {
|
|
|
|
if (args[i] == "COMMAND") {
|
|
|
|
if (!command.empty()) {
|
2009-03-16 17:51:30 +03:00
|
|
|
this->SetError(" may be given at most one COMMAND.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
doing = DoingCommand;
|
|
|
|
} else if (args[i] == "CONFIGURATIONS") {
|
|
|
|
if (!configurations.empty()) {
|
2009-03-16 17:51:30 +03:00
|
|
|
this->SetError(" may be given at most one set of CONFIGURATIONS.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
doing = DoingConfigs;
|
|
|
|
} else if (args[i] == "WORKING_DIRECTORY") {
|
|
|
|
if (!working_directory.empty()) {
|
2010-12-17 00:48:27 +03:00
|
|
|
this->SetError(" may be given at most one WORKING_DIRECTORY.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
doing = DoingWorkingDirectory;
|
|
|
|
} else if (doing == DoingName) {
|
2009-03-16 17:51:30 +03:00
|
|
|
name = args[i];
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingCommand) {
|
2009-03-16 17:51:30 +03:00
|
|
|
command.push_back(args[i]);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingConfigs) {
|
2009-03-16 17:51:30 +03:00
|
|
|
configurations.push_back(args[i]);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing == DoingWorkingDirectory) {
|
2010-12-17 00:48:27 +03:00
|
|
|
working_directory = args[i];
|
|
|
|
doing = DoingNone;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-03-16 17:51:30 +03:00
|
|
|
e << " given unknown argument:\n " << args[i] << "\n";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2009-03-16 17:51:30 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-16 17:51:30 +03:00
|
|
|
|
|
|
|
// Require a test name.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.empty()) {
|
2009-03-16 17:51:30 +03:00
|
|
|
this->SetError(" must be given non-empty NAME.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-16 17:51:30 +03:00
|
|
|
|
|
|
|
// Require a command.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (command.empty()) {
|
2009-03-16 17:51:30 +03:00
|
|
|
this->SetError(" must be given non-empty COMMAND.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-16 17:51:30 +03:00
|
|
|
|
|
|
|
// Require a unique test name within the directory.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->GetTest(name)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2009-03-16 17:51:30 +03:00
|
|
|
e << " given test NAME \"" << name
|
|
|
|
<< "\" which already exists in this directory.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2009-03-16 17:51:30 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-16 17:51:30 +03:00
|
|
|
|
|
|
|
// Add the test.
|
2014-03-11 03:04:11 +04:00
|
|
|
cmTest* test = this->Makefile->CreateTest(name);
|
2009-03-16 17:51:30 +03:00
|
|
|
test->SetOldStyle(false);
|
|
|
|
test->SetCommand(command);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!working_directory.empty()) {
|
2011-01-20 22:05:39 +03:00
|
|
|
test->SetProperty("WORKING_DIRECTORY", working_directory.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-03-16 17:51:30 +03:00
|
|
|
this->Makefile->AddTestGenerator(new cmTestGenerator(test, configurations));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|