ENH: add -R (similar to ctest but use substr instead of regexp). indent.
This commit is contained in:
parent
437a8c9816
commit
95519ef1b7
|
@ -22,8 +22,8 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
{
|
{
|
||||||
if (argsIn.size() < 3)
|
if (argsIn.size() < 3)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -45,7 +45,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
std::ofstream fout(driver.c_str());
|
std::ofstream fout(driver.c_str());
|
||||||
if(!fout)
|
if (!fout)
|
||||||
{
|
{
|
||||||
std::string err = "Could not create file ";
|
std::string err = "Could not create file ";
|
||||||
err += driver;
|
err += driver;
|
||||||
|
@ -56,9 +56,12 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
|
|
||||||
// Create the test driver file
|
// Create the test driver file
|
||||||
|
|
||||||
fout << "#include <stdio.h>\n";
|
fout <<
|
||||||
fout << "#include <string.h>\n";
|
"#include <stdio.h>\n"
|
||||||
fout << "// forward declare test functions\n";
|
"#include <string.h>\n"
|
||||||
|
"\n"
|
||||||
|
"// Forward declare test functions\n"
|
||||||
|
"\n";
|
||||||
|
|
||||||
std::vector<std::string>::iterator testsBegin = i;
|
std::vector<std::string>::iterator testsBegin = i;
|
||||||
std::vector<std::string> tests_filename;
|
std::vector<std::string> tests_filename;
|
||||||
|
@ -80,65 +83,105 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
fout << "int " << *i << "(int, char**);\n";
|
fout << "int " << *i << "(int, char**);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
fout << "// Create map \n";
|
fout <<
|
||||||
fout << "typedef int (*MainFuncPointer)(int , char**);\n";
|
"\n"
|
||||||
fout << "struct functionMapEntry\n"
|
"// Create map\n"
|
||||||
<< "{\n"
|
"\n"
|
||||||
<< "const char* name;\n"
|
"typedef int (*MainFuncPointer)(int , char**);\n"
|
||||||
<< "MainFuncPointer func;\n"
|
"struct functionMapEntry\n"
|
||||||
<< "};\n\n";
|
"{\n"
|
||||||
fout << "functionMapEntry cmakeGeneratedFunctionMapEntries[] = {\n";
|
" const char* name;\n"
|
||||||
|
" MainFuncPointer func;\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"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 <<
|
||||||
|
" {\n"
|
||||||
|
" \"" << *i << "\",\n"
|
||||||
|
" " << *i << "\n"
|
||||||
|
" },\n";
|
||||||
numTests++;
|
numTests++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fout << "};\n";
|
fout <<
|
||||||
fout << "int main(int ac, char** av)\n"
|
"};\n"
|
||||||
<< "{\n";
|
"\n"
|
||||||
fout << " int NumTests = " << numTests << ";\n";
|
"int main(int ac, char** av)\n"
|
||||||
fout << " int i;\n";
|
"{\n"
|
||||||
fout << " if(ac < 2)\n";
|
" int NumTests = " << numTests << ";\n"
|
||||||
fout << " {\n";
|
" int i;\n"
|
||||||
fout << " // if there is only one test, then run it with the arguments\n";
|
" \n"
|
||||||
fout << " if(NumTests == 1)\n";
|
" // If no test name was given\n"
|
||||||
fout << " { return (*cmakeGeneratedFunctionMapEntries[0].func)(ac, av); }\n";
|
" if (ac < 2)\n"
|
||||||
fout << " printf(\"Available tests:\\n\");\n";
|
" {\n"
|
||||||
fout << " for(i =0; i < NumTests; ++i)\n";
|
" // If there is only one test, then run it with the arguments\n"
|
||||||
fout << " {\n";
|
" if (NumTests == 1)\n"
|
||||||
fout << " printf(\"%d. %s\\n\", i, cmakeGeneratedFunctionMapEntries[i].name);\n";
|
" {\n"
|
||||||
fout << " }\n";
|
" return (*cmakeGeneratedFunctionMapEntries[0].func)(ac, av);\n"
|
||||||
fout << " printf(\"To run a test, enter the test number: \");\n";
|
" }\n"
|
||||||
fout << " int testNum = 0;\n";
|
" \n"
|
||||||
fout << " scanf(\"%d\", &testNum);\n";
|
" // Ask for a test\n"
|
||||||
fout << " if(testNum >= NumTests)\n";
|
" printf(\"Available tests:\\n\");\n"
|
||||||
fout << " {\n";
|
" for (i =0; i < NumTests; ++i)\n"
|
||||||
fout << " printf(\"%d is an invalid test number.\\n\", testNum);\n";
|
" {\n"
|
||||||
fout << " return -1;\n";
|
" printf(\"%d. %s\\n\", i, cmakeGeneratedFunctionMapEntries[i].name);\n"
|
||||||
fout << " }\n";
|
" }\n"
|
||||||
fout << " return (*cmakeGeneratedFunctionMapEntries[testNum].func)(ac-1, av+1);\n";
|
" printf(\"To run a test, enter the test number: \");\n"
|
||||||
fout << " }\n";
|
" int testNum = 0;\n"
|
||||||
fout << " for(i =0; i < NumTests; ++i)\n";
|
" scanf(\"%d\", &testNum);\n"
|
||||||
fout << " {\n";
|
" if (testNum >= NumTests)\n"
|
||||||
fout << " if(strcmp(cmakeGeneratedFunctionMapEntries[i].name, av[1]) == 0)\n";
|
" {\n"
|
||||||
fout << " {\n";
|
" printf(\"%d is an invalid test number.\\n\", testNum);\n"
|
||||||
fout << " return (*cmakeGeneratedFunctionMapEntries[i].func)(ac-1, av+1);\n";
|
" return -1;\n"
|
||||||
fout << " }\n";
|
" }\n"
|
||||||
fout << " }\n";
|
" return (*cmakeGeneratedFunctionMapEntries[testNum].func)(ac-1, av+1);\n"
|
||||||
fout << " // if there is only one test, then run it with the arguments\n";
|
" }\n"
|
||||||
fout << " if(NumTests == 1)\n";
|
" \n"
|
||||||
fout << " { return (*cmakeGeneratedFunctionMapEntries[0].func)(ac, av); }\n";
|
" // If partial match is requested\n"
|
||||||
fout << " printf(\"Available tests:\\n\");\n";
|
" int partial_match = (strcmp(av[1], \"-R\") == 0) ? 1 : 0;\n"
|
||||||
fout << " for(i =0; i < NumTests; ++i)\n";
|
" if (partial_match && ac < 3)\n"
|
||||||
fout << " {\n";
|
" {\n"
|
||||||
fout << " printf(\"%d. %s\\n\", i, cmakeGeneratedFunctionMapEntries[i].name);\n";
|
" printf(\"-R needs an additional parameter.\\n\");\n"
|
||||||
fout << " }\n";
|
" return -1;\n"
|
||||||
fout << " printf(\"Failed: %s is an invalid test name.\\n\", av[1]);\n";
|
" }\n"
|
||||||
fout << " return -1;\n";
|
" \n"
|
||||||
fout << "}\n";
|
" // A test name was given, try to find it\n"
|
||||||
|
" for (i =0; i < NumTests; ++i)\n"
|
||||||
|
" {\n"
|
||||||
|
" if (partial_match && \n"
|
||||||
|
" strstr(cmakeGeneratedFunctionMapEntries[i].name, av[2]) != NULL)\n"
|
||||||
|
" {\n"
|
||||||
|
" return (*cmakeGeneratedFunctionMapEntries[i].func)(ac-2, av+2);\n"
|
||||||
|
" }\n"
|
||||||
|
" else if (!partial_match && \n"
|
||||||
|
" strcmp(cmakeGeneratedFunctionMapEntries[i].name, av[1]) == 0)\n"
|
||||||
|
" {\n"
|
||||||
|
" return (*cmakeGeneratedFunctionMapEntries[i].func)(ac-1, av+1);\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" // If the test was not found but there is only one test, then\n"
|
||||||
|
" // run it with the arguments\n"
|
||||||
|
" if (NumTests == 1)\n"
|
||||||
|
" {\n"
|
||||||
|
" return (*cmakeGeneratedFunctionMapEntries[0].func)(ac, av);\n"
|
||||||
|
" }\n"
|
||||||
|
" \n"
|
||||||
|
" // Nothing was run, display the test names\n"
|
||||||
|
" printf(\"Available tests:\\n\");\n"
|
||||||
|
" for (i =0; i < NumTests; ++i)\n"
|
||||||
|
" {\n"
|
||||||
|
" printf(\"%d. %s\\n\", i, cmakeGeneratedFunctionMapEntries[i].name);\n"
|
||||||
|
" }\n"
|
||||||
|
" printf(\"Failed: %s is an invalid test name.\\n\", av[1]);\n"
|
||||||
|
" \n"
|
||||||
|
" return -1;\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
fout.close();
|
fout.close();
|
||||||
|
|
||||||
// Create the source list
|
// Create the source list
|
||||||
|
@ -151,7 +194,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
false);
|
false);
|
||||||
m_Makefile->AddSource(cfile, sourceList);
|
m_Makefile->AddSource(cfile, sourceList);
|
||||||
|
|
||||||
for(i = tests_filename.begin(); i != tests_filename.end(); ++i)
|
for (i = tests_filename.begin(); i != tests_filename.end(); ++i)
|
||||||
{
|
{
|
||||||
cmSourceFile cfile;
|
cmSourceFile cfile;
|
||||||
cfile.SetIsAnAbstractClass(false);
|
cfile.SetIsAnAbstractClass(false);
|
||||||
|
|
Loading…
Reference in New Issue