From ade75434c4350b0f0dd5a70924132a1b851e53e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Thu, 16 Jan 2014 23:53:29 +0100 Subject: [PATCH] fixed WinTestRunner batch mode --- CppUnit/WinTestRunner/src/WinTestRunner.cpp | 66 ++++++++++++--------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/CppUnit/WinTestRunner/src/WinTestRunner.cpp b/CppUnit/WinTestRunner/src/WinTestRunner.cpp index b974f7b58..cc5ff5721 100644 --- a/CppUnit/WinTestRunner/src/WinTestRunner.cpp +++ b/CppUnit/WinTestRunner/src/WinTestRunner.cpp @@ -34,26 +34,15 @@ void WinTestRunner::run() std::string cmdLine(AfxGetApp()->m_lpCmdLine); if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B')) { - // We're running in batch mode. - std::string outPath; - if (cmdLine.size() > 4 && cmdLine[2] == ':') - outPath = cmdLine.substr(3); - else - outPath = "CON"; - std::ofstream ostr(outPath.c_str()); - if (ostr.good()) - { - TestRunner runner(ostr); - for (std::vector::iterator it = _tests.begin(); it != _tests.end(); ++it) - runner.addTest((*it)->toString(), *it); - _tests.clear(); - std::vector args; - args.push_back("WinTestRunner"); - args.push_back("-all"); - bool success = runner.run(args); - ExitProcess(success ? 0 : 1); - } - else ExitProcess(2); + TestRunner runner; + for (std::vector::iterator it = _tests.begin(); it != _tests.end(); ++it) + runner.addTest((*it)->toString(), *it); + _tests.clear(); + std::vector args; + args.push_back("WinTestRunner"); + args.push_back("-all"); + bool success = runner.run(args); + ExitProcess(success ? 0 : 1); } else { @@ -77,13 +66,36 @@ END_MESSAGE_MAP() BOOL WinTestRunnerApp::InitInstance() { - AllocConsole(); - SetConsoleTitle("CppUnit WinTestRunner Console"); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - freopen("CONIN$", "r", stdin); - TestMain(); - FreeConsole(); + std::string cmdLine(AfxGetApp()->m_lpCmdLine); + if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B')) + { + // We're running in batch mode. + std::string outPath; + if (cmdLine.size() > 4 && cmdLine[2] == ':') + { + 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; }