2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-06-06 00:32:33 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-06-06 00:32:33 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-06-06 00:32:33 +00:00
|
|
|
#include "cmAddTestCommand.h"
|
|
|
|
|
2009-03-16 14:40:46 +00:00
|
|
|
#include "cmTestGenerator.h"
|
|
|
|
|
2005-04-24 19:59:51 +00:00
|
|
|
#include "cmTest.h"
|
|
|
|
|
|
|
|
|
2001-06-06 00:32:33 +00:00
|
|
|
// cmExecutableCommand
|
2008-01-23 15:28:26 +00:00
|
|
|
bool cmAddTestCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2001-06-06 00:32:33 +00:00
|
|
|
{
|
2009-03-16 14:51:30 +00:00
|
|
|
if(!args.empty() && args[0] == "NAME")
|
|
|
|
{
|
|
|
|
return this->HandleNameMode(args);
|
|
|
|
}
|
|
|
|
|
2006-05-10 17:50:44 +00: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
|
2001-06-06 00:32:33 +00:00
|
|
|
if(args.size() < 2 )
|
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2002-02-26 16:46:01 +00:00
|
|
|
|
2009-03-16 14:42:40 +00:00
|
|
|
// Collect the command with arguments.
|
|
|
|
std::vector<std::string> command;
|
|
|
|
for(std::vector<std::string>::const_iterator it = args.begin() + 1;
|
|
|
|
it != args.end(); ++it)
|
2005-04-24 20:19:54 +00:00
|
|
|
{
|
2009-03-16 14:42:40 +00:00
|
|
|
command.push_back(*it);
|
2005-04-24 20:19:54 +00:00
|
|
|
}
|
2001-06-06 17:58:18 +00:00
|
|
|
|
2009-03-16 14:40:46 +00:00
|
|
|
// 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());
|
2009-03-16 14:51:30 +00:00
|
|
|
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
|
2009-03-16 14:40:46 +00:00
|
|
|
{
|
|
|
|
test = this->Makefile->CreateTest(args[0].c_str());
|
2009-03-16 14:51:30 +00:00
|
|
|
test->SetOldStyle(true);
|
2009-03-16 14:40:46 +00:00
|
|
|
this->Makefile->AddTestGenerator(new cmTestGenerator(test));
|
|
|
|
}
|
2009-03-16 14:42:40 +00:00
|
|
|
test->SetCommand(command);
|
2001-06-06 17:58:18 +00:00
|
|
|
|
2005-04-24 19:59:51 +00:00
|
|
|
return true;
|
2001-06-06 00:32:33 +00:00
|
|
|
}
|
2009-03-16 14:51:30 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
}
|