11
int main (int argc, char **argv)
13
std::cin >> std::noskipws;
17
std::cout << "Usage: PATH_TO_TEST_BINARY --gtest_list_tests | ./build_test_cases PATH_TO_TEST_BINARY";
21
std::map<std::string, std::vector<std::string> > testCases;
23
std::string currentTestCase;
25
while (std::getline (std::cin, line))
28
if (line.find (" ") == 0)
29
testCases[currentTestCase].push_back (currentTestCase + line.substr (2));
31
currentTestCase = line;
35
std::ofstream testfilecmake;
36
char *base = basename (argv[1]);
37
std::string gtestName (base);
39
testfilecmake.open (std::string (gtestName + "_test.cmake").c_str (), std::ios::out | std::ios::trunc);
41
if (testfilecmake.is_open ())
43
for (std::map <std::string, std::vector<std::string> >::iterator it = testCases.begin ();
44
it != testCases.end (); it++)
46
for (std::vector <std::string>::iterator jt = it->second.begin ();
47
jt != it->second.end (); jt++)
49
if (testfilecmake.good ())
51
std::string addTest ("ADD_TEST (");
52
std::string testExec (" \"" + std::string (argv[1]) + "\"");
53
std::string gTestFilter ("\"--gtest_filter=\"");
54
std::string filterBegin ("\"");
55
std::string filterEnd ("\")");
57
testfilecmake << addTest << *jt << testExec << gTestFilter << filterBegin << *jt << filterEnd << std::endl;
62
testfilecmake.close ();
65
std::ifstream CTestTestfile ("CTestTestfile.cmake", std::ifstream::in);
66
bool needsInclude = true;
69
std::string includeLine = std::string ("INCLUDE (") +
71
std::string ("_test.cmake)");
73
if (CTestTestfile.is_open ())
75
while (CTestTestfile.good ())
77
std::getline (CTestTestfile, line);
79
if (line == includeLine)
83
CTestTestfile.close ();
88
std::ofstream CTestTestfileW ("CTestTestfile.cmake", std::ofstream::app | std::ofstream::out);
90
if (CTestTestfileW.is_open ())
92
CTestTestfileW << includeLine;
93
CTestTestfileW.close ();