Unfortunately, I noticed the comment on bug 8668 too late. This changes my last implementation of the exe wrapper to something which makes much more sense: a REQUIRED_FILES property on tests.
This commit is contained in:
parent
48b6133928
commit
4de7cc3621
|
@ -26,8 +26,6 @@ cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
|
|||
this->TestResult.Status = 0;
|
||||
this->TestResult.TestCount = 0;
|
||||
this->TestResult.Properties = 0;
|
||||
this->PrefixCommand = "";
|
||||
this->UsePrefixCommand = false;
|
||||
}
|
||||
|
||||
cmCTestRunTest::~cmCTestRunTest()
|
||||
|
@ -305,7 +303,6 @@ bool cmCTestRunTest::StartTest(size_t total)
|
|||
<< this->TestProperties->Name << std::endl);
|
||||
this->ComputeArguments();
|
||||
std::vector<std::string>& args = this->TestProperties->Args;
|
||||
std::vector<std::string>& pargs = this->TestProperties->PrefixArgs;
|
||||
this->TestResult.Properties = this->TestProperties;
|
||||
this->TestResult.ExecutionTime = 0;
|
||||
this->TestResult.ReturnValue = -1;
|
||||
|
@ -315,17 +312,42 @@ bool cmCTestRunTest::StartTest(size_t total)
|
|||
this->TestResult.Name = this->TestProperties->Name;
|
||||
this->TestResult.Path = this->TestProperties->Directory.c_str();
|
||||
|
||||
// if we are using a prefix command, make sure THAT executable exists
|
||||
if (this->UsePrefixCommand && this->PrefixCommand == "")
|
||||
// Check if all required files exist
|
||||
for(std::vector<std::string>::iterator i =
|
||||
this->TestProperties->RequiredFiles.begin();
|
||||
i != this->TestProperties->RequiredFiles.end(); ++i)
|
||||
{
|
||||
this->ExeNotFound(pargs[0]);
|
||||
std::string file = *i;
|
||||
|
||||
if(!cmSystemTools::FileExists(file.c_str()))
|
||||
{
|
||||
//Required file was not found
|
||||
this->TestProcess = new cmProcess;
|
||||
*this->TestHandler->LogFile << "Unable to find required file: "
|
||||
<< file.c_str() << std::endl;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find required file: "
|
||||
<< file.c_str() << std::endl);
|
||||
this->TestResult.Output = "Unable to find required file: " + file;
|
||||
this->TestResult.FullCommandLine = "";
|
||||
this->TestResult.CompletionStatus = "Not Run";
|
||||
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
// log and return if we did not find the executable
|
||||
if (this->ActualCommand == "")
|
||||
{
|
||||
this->ExeNotFound(args[1]);
|
||||
// if the command was not found create a TestResult object
|
||||
// that has that information
|
||||
this->TestProcess = new cmProcess;
|
||||
*this->TestHandler->LogFile << "Unable to find executable: "
|
||||
<< args[1].c_str() << std::endl;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
|
||||
<< args[1].c_str() << std::endl);
|
||||
this->TestResult.Output = "Unable to find executable: " + args[1];
|
||||
this->TestResult.FullCommandLine = "";
|
||||
this->TestResult.CompletionStatus = "Not Run";
|
||||
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
||||
return false;
|
||||
}
|
||||
this->StartTime = this->CTest->CurrentTime();
|
||||
|
@ -334,36 +356,12 @@ bool cmCTestRunTest::StartTest(size_t total)
|
|||
&this->TestProperties->Environment);
|
||||
}
|
||||
|
||||
void cmCTestRunTest::ExeNotFound(std::string exe)
|
||||
{
|
||||
this->TestProcess = new cmProcess;
|
||||
*this->TestHandler->LogFile << "Unable to find executable: "
|
||||
<< exe.c_str() << std::endl;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
|
||||
<< exe.c_str() << std::endl);
|
||||
this->TestResult.Output = "Unable to find executable: " + exe;
|
||||
this->TestResult.FullCommandLine = "";
|
||||
this->TestResult.CompletionStatus = "Not Run";
|
||||
this->TestResult.Reason = "";
|
||||
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
||||
}
|
||||
|
||||
void cmCTestRunTest::ComputeArguments()
|
||||
{
|
||||
std::vector<std::string>::const_iterator j =
|
||||
this->TestProperties->Args.begin();
|
||||
++j; // skip test name
|
||||
|
||||
this->TestCommand = "";
|
||||
|
||||
//If we are using a prefix command, find the exe for it
|
||||
if(this->TestProperties->PrefixArgs.size())
|
||||
{
|
||||
this->UsePrefixCommand = true;
|
||||
this->PrefixCommand = this->TestHandler->FindTheExecutable(
|
||||
this->TestProperties->PrefixArgs[0].c_str());
|
||||
}
|
||||
|
||||
// find the test executable
|
||||
if(this->TestHandler->MemCheck)
|
||||
{
|
||||
|
@ -378,6 +376,8 @@ void cmCTestRunTest::ComputeArguments()
|
|||
this->TestProperties->Args[1].c_str());
|
||||
++j; //skip the executable (it will be actualCommand)
|
||||
}
|
||||
this->TestCommand
|
||||
= cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
|
||||
|
||||
//Prepends memcheck args to our command string
|
||||
this->TestHandler->GenerateTestCommand(this->Arguments);
|
||||
|
@ -387,27 +387,6 @@ void cmCTestRunTest::ComputeArguments()
|
|||
this->TestCommand += " ";
|
||||
this->TestCommand += cmSystemTools::EscapeSpaces(j->c_str());
|
||||
}
|
||||
//Add user specified prefix args
|
||||
if(this->UsePrefixCommand)
|
||||
{
|
||||
this->TestCommand +=
|
||||
cmSystemTools::ConvertToOutputPath(this->PrefixCommand.c_str());
|
||||
|
||||
std::vector<std::string>::iterator i =
|
||||
this->TestProperties->PrefixArgs.begin();
|
||||
++i; //skip the exe name
|
||||
for(; i != this->TestProperties->PrefixArgs.end(); ++i)
|
||||
{
|
||||
this->TestCommand += " ";
|
||||
this->TestCommand += cmSystemTools::EscapeSpaces(i->c_str());
|
||||
this->Arguments.push_back(*i);
|
||||
}
|
||||
this->Arguments.push_back(this->ActualCommand);
|
||||
this->TestCommand += " ";
|
||||
}
|
||||
//Add regular test args
|
||||
this->TestCommand
|
||||
+= cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
|
||||
|
||||
for(;j != this->TestProperties->Args.end(); ++j)
|
||||
{
|
||||
|
@ -454,9 +433,7 @@ bool cmCTestRunTest::CreateProcess(double testTimeOut,
|
|||
this->TestProcess->SetId(this->Index);
|
||||
this->TestProcess->SetWorkingDirectory(
|
||||
this->TestProperties->Directory.c_str());
|
||||
this->TestProcess->SetCommand(this->UsePrefixCommand ?
|
||||
this->PrefixCommand.c_str() :
|
||||
this->ActualCommand.c_str());
|
||||
this->TestProcess->SetCommand(this->ActualCommand.c_str());
|
||||
this->TestProcess->SetCommandArguments(this->Arguments);
|
||||
|
||||
std::vector<std::string> origEnv;
|
||||
|
|
|
@ -269,30 +269,7 @@ bool cmCTestAddTestCommand
|
|||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool prefixCmdFound = false;
|
||||
std::vector<std::string> actualArgs, prefix;
|
||||
|
||||
//separate the regular command and the prefix command (bug 8668)
|
||||
for(std::vector<std::string>::const_iterator i = args.begin();
|
||||
i != args.end(); ++i)
|
||||
{
|
||||
if(*i == "EXEC_PREFIX_CMD")
|
||||
{
|
||||
prefixCmdFound = true;
|
||||
continue;
|
||||
}
|
||||
if(prefixCmdFound)
|
||||
{
|
||||
prefix.push_back(*i);
|
||||
}
|
||||
else
|
||||
{
|
||||
actualArgs.push_back(*i);
|
||||
}
|
||||
}
|
||||
|
||||
return this->TestHandler->AddTest(actualArgs, prefix);
|
||||
return this->TestHandler->AddTest(args);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -2036,6 +2013,10 @@ bool cmCTestTestHandler::SetTestsProperties(
|
|||
{
|
||||
rtit->Cost = static_cast<float>(atof(val.c_str()));
|
||||
}
|
||||
if ( key == "REQUIRED_FILE" )
|
||||
{
|
||||
rtit->RequiredFiles.push_back(val);
|
||||
}
|
||||
if ( key == "RUN_SERIAL" )
|
||||
{
|
||||
rtit->RunSerial = cmSystemTools::IsOn(val.c_str());
|
||||
|
@ -2127,8 +2108,7 @@ bool cmCTestTestHandler::SetTestsProperties(
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args,
|
||||
const std::vector<std::string>& prefix)
|
||||
bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
|
||||
{
|
||||
const std::string& testname = args[0];
|
||||
cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
|
||||
|
@ -2183,7 +2163,6 @@ bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args,
|
|||
cmCTestTestProperties test;
|
||||
test.Name = testname;
|
||||
test.Args = args;
|
||||
test.PrefixArgs = prefix;
|
||||
test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
|
||||
cmCTestLog(this->CTest, DEBUG, "Set test directory: "
|
||||
<< test.Directory << std::endl);
|
||||
|
|
|
@ -66,8 +66,7 @@ public:
|
|||
/*
|
||||
* Add the test to the list of tests to be executed
|
||||
*/
|
||||
bool AddTest(const std::vector<std::string>& args,
|
||||
const std::vector<std::string>& prefix);
|
||||
bool AddTest(const std::vector<std::string>& args);
|
||||
|
||||
/*
|
||||
* Set tests properties
|
||||
|
@ -85,7 +84,7 @@ public:
|
|||
cmStdString Name;
|
||||
cmStdString Directory;
|
||||
std::vector<std::string> Args;
|
||||
std::vector<std::string> PrefixArgs;
|
||||
std::vector<std::string> RequiredFiles;
|
||||
std::vector<std::string> Depends;
|
||||
std::vector<std::pair<cmsys::RegularExpression,
|
||||
std::string> > ErrorRegularExpressions;
|
||||
|
|
|
@ -56,8 +56,7 @@ public:
|
|||
virtual const char* GetFullDocumentation()
|
||||
{
|
||||
return
|
||||
" add_test(testname Exename arg1 arg2 ... \n"
|
||||
" [EXEC_PREFIX_CMD wrapperExe args...])\n"
|
||||
" add_test(testname Exename arg1 arg2 ... )\n"
|
||||
"If the ENABLE_TESTING command has been run, this command adds a "
|
||||
"test target to the current directory. If ENABLE_TESTING has not "
|
||||
"been run, this command does nothing. "
|
||||
|
@ -67,9 +66,6 @@ public:
|
|||
"system (like tclsh). The test will be run with the current working "
|
||||
"directory set to the CMakeList.txt files corresponding directory "
|
||||
"in the binary tree.\n"
|
||||
"Use EXEC_PREFIX_CMD to wrap an executable built by this project "
|
||||
"in another executable such as mpiexec. This will only run the "
|
||||
"test if the wrapped executable was built."
|
||||
"\n"
|
||||
" add_test(NAME <name> [CONFIGURATIONS [Debug|Release|...]]\n"
|
||||
" COMMAND <command> [arg1 [arg2 ...]])\n"
|
||||
|
|
|
@ -73,7 +73,9 @@ public:
|
|||
"seconds specified.\n"
|
||||
"RUN_SERIAL: If set to true, this test will not run in parallel with "
|
||||
"any other tests. This should be used in conjunction with "
|
||||
"the ctest_test PARALLEL_LEVEL option.\n";
|
||||
"the ctest_test PARALLEL_LEVEL option.\n"
|
||||
"REQUIRED_FILE: Set this to a file that must exist in order for the "
|
||||
"test to be run.\n";
|
||||
}
|
||||
|
||||
cmTypeMacro(cmSetTestsPropertiesCommand, cmCommand);
|
||||
|
|
Loading…
Reference in New Issue