diff options
author | Thanos Doukoudakis <thanos.doukoudakis@isode.com> | 2017-06-16 10:45:03 (GMT) |
---|---|---|
committer | Thanos Doukoudakis <thanos.doukoudakis@isode.com> | 2017-07-07 13:47:58 (GMT) |
commit | 1b678a155adca8957866e016b0e344eee6290466 (patch) | |
tree | 08af7836ed7fca39a61f85941ec7545be7455c97 /QA/Checker/checker.cpp | |
parent | 2a251161c5baa688ec12068346359bd829ab2ea1 (diff) | |
download | swift-1b678a155adca8957866e016b0e344eee6290466.zip swift-1b678a155adca8957866e016b0e344eee6290466.tar.bz2 |
Make gtest output more compact
This patch will make the checker test application output to use a custom
printer for google test results. The output will be less verbose, and
similar to the output of CppUnit. If the --verbose flag is used, the
default printer will be used instead.
Test-information:
Tested on Windows 10 and Ubuntu 16.04.
Change-Id: I1488cf576ab07da03b0dfcc93a48a8518d5afc06
Diffstat (limited to 'QA/Checker/checker.cpp')
-rw-r--r-- | QA/Checker/checker.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/QA/Checker/checker.cpp b/QA/Checker/checker.cpp index bcf0f5c..3cc7713 100644 --- a/QA/Checker/checker.cpp +++ b/QA/Checker/checker.cpp @@ -1,42 +1,43 @@ /* * Copyright (c) 2010-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <cstdlib> #include <fstream> #include <string> #include <sstream> #include <gtest/gtest.h> +#include <QA/Checker/CppUnitTestResultPrinter.h> #include <cppunit/BriefTestProgressListener.h> #include <cppunit/TextOutputter.h> #include <cppunit/TextTestProgressListener.h> #include <cppunit/TextTestResult.h> #include <cppunit/XmlOutputter.h> #include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/ui/text/TestRunner.h> #include <Swiften/Base/Log.h> using Swift::Log; int main(int argc, char* argv[]) { bool verbose = false; bool outputXML = false; Log::setLogLevel(Swift::Log::error); // Parse parameters std::vector<std::string> testsToRun; for (int i = 1; i < argc; ++i) { std::string param(argv[i]); if (param == "--verbose") { verbose = true; } else if (param == "--xml") { outputXML = true; } else if (param == "--debug") { @@ -99,40 +100,46 @@ int main(int argc, char* argv[]) { for (std::vector<std::string>::const_iterator i = testsToRun.begin(); i != testsToRun.end(); ++i) { try { runner.run(controller, *i); } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; return -1; } } // Output the results if (outputXML) { std::ofstream cppUnitXUnitOutputFile; cppUnitXUnitOutputFile.open(cppunitOutputFilename, std::ofstream::out | std::ofstream::trunc); if (cppUnitXUnitOutputFile.is_open()) { CppUnit::XmlOutputter outputter(&result, cppUnitXUnitOutputFile); outputter.write(); } else { std::cerr << "Failed to overwrite " << cppunitOutputFilename << " output file." << std::endl; return 1; } } else { CppUnit::TextOutputter outputter(&result, std::cerr); outputter.write(); } auto googleTestWasSuccessful = false; try { + if (!verbose) { + testing::UnitTest& unitTest = *testing::UnitTest::GetInstance(); + testing::TestEventListeners& listeners = unitTest.listeners(); + delete listeners.Release(listeners.default_result_printer()); + listeners.Append(new testing::CppUnitTestResultPrinter); + } googleTestWasSuccessful = RUN_ALL_TESTS() == 0 ? true : false; } catch (const ::testing::internal::GoogleTestFailureException& e) { googleTestWasSuccessful = false; SWIFT_LOG(error) << "GoogleTestFailureException was thrown: " << e.what() << std::endl; } auto cppUnitWasSuccessful = result.wasSuccessful() ? true : false; return (googleTestWasSuccessful && cppUnitWasSuccessful) ? 0 : 1; } |