Add WORKING_DIRECTORY argument to add_test

This commit is contained in:
Ben Boeckel 2010-12-16 16:48:27 -05:00
parent 7679f9fab0
commit 42de5d02dd
2 changed files with 20 additions and 0 deletions

View File

@ -74,6 +74,7 @@ bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
{
std::string name;
std::vector<std::string> configurations;
std::string working_directory;
std::vector<std::string> command;
// Read the arguments.
@ -81,6 +82,7 @@ bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
DoingName,
DoingCommand,
DoingConfigs,
DoingWorkingDirectory,
DoingNone
};
Doing doing = DoingName;
@ -104,6 +106,15 @@ bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
}
doing = DoingConfigs;
}
else if(args[i] == "WORKING_DIRECTORY")
{
if(!working_directory.empty())
{
this->SetError(" may be given at most one WORKING_DIRECTORY.");
return false;
}
doing = DoingWorkingDirectory;
}
else if(doing == DoingName)
{
name = args[i];
@ -117,6 +128,11 @@ bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
{
configurations.push_back(args[i]);
}
else if(doing == DoingWorkingDirectory)
{
working_directory = args[i];
doing = DoingNone;
}
else
{
cmOStringStream e;
@ -154,6 +170,7 @@ bool cmAddTestCommand::HandleNameMode(std::vector<std::string> const& args)
cmTest* test = this->Makefile->CreateTest(name.c_str());
test->SetOldStyle(false);
test->SetCommand(command);
test->SetProperty("WORKING_DIRECTORY", working_directory.c_str());
this->Makefile->AddTestGenerator(new cmTestGenerator(test, configurations));
return true;

View File

@ -68,12 +68,15 @@ public:
"in the binary tree.\n"
"\n"
" add_test(NAME <name> [CONFIGURATIONS [Debug|Release|...]]\n"
" [WORKING_DIRECTORY dir]\n"
" COMMAND <command> [arg1 [arg2 ...]])\n"
"If COMMAND specifies an executable target (created by "
"add_executable) it will automatically be replaced by the location "
"of the executable created at build time. "
"If a CONFIGURATIONS option is given then the test will be executed "
"only when testing under one of the named configurations."
"If a WORKING_DIRECTORY option is given then the test will be executed "
"in the given directory."
"\n"
"Arguments after COMMAND may use \"generator expressions\" with the "
"syntax \"$<...>\". "