Browse Source

ENH: now supports tests inside sub-dirs

Sebastien Barre 23 years ago
parent
commit
a5b833119d
1 changed files with 42 additions and 8 deletions
  1. 42 8
      Source/cmCreateTestSourceList.cxx

+ 42 - 8
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);
     }