diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx index 1f7246ef0..5fc64b7cd 100644 --- a/Source/cmCreateTestSourceList.cxx +++ b/Source/cmCreateTestSourceList.cxx @@ -30,7 +30,39 @@ bool cmCreateTestSourceList::InitialPass(std::vector const& argsIn) cmSystemTools::ExpandListArguments(argsIn, args); std::vector::iterator i = args.begin(); - + std::string extraInclude; + std::string function; + std::vector tests; + // extract extra include and function ot + for(; i != args.end(); i++) + { + if(*i == "EXTRA_INCLUDE") + { + ++i; + if(i == args.end()) + { + this->SetError("incorrect arguments to EXTRA_INCLUDE"); + return false; + } + extraInclude = *i; + } + else if(*i == "FUNCTION") + { + ++i; + if(i == args.end()) + { + this->SetError("incorrect arguments to FUNCTION"); + return false; + } + function = *i; + } + else + { + tests.push_back(*i); + } + } + i = tests.begin(); + // Name of the source list const char* sourceList = i->c_str(); @@ -59,8 +91,13 @@ bool cmCreateTestSourceList::InitialPass(std::vector const& argsIn) fout << "#include \n" "#include \n" - "#include \n" - + "#include \n"; + if(extraInclude.size()) + { + fout << "#include \"" << extraInclude << "\"\n"; + } + + fout << "\n" "// Forward declare test functions\n" "\n"; @@ -75,8 +112,12 @@ bool cmCreateTestSourceList::InitialPass(std::vector const& argsIn) // For the moment: // - replace spaces ' ', ':' and '/' with underscores '_' - for(i = testsBegin; i != args.end(); ++i) + for(i = testsBegin; i != tests.end(); ++i) { + if(*i == "EXTRA_INCLUDE") + { + break; + } std::string func_name = *i; cmSystemTools::ConvertToUnixSlashes(func_name); cmSystemTools::ReplaceString(func_name, " ", "_"); @@ -101,7 +142,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector const& argsIn) int numTests = 0; std::vector::iterator j; - for(i = testsBegin, j = tests_func_name.begin(); i != args.end(); ++i, ++j) + for(i = testsBegin, j = tests_func_name.begin(); i != tests.end(); ++i, ++j) { fout << " {\n" @@ -138,7 +179,14 @@ bool cmCreateTestSourceList::InitialPass(std::vector const& argsIn) " int NumTests = " << numTests << ";\n" " int i;\n" " \n" - " // If no test name was given\n" + " // If no test name was given\n"; + if(function.size()) + { + fout << " // process command line with user function\n" + << " " << function << "(&ac, &av);\n"; + } + + fout << " if (ac < 2)\n" " {\n" " // If there is only one test, then run it with the arguments\n" @@ -218,7 +266,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector const& argsIn) false); m_Makefile->AddSource(cfile, sourceList); - for(i = testsBegin; i != args.end(); ++i) + for(i = testsBegin; i != tests.end(); ++i) { cmSourceFile cfile; cfile.SetIsAnAbstractClass(false); diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h index 3d78b9370..102226ec7 100644 --- a/Source/cmCreateTestSourceList.h +++ b/Source/cmCreateTestSourceList.h @@ -67,13 +67,16 @@ public: virtual const char* GetFullDocumentation() { return - "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 needed to build the testdriver will be in SourceListName.\n" "DriverName.cxx is the name of the test driver program.\n" "The rest of the arguments consist of a list of test source files, can be " "; 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 int foo();) " - "DriverName.cxx will be able to call each of the tests by name on the command line."; + "DriverName.cxx will be able to call each of the tests by name on the command line. " + "If EXTRA_INCLUDE is specified, then the next argument is included into the generated file. " + "If FUNCTION is specified, then the next argument is taken as a function name that is passed " + "a pointer to ac and av. This can be used to add extra command line processing to each test. "; } cmTypeMacro(cmCreateTestSourceList, cmCommand); diff --git a/Tests/TestDriver/CMakeLists.txt b/Tests/TestDriver/CMakeLists.txt index a7f63328a..2e0a1fa5d 100644 --- a/Tests/TestDriver/CMakeLists.txt +++ b/Tests/TestDriver/CMakeLists.txt @@ -2,12 +2,13 @@ PROJECT(TestDriverTest) SET(Extra_SRCS testExtraStuff.cxx testExtraStuff2.cxx ) SET(Extra_SRCS ${Extra_SRCS};testExtraStuff3.cxx ) - +INCLUDE_DIRECTORIES(${TestDriverTest_SOURCE_DIR}) CREATE_TEST_SOURCELIST(testSrcs TestDriverTest test1 test2 - subdir/test3) + subdir/test3 + EXTRA_INCLUDE testArgs.h FUNCTION testProccessArgs) ADD_EXECUTABLE(TestDriverTest testSrcs ${Extra_SRCS})