ENH: now supports tests inside sub-dirs
This commit is contained in:
parent
9c4922b3af
commit
a5b833119d
|
@ -25,18 +25,25 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
this->SetError("called with wrong number of arguments.");
|
this->SetError("called with wrong number of arguments.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
cmSystemTools::ExpandListArguments(argsIn, args);
|
cmSystemTools::ExpandListArguments(argsIn, args, true);
|
||||||
|
|
||||||
std::vector<std::string>::iterator i = args.begin();
|
std::vector<std::string>::iterator i = args.begin();
|
||||||
|
|
||||||
|
// Name of the source list
|
||||||
|
|
||||||
const char* sourceList = i->c_str();
|
const char* sourceList = i->c_str();
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
|
// Name of the test driver
|
||||||
|
|
||||||
std::string driver = m_Makefile->GetCurrentOutputDirectory();
|
std::string driver = m_Makefile->GetCurrentOutputDirectory();
|
||||||
driver += "/";
|
driver += "/";
|
||||||
driver += *i;
|
driver += *i;
|
||||||
driver += ".cxx";
|
driver += ".cxx";
|
||||||
++i;
|
++i;
|
||||||
std::vector<std::string>::iterator testsBegin = i;
|
|
||||||
std::ofstream fout(driver.c_str());
|
std::ofstream fout(driver.c_str());
|
||||||
if(!fout)
|
if(!fout)
|
||||||
{
|
{
|
||||||
|
@ -46,14 +53,33 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
this->SetError(err.c_str());
|
this->SetError(err.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the test driver file
|
// Create the test driver file
|
||||||
|
|
||||||
fout << "#include <stdio.h>\n";
|
fout << "#include <stdio.h>\n";
|
||||||
fout << "#include <string.h>\n";
|
fout << "#include <string.h>\n";
|
||||||
fout << "// forward declare test functions\n";
|
fout << "// forward declare test functions\n";
|
||||||
|
|
||||||
|
std::vector<std::string>::iterator testsBegin = i;
|
||||||
|
std::vector<std::string> tests_filename;
|
||||||
|
|
||||||
|
// The rest of the arguments consist of a list of test source files.
|
||||||
|
// Sadly, they can be in directories. Let's modify each arg to get
|
||||||
|
// a unique function name for the corresponding test, and push the
|
||||||
|
// real source filename to the tests_filename var (used at the end).
|
||||||
|
// For the moment:
|
||||||
|
// - replace spaces ' ', ':' and '/' with underscores '_'
|
||||||
|
|
||||||
for(i = testsBegin; i != args.end(); ++i)
|
for(i = testsBegin; i != args.end(); ++i)
|
||||||
{
|
{
|
||||||
|
tests_filename.push_back(*i);
|
||||||
|
cmSystemTools::ConvertToUnixSlashes(*i);
|
||||||
|
cmSystemTools::ReplaceString(*i, " ", "_");
|
||||||
|
cmSystemTools::ReplaceString(*i, "/", "_");
|
||||||
|
cmSystemTools::ReplaceString(*i, ":", "_");
|
||||||
fout << "int " << *i << "(int, char**);\n";
|
fout << "int " << *i << "(int, char**);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
fout << "// Create map \n";
|
fout << "// Create map \n";
|
||||||
fout << "typedef int (*MainFuncPointer)(int , char**);\n";
|
fout << "typedef int (*MainFuncPointer)(int , char**);\n";
|
||||||
fout << "struct functionMapEntry\n"
|
fout << "struct functionMapEntry\n"
|
||||||
|
@ -62,12 +88,14 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
<< "MainFuncPointer func;\n"
|
<< "MainFuncPointer func;\n"
|
||||||
<< "};\n\n";
|
<< "};\n\n";
|
||||||
fout << "functionMapEntry cmakeGeneratedFunctionMapEntries[] = {\n";
|
fout << "functionMapEntry cmakeGeneratedFunctionMapEntries[] = {\n";
|
||||||
|
|
||||||
int numTests = 0;
|
int numTests = 0;
|
||||||
for(i = testsBegin; i != args.end(); ++i)
|
for(i = testsBegin; i != args.end(); ++i)
|
||||||
{
|
{
|
||||||
fout << "{\"" << *i << "\", " << *i << "},\n";
|
fout << "{\"" << *i << "\", " << *i << "},\n";
|
||||||
numTests++;
|
numTests++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fout << "};\n";
|
fout << "};\n";
|
||||||
fout << "int main(int ac, char** av)\n"
|
fout << "int main(int ac, char** av)\n"
|
||||||
<< "{\n";
|
<< "{\n";
|
||||||
|
@ -112,19 +140,25 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
fout << " return -1;\n";
|
fout << " return -1;\n";
|
||||||
fout << "}\n";
|
fout << "}\n";
|
||||||
fout.close();
|
fout.close();
|
||||||
// create the source list
|
|
||||||
|
// Create the source list
|
||||||
|
|
||||||
cmSourceFile cfile;
|
cmSourceFile cfile;
|
||||||
cfile.SetIsAnAbstractClass(false);
|
cfile.SetIsAnAbstractClass(false);
|
||||||
cfile.SetName(args[1].c_str(), m_Makefile->GetCurrentOutputDirectory(),
|
cfile.SetName(args[1].c_str(),
|
||||||
"cxx", false);
|
m_Makefile->GetCurrentOutputDirectory(),
|
||||||
|
"cxx",
|
||||||
|
false);
|
||||||
m_Makefile->AddSource(cfile, sourceList);
|
m_Makefile->AddSource(cfile, sourceList);
|
||||||
|
|
||||||
for(i = testsBegin; i != args.end(); ++i)
|
for(i = tests_filename.begin(); i != tests_filename.end(); ++i)
|
||||||
{
|
{
|
||||||
cmSourceFile cfile;
|
cmSourceFile cfile;
|
||||||
cfile.SetIsAnAbstractClass(false);
|
cfile.SetIsAnAbstractClass(false);
|
||||||
cfile.SetName(i->c_str(), m_Makefile->GetCurrentDirectory(),
|
cfile.SetName(i->c_str(),
|
||||||
"cxx", false);
|
m_Makefile->GetCurrentDirectory(),
|
||||||
|
"cxx",
|
||||||
|
false);
|
||||||
m_Makefile->AddSource(cfile, sourceList);
|
m_Makefile->AddSource(cfile, sourceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue