summaryrefslogtreecommitdiffstats
path: root/Source/cmCreateTestSourceList.cxx
diff options
context:
space:
mode:
authorSebastien Barre <sebastien.barre@kitware.com>2002-03-26 21:42:43 (GMT)
committerSebastien Barre <sebastien.barre@kitware.com>2002-03-26 21:42:43 (GMT)
commita5b833119db2f76472dda7b7dd22b07b9113453e (patch)
treecd7d40c386f43663dd466dddf2e5bdedde9a540c /Source/cmCreateTestSourceList.cxx
parent9c4922b3af0b785af052fe767119acfd7f44ca8e (diff)
downloadCMake-a5b833119db2f76472dda7b7dd22b07b9113453e.zip
CMake-a5b833119db2f76472dda7b7dd22b07b9113453e.tar.gz
CMake-a5b833119db2f76472dda7b7dd22b07b9113453e.tar.bz2
ENH: now supports tests inside sub-dirs
Diffstat (limited to 'Source/cmCreateTestSourceList.cxx')
-rw-r--r--Source/cmCreateTestSourceList.cxx50
1 files changed, 42 insertions, 8 deletions
diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx
index 4d729a9..43f1930 100644
--- a/Source/cmCreateTestSourceList.cxx
+++ b/Source/cmCreateTestSourceList.cxx
@@ -25,18 +25,25 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
this->SetError("called with wrong number of arguments.");
return false;
}
+
std::vector<std::string> args;
- cmSystemTools::ExpandListArguments(argsIn, args);
+ cmSystemTools::ExpandListArguments(argsIn, args, true);
std::vector<std::string>::iterator i = args.begin();
+
+ // Name of the source list
+
const char* sourceList = i->c_str();
++i;
+
+ // Name of the test driver
+
std::string driver = m_Makefile->GetCurrentOutputDirectory();
driver += "/";
driver += *i;
driver += ".cxx";
++i;
- std::vector<std::string>::iterator testsBegin = i;
+
std::ofstream fout(driver.c_str());
if(!fout)
{
@@ -46,14 +53,33 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
this->SetError(err.c_str());
return false;
}
+
// Create the test driver file
+
fout << "#include <stdio.h>\n";
fout << "#include <string.h>\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)
{
+ tests_filename.push_back(*i);
+ cmSystemTools::ConvertToUnixSlashes(*i);
+ cmSystemTools::ReplaceString(*i, " ", "_");
+ cmSystemTools::ReplaceString(*i, "/", "_");
+ cmSystemTools::ReplaceString(*i, ":", "_");
fout << "int " << *i << "(int, char**);\n";
}
+
fout << "// Create map \n";
fout << "typedef int (*MainFuncPointer)(int , char**);\n";
fout << "struct functionMapEntry\n"
@@ -62,12 +88,14 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
<< "MainFuncPointer func;\n"
<< "};\n\n";
fout << "functionMapEntry cmakeGeneratedFunctionMapEntries[] = {\n";
+
int numTests = 0;
for(i = testsBegin; i != args.end(); ++i)
{
fout << "{\"" << *i << "\", " << *i << "},\n";
numTests++;
}
+
fout << "};\n";
fout << "int main(int ac, char** av)\n"
<< "{\n";
@@ -112,19 +140,25 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
fout << " return -1;\n";
fout << "}\n";
fout.close();
- // create the source list
+
+ // Create the source list
+
cmSourceFile cfile;
cfile.SetIsAnAbstractClass(false);
- cfile.SetName(args[1].c_str(), m_Makefile->GetCurrentOutputDirectory(),
- "cxx", false);
+ cfile.SetName(args[1].c_str(),
+ m_Makefile->GetCurrentOutputDirectory(),
+ "cxx",
+ false);
m_Makefile->AddSource(cfile, sourceList);
- for(i = testsBegin; i != args.end(); ++i)
+ for(i = tests_filename.begin(); i != tests_filename.end(); ++i)
{
cmSourceFile cfile;
cfile.SetIsAnAbstractClass(false);
- cfile.SetName(i->c_str(), m_Makefile->GetCurrentDirectory(),
- "cxx", false);
+ cfile.SetName(i->c_str(),
+ m_Makefile->GetCurrentDirectory(),
+ "cxx",
+ false);
m_Makefile->AddSource(cfile, sourceList);
}