fixed WinTestRunner batch mode

This commit is contained in:
Günter Obiltschnig 2014-01-16 23:53:29 +01:00
parent b7778b4fe0
commit ade75434c4

View File

@ -34,26 +34,15 @@ void WinTestRunner::run()
std::string cmdLine(AfxGetApp()->m_lpCmdLine); std::string cmdLine(AfxGetApp()->m_lpCmdLine);
if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B')) if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B'))
{ {
// We're running in batch mode. TestRunner runner;
std::string outPath; for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
if (cmdLine.size() > 4 && cmdLine[2] == ':') runner.addTest((*it)->toString(), *it);
outPath = cmdLine.substr(3); _tests.clear();
else std::vector<std::string> args;
outPath = "CON"; args.push_back("WinTestRunner");
std::ofstream ostr(outPath.c_str()); args.push_back("-all");
if (ostr.good()) bool success = runner.run(args);
{ ExitProcess(success ? 0 : 1);
TestRunner runner(ostr);
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
runner.addTest((*it)->toString(), *it);
_tests.clear();
std::vector<std::string> args;
args.push_back("WinTestRunner");
args.push_back("-all");
bool success = runner.run(args);
ExitProcess(success ? 0 : 1);
}
else ExitProcess(2);
} }
else else
{ {
@ -77,13 +66,36 @@ END_MESSAGE_MAP()
BOOL WinTestRunnerApp::InitInstance() BOOL WinTestRunnerApp::InitInstance()
{ {
AllocConsole(); std::string cmdLine(AfxGetApp()->m_lpCmdLine);
SetConsoleTitle("CppUnit WinTestRunner Console"); if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B'))
freopen("CONOUT$", "w", stdout); {
freopen("CONOUT$", "w", stderr); // We're running in batch mode.
freopen("CONIN$", "r", stdin); std::string outPath;
TestMain(); if (cmdLine.size() > 4 && cmdLine[2] == ':')
FreeConsole(); {
outPath = cmdLine.substr(3);
}
else
{
char buffer[1024];
GetModuleFileName(NULL, buffer, sizeof(buffer));
outPath = buffer;
outPath += ".out";
}
freopen(outPath.c_str(), "w", stdout);
freopen(outPath.c_str(), "w", stderr);
TestMain();
}
else
{
AllocConsole();
SetConsoleTitle("CppUnit WinTestRunner Console");
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
freopen("CONIN$", "r", stdin);
TestMain();
FreeConsole();
}
return FALSE; return FALSE;
} }