updated to handle extensions

This commit is contained in:
Ken Martin 2002-07-30 16:19:14 -04:00
parent c05e3613ce
commit 0f6e022dca
2 changed files with 34 additions and 11 deletions

View File

@ -69,11 +69,15 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
++i; ++i;
// Name of the test driver // Name of the test driver
// make sure they specified an extension
if (cmSystemTools::GetFilenameExtension(*i).size() < 1)
{
this->SetError("You must specify a file extenion for the test driver file.");
return false;
}
std::string driver = m_Makefile->GetCurrentOutputDirectory(); std::string driver = m_Makefile->GetCurrentOutputDirectory();
driver += "/"; driver += "/";
driver += *i; driver += *i;
driver += ".cxx";
++i; ++i;
std::ofstream fout(driver.c_str()); std::ofstream fout(driver.c_str());
@ -119,20 +123,29 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
{ {
break; break;
} }
std::string func_name = *i; std::string func_name;
if (cmSystemTools::GetFilenamePath(*i).size() > 0)
{
func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
cmSystemTools::GetFilenameWithoutLastExtension(*i);
}
else
{
func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
}
cmSystemTools::ConvertToUnixSlashes(func_name); cmSystemTools::ConvertToUnixSlashes(func_name);
cmSystemTools::ReplaceString(func_name, " ", "_"); cmSystemTools::ReplaceString(func_name, " ", "_");
cmSystemTools::ReplaceString(func_name, "/", "_"); cmSystemTools::ReplaceString(func_name, "/", "_");
cmSystemTools::ReplaceString(func_name, ":", "_"); cmSystemTools::ReplaceString(func_name, ":", "_");
tests_func_name.push_back(func_name); tests_func_name.push_back(func_name);
fout << "int " << func_name << "(int, char**);\n"; fout << "int " << func_name << "(int, char*[]);\n";
} }
fout << fout <<
"\n" "\n"
"// Create map\n" "// Create map\n"
"\n" "\n"
"typedef int (*MainFuncPointer)(int , char**);\n" "typedef int (*MainFuncPointer)(int , char*[]);\n"
"struct functionMapEntry\n" "struct functionMapEntry\n"
"{\n" "{\n"
" const char* name;\n" " const char* name;\n"
@ -145,9 +158,19 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
std::vector<std::string>::iterator j; std::vector<std::string>::iterator j;
for(i = testsBegin, j = tests_func_name.begin(); i != tests.end(); ++i, ++j) for(i = testsBegin, j = tests_func_name.begin(); i != tests.end(); ++i, ++j)
{ {
std::string func_name;
if (cmSystemTools::GetFilenamePath(*i).size() > 0)
{
func_name = cmSystemTools::GetFilenamePath(*i) + "/" +
cmSystemTools::GetFilenameWithoutLastExtension(*i);
}
else
{
func_name = cmSystemTools::GetFilenameWithoutLastExtension(*i);
}
fout << fout <<
" {\n" " {\n"
" \"" << *i << "\",\n" " \"" << func_name << "\",\n"
" " << *j << "\n" " " << *j << "\n"
" },\n"; " },\n";
numTests++; numTests++;
@ -177,7 +200,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
" return new_string;\n" " return new_string;\n"
"}\n" "}\n"
"\n" "\n"
"int main(int ac, char** av)\n" "int main(int ac, char *av[])\n"
"{\n" "{\n"
" int NumTests, i, testNum, partial_match;\n" " int NumTests, i, testNum, partial_match;\n"
" char *arg, *test_name;\n" " char *arg, *test_name;\n"
@ -266,12 +289,12 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
std::string sourceListValue; std::string sourceListValue;
cfile.SetIsAnAbstractClass(false); cfile.SetIsAnAbstractClass(false);
cfile.SetName(args[1].c_str(), cfile.SetName(cmSystemTools::GetFilenameWithoutExtension(args[1]).c_str(),
m_Makefile->GetCurrentOutputDirectory(), m_Makefile->GetCurrentOutputDirectory(),
"cxx", "cxx",
false); false);
m_Makefile->AddSource(cfile); m_Makefile->AddSource(cfile);
sourceListValue = args[1] + ".cxx"; sourceListValue = args[1];
for(i = testsBegin; i != tests.end(); ++i) for(i = testsBegin; i != tests.end(); ++i)
{ {

View File

@ -70,11 +70,11 @@ public:
"CREATE_TEST_SOURCELIST(SourceListName DriverName test1 test2 test3 " "CREATE_TEST_SOURCELIST(SourceListName DriverName test1 test2 test3 "
"EXTRA_INCLUDE include.h FUNCTION function) The list of source files " "EXTRA_INCLUDE include.h FUNCTION function) The list of source files "
"needed to build the testdriver will be in SourceListName. " "needed to build the testdriver will be in SourceListName. "
"DriverName.cxx is the name of the test driver program. The rest of " "DriverName is the name of the test driver program. The rest of "
"the arguments consist of a list of test source files, can be " "the arguments consist of a list of test source files, can be "
"; separated. Each test source file should have a function in it that " "; separated. Each test source file should have a function in it that "
"is the same name as the file with no extension (foo.cxx should have " "is the same name as the file with no extension (foo.cxx should have "
"int foo();) DriverName.cxx will be able to call each of the tests by " "int foo();) DriverName will be able to call each of the tests by "
"name on the command line. If EXTRA_INCLUDE is specified, then the " "name on the command line. If EXTRA_INCLUDE is specified, then the "
"next argument is included into the generated file. If FUNCTION is " "next argument is included into the generated file. If FUNCTION is "
"specified, then the next argument is taken as a function name that " "specified, then the next argument is taken as a function name that "