ENH: Using cmListFileCache to read the DartTestfile instead of duplicating the parse loop.

This commit is contained in:
Brad King 2003-12-05 16:39:14 -05:00
parent bcfd5ce161
commit 21c5c6c81d

View File

@ -1650,151 +1650,147 @@ void cmCTest::ProcessDirectory(std::vector<std::string> &passed,
} }
int firstTest = 1; int firstTest = 1;
long line = 0;
#define SPACE_REGEX "[ \t\r\n]"
cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str()); cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str()); cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)"); cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
bool parseError; cmListFileCache cache;
while ( fin ) cmListFile* listFile = cache.GetFileCache("DartTestfile.txt", false);
for(std::vector<cmListFileFunction>::const_iterator f =
listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
{ {
cmListFileFunction lff; const cmListFileFunction& lff = *f;
if(cmListFileCache::ParseFunction(fin, lff, "DartTestfile.txt", const std::string& name = lff.m_Name;
parseError, line)) const std::vector<cmListFileArgument>& args = lff.m_Arguments;
if (name == "SUBDIRS")
{ {
const std::string& name = lff.m_Name; std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
const std::vector<cmListFileArgument>& args = lff.m_Arguments; for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
if (name == "SUBDIRS") j != args.end(); ++j)
{ {
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); std::string nwd = cwd + "/";
for(std::vector<cmListFileArgument>::const_iterator j = args.begin(); nwd += j->Value;
j != args.end(); ++j) if (cmSystemTools::FileIsDirectory(nwd.c_str()))
{ {
std::string nwd = cwd + "/"; cmSystemTools::ChangeDirectory(nwd.c_str());
nwd += j->Value; this->ProcessDirectory(passed, failed);
if (cmSystemTools::FileIsDirectory(nwd.c_str()))
{
cmSystemTools::ChangeDirectory(nwd.c_str());
this->ProcessDirectory(passed, failed);
}
} }
// return to the original directory
cmSystemTools::ChangeDirectory(cwd.c_str());
} }
// return to the original directory
if (name == "ADD_TEST") cmSystemTools::ChangeDirectory(cwd.c_str());
}
if (name == "ADD_TEST")
{
if (this->m_UseExcludeRegExp &&
this->m_UseExcludeRegExpFirst &&
ereg.find(args[0].Value.c_str()))
{ {
if (this->m_UseExcludeRegExp && continue;
this->m_UseExcludeRegExpFirst && }
ereg.find(args[0].Value.c_str())) if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
{ {
continue; continue;
} }
if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str())) if (this->m_UseExcludeRegExp &&
{ !this->m_UseExcludeRegExpFirst &&
continue; ereg.find(args[0].Value.c_str()))
} {
if (this->m_UseExcludeRegExp && continue;
!this->m_UseExcludeRegExpFirst && }
ereg.find(args[0].Value.c_str()))
{
continue;
}
cmCTestTestResult cres; cmCTestTestResult cres;
cres.m_Status = cmCTest::NOT_RUN; cres.m_Status = cmCTest::NOT_RUN;
if (firstTest) if (firstTest)
{
std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
std::cerr << "Changing directory into " << nwd.c_str() << "\n";
firstTest = 0;
}
cres.m_Name = args[0].Value;
if ( m_ShowOnly )
{
std::cout << args[0].Value << std::endl;
}
else
{
fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
fflush(stderr);
}
//std::cerr << "Testing " << args[0] << " ... ";
// find the test executable
std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
// continue if we did not find the executable
if (testCommand == "")
{
std::cerr << "Unable to find executable: " <<
args[1].Value.c_str() << "\n";
m_TestResults.push_back( cres );
continue;
}
// add the arguments
std::vector<cmListFileArgument>::const_iterator j = args.begin();
++j;
++j;
std::vector<const char*> arguments;
arguments.push_back(actualCommand.c_str());
for(;j != args.end(); ++j)
{
testCommand += " ";
testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
arguments.push_back(j->Value.c_str());
}
arguments.push_back(0);
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
int retVal = 0;
double clock_start, clock_finish;
clock_start = cmSystemTools::GetTime();
if ( m_Verbose )
{
std::cout << std::endl << "Test command: " << testCommand << std::endl;
}
int res = 0;
if ( !m_ShowOnly )
{
res = this->RunTest(arguments, &output, &retVal);
}
clock_finish = cmSystemTools::GetTime();
cres.m_ExecutionTime = (double)(clock_finish - clock_start);
cres.m_FullCommandLine = testCommand;
if ( !m_ShowOnly )
{
if (res == cmsysProcess_State_Exited && retVal == 0)
{ {
std::string nwd = cmSystemTools::GetCurrentWorkingDirectory(); fprintf(stderr," Passed\n");
std::cerr << "Changing directory into " << nwd.c_str() << "\n"; passed.push_back(args[0].Value);
firstTest = 0; cres.m_Status = cmCTest::COMPLETED;
}
cres.m_Name = args[0].Value;
if ( m_ShowOnly )
{
std::cout << args[0].Value << std::endl;
} }
else else
{ {
fprintf(stderr,"Testing %-30s ",args[0].Value.c_str()); cres.m_Status = cmCTest::FAILED;
fflush(stderr); if ( res == cmsysProcess_State_Expired )
}
//std::cerr << "Testing " << args[0] << " ... ";
// find the test executable
std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
// continue if we did not find the executable
if (testCommand == "")
{
std::cerr << "Unable to find executable: " <<
args[1].Value.c_str() << "\n";
m_TestResults.push_back( cres );
continue;
}
// add the arguments
std::vector<cmListFileArgument>::const_iterator j = args.begin();
++j;
++j;
std::vector<const char*> arguments;
arguments.push_back(actualCommand.c_str());
for(;j != args.end(); ++j)
{
testCommand += " ";
testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
arguments.push_back(j->Value.c_str());
}
arguments.push_back(0);
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
int retVal = 0;
double clock_start, clock_finish;
clock_start = cmSystemTools::GetTime();
if ( m_Verbose )
{
std::cout << std::endl << "Test command: " << testCommand << std::endl;
}
int res = 0;
if ( !m_ShowOnly )
{
res = this->RunTest(arguments, &output, &retVal);
}
clock_finish = cmSystemTools::GetTime();
cres.m_ExecutionTime = (double)(clock_finish - clock_start);
cres.m_FullCommandLine = testCommand;
if ( !m_ShowOnly )
{
if (res == cmsysProcess_State_Exited && retVal == 0)
{ {
fprintf(stderr," Passed\n"); fprintf(stderr,"***Timeout\n");
passed.push_back(args[0].Value); cres.m_Status = cmCTest::TIMEOUT;
cres.m_Status = cmCTest::COMPLETED;
} }
else else if ( res == cmsysProcess_State_Exception )
{ {
cres.m_Status = cmCTest::FAILED; fprintf(stderr,"***Exception: ");
if ( res == cmsysProcess_State_Expired ) switch ( retVal )
{ {
fprintf(stderr,"***Timeout\n");
cres.m_Status = cmCTest::TIMEOUT;
}
else if ( res == cmsysProcess_State_Exception )
{
fprintf(stderr,"***Exception: ");
switch ( retVal )
{
case cmsysProcess_Exception_Fault: case cmsysProcess_Exception_Fault:
fprintf(stderr,"SegFault"); fprintf(stderr,"SegFault");
cres.m_Status = cmCTest::SEGFAULT; cres.m_Status = cmCTest::SEGFAULT;
@ -1814,42 +1810,41 @@ void cmCTest::ProcessDirectory(std::vector<std::string> &passed,
default: default:
fprintf(stderr,"Other"); fprintf(stderr,"Other");
cres.m_Status = cmCTest::OTHER_FAULT; cres.m_Status = cmCTest::OTHER_FAULT;
}
fprintf(stderr,"\n");
} }
else if ( res == cmsysProcess_State_Error ) fprintf(stderr,"\n");
{
fprintf(stderr,"***Bad command\n");
cres.m_Status = cmCTest::BAD_COMMAND;
}
else
{
fprintf(stderr,"***Failed\n");
}
failed.push_back(args[0].Value);
} }
if (output != "") else if ( res == cmsysProcess_State_Error )
{ {
if (dartStuff.find(output.c_str())) fprintf(stderr,"***Bad command\n");
{ cres.m_Status = cmCTest::BAD_COMMAND;
std::string dartString = dartStuff.match(1); }
cmSystemTools::ReplaceString(output, dartString.c_str(),""); else
cres.m_RegressionImages = this->GenerateRegressionImages(dartString); {
} fprintf(stderr,"***Failed\n");
}
failed.push_back(args[0].Value);
}
if (output != "")
{
if (dartStuff.find(output.c_str()))
{
std::string dartString = dartStuff.match(1);
cmSystemTools::ReplaceString(output, dartString.c_str(),"");
cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
} }
} }
cres.m_Output = output;
cres.m_ReturnValue = retVal;
std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
if ( nwd.size() > m_ToplevelPath.size() )
{
nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
}
cmSystemTools::ReplaceString(nwd, "\\", "/");
cres.m_Path = nwd;
cres.m_CompletionStatus = "Completed";
m_TestResults.push_back( cres );
} }
cres.m_Output = output;
cres.m_ReturnValue = retVal;
std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
if ( nwd.size() > m_ToplevelPath.size() )
{
nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
}
cmSystemTools::ReplaceString(nwd, "\\", "/");
cres.m_Path = nwd;
cres.m_CompletionStatus = "Completed";
m_TestResults.push_back( cres );
} }
} }
} }
@ -2193,6 +2188,8 @@ std::string cmCTest::GetTestModelString()
return "Experimental"; return "Experimental";
} }
#define SPACE_REGEX "[ \t\r\n]"
std::string cmCTest::GenerateRegressionImages(const std::string& xml) std::string cmCTest::GenerateRegressionImages(const std::string& xml)
{ {
cmsys::RegularExpression twoattributes( cmsys::RegularExpression twoattributes(