2001-08-23 19:12:19 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "ctest.h"
|
2001-08-30 00:42:03 +04:00
|
|
|
#include "cmRegularExpression.h"
|
2001-08-23 19:12:19 +04:00
|
|
|
|
|
|
|
bool TryExecutable(const char *dir, const char *file,
|
|
|
|
std::string *fullPath, const char *subdir)
|
|
|
|
{
|
|
|
|
// try current directory
|
|
|
|
std::string tryPath;
|
|
|
|
if (dir && strcmp(dir,""))
|
|
|
|
{
|
|
|
|
tryPath = dir;
|
|
|
|
tryPath += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subdir && strcmp(subdir,""))
|
|
|
|
{
|
|
|
|
tryPath += subdir;
|
|
|
|
tryPath += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
tryPath += file;
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
*fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
*fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string ctest::FindExecutable(const char *exe)
|
|
|
|
{
|
|
|
|
std::string fullPath = "";
|
|
|
|
std::string dir;
|
|
|
|
std::string file;
|
|
|
|
|
|
|
|
cmSystemTools::SplitProgramPath(exe, dir, file);
|
|
|
|
|
|
|
|
if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
|
|
|
|
{
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
|
|
|
|
{
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
|
|
|
|
{
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
|
|
|
|
{
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
|
|
|
|
{
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
|
|
|
|
{
|
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
2001-08-23 21:12:13 +04:00
|
|
|
// if everything else failed, check the users path
|
|
|
|
if (dir != "")
|
|
|
|
{
|
|
|
|
std::string path = cmSystemTools::FindProgram(file.c_str());
|
|
|
|
if (path != "")
|
|
|
|
{
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-23 19:12:19 +04:00
|
|
|
return fullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ctest::ProcessDirectory(int &passed, int &failed)
|
|
|
|
{
|
|
|
|
// does the DartTestfile.txt exist ?
|
|
|
|
if(!cmSystemTools::FileExists("DartTestfile.txt"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the file
|
|
|
|
std::ifstream fin("DartTestfile.txt");
|
|
|
|
if(!fin)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::string> args;
|
2001-08-30 00:42:03 +04:00
|
|
|
cmRegularExpression var(this->m_RegExp.c_str());
|
2001-09-11 23:17:40 +04:00
|
|
|
cmRegularExpression dartStuff("([\t\n ]*<DartMeasurement.*/DartMeasurement[a-zA-Z]*>[\t ]*[\n]*)");
|
2001-08-30 00:42:03 +04:00
|
|
|
|
2001-11-30 00:44:22 +03:00
|
|
|
bool parseError;
|
2001-08-23 19:12:19 +04:00
|
|
|
while ( fin )
|
|
|
|
{
|
2001-11-30 00:44:22 +03:00
|
|
|
if(cmSystemTools::ParseFunction(fin, name, args, "DartTestfile.txt",
|
|
|
|
parseError))
|
2001-08-23 19:12:19 +04:00
|
|
|
{
|
|
|
|
if (name == "SUBDIRS")
|
|
|
|
{
|
|
|
|
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
|
|
|
|
for(std::vector<std::string>::iterator j = args.begin();
|
|
|
|
j != args.end(); ++j)
|
|
|
|
{
|
|
|
|
std::string nwd = cwd + "/";
|
|
|
|
nwd += *j;
|
|
|
|
if (cmSystemTools::FileIsDirectory(nwd.c_str()))
|
|
|
|
{
|
2001-08-24 00:00:46 +04:00
|
|
|
std::cerr << "Changing directory into " << nwd.c_str() << "\n";
|
2001-08-23 19:12:19 +04:00
|
|
|
cmSystemTools::ChangeDirectory(nwd.c_str());
|
|
|
|
this->ProcessDirectory(passed,failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
}
|
2001-08-30 00:42:03 +04:00
|
|
|
|
2001-08-23 19:12:19 +04:00
|
|
|
if (name == "ADD_TEST")
|
|
|
|
{
|
2001-08-30 00:42:03 +04:00
|
|
|
if (this->m_UseRegExp && !var.find(args[0].c_str()))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2001-08-27 18:23:45 +04:00
|
|
|
fprintf(stderr,"Testing %-30s ",args[0].c_str());
|
|
|
|
//std::cerr << "Testing " << args[0] << " ... ";
|
2001-08-23 19:12:19 +04:00
|
|
|
// find the test executable
|
2001-09-21 00:43:51 +04:00
|
|
|
std::string testCommand =
|
|
|
|
cmSystemTools::EscapeSpaces(this->FindExecutable(args[1].c_str()).c_str());
|
2001-12-03 23:55:28 +03:00
|
|
|
|
|
|
|
// continue if we did not find the executable
|
|
|
|
if (testCommand == "")
|
|
|
|
{
|
|
|
|
std::cerr << "Unable to find executable: " <<
|
|
|
|
args[1].c_str() << "\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-08-23 19:12:19 +04:00
|
|
|
// add the arguments
|
|
|
|
std::vector<std::string>::iterator j = args.begin();
|
|
|
|
++j;
|
|
|
|
++j;
|
|
|
|
for(;j != args.end(); ++j)
|
|
|
|
{
|
|
|
|
testCommand += " ";
|
2001-09-21 00:43:51 +04:00
|
|
|
testCommand += cmSystemTools::EscapeSpaces(j->c_str());
|
2001-08-23 19:12:19 +04:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Run an executable command and put the stdout in output.
|
|
|
|
*/
|
|
|
|
std::string output;
|
|
|
|
int retVal;
|
2001-09-11 23:17:40 +04:00
|
|
|
|
2001-08-23 19:12:19 +04:00
|
|
|
if (!cmSystemTools::RunCommand(testCommand.c_str(), output,
|
|
|
|
retVal, false) || retVal != 0)
|
|
|
|
{
|
2001-08-30 00:42:03 +04:00
|
|
|
fprintf(stderr,"***Failed\n");
|
2001-08-23 19:12:19 +04:00
|
|
|
if (output != "")
|
|
|
|
{
|
2001-09-11 23:17:40 +04:00
|
|
|
if (dartStuff.find(output.c_str()))
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(output,
|
|
|
|
dartStuff.match(1).c_str(),"");
|
|
|
|
}
|
|
|
|
if (output != "")
|
|
|
|
{
|
|
|
|
std::cerr << output.c_str() << "\n";
|
|
|
|
}
|
2001-08-23 19:12:19 +04:00
|
|
|
}
|
|
|
|
failed++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-30 00:42:03 +04:00
|
|
|
fprintf(stderr," Passed\n");
|
2001-08-23 19:12:19 +04:00
|
|
|
if (output != "")
|
|
|
|
{
|
2001-09-11 23:17:40 +04:00
|
|
|
if (dartStuff.find(output.c_str()))
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(output,
|
|
|
|
dartStuff.match(1).c_str(),"");
|
|
|
|
}
|
|
|
|
if (output != "")
|
|
|
|
{
|
|
|
|
std::cerr << output.c_str() << "\n";
|
|
|
|
}
|
2001-08-23 19:12:19 +04:00
|
|
|
}
|
|
|
|
passed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// this is a test driver program for cmake.
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int passed = 0;
|
|
|
|
int failed = 0;
|
|
|
|
int total;
|
|
|
|
|
|
|
|
ctest inst;
|
|
|
|
|
2001-08-30 00:42:03 +04:00
|
|
|
// look at the args
|
|
|
|
std::vector<std::string> args;
|
|
|
|
for(int i =0; i < argc; ++i)
|
|
|
|
{
|
|
|
|
args.push_back(argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int i=1; i < args.size(); ++i)
|
|
|
|
{
|
|
|
|
std::string arg = args[i];
|
|
|
|
if(arg.find("-R",0) == 0 && i < args.size() - 1)
|
|
|
|
{
|
|
|
|
inst.m_UseRegExp = true;
|
|
|
|
inst.m_RegExp = args[i+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-23 19:12:19 +04:00
|
|
|
// call process directory
|
|
|
|
inst.ProcessDirectory(passed, failed);
|
|
|
|
total = passed + failed;
|
|
|
|
|
|
|
|
if (total == 0)
|
|
|
|
{
|
|
|
|
std::cerr << "No tests were found!!!\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float percent = passed * 100.0 / total;
|
2001-08-23 19:39:21 +04:00
|
|
|
fprintf(stderr,"%.0f%% tests passed, %i tests failed out of %i\n",
|
2001-08-23 19:12:19 +04:00
|
|
|
percent,failed, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
return failed;
|
|
|
|
}
|