catch_reporter_automake.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Created by Justin R. Wilson on 2/19/2017.
  3. * Copyright 2017 Justin R. Wilson. All rights reserved.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef TWOBLUECUBES_CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  9. #define TWOBLUECUBES_CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  10. // Don't #include any Catch headers here - we can assume they are already
  11. // included before this header.
  12. // This is not good practice in general but is necessary in this case so this
  13. // file can be distributed as a single header that works with the main
  14. // Catch single header.
  15. namespace Catch {
  16. struct AutomakeReporter : StreamingReporterBase<AutomakeReporter> {
  17. AutomakeReporter( ReporterConfig const& _config )
  18. : StreamingReporterBase( _config )
  19. {}
  20. ~AutomakeReporter() override;
  21. static std::string getDescription() {
  22. return "Reports test results in the format of Automake .trs files";
  23. }
  24. void assertionStarting( AssertionInfo const& ) override {}
  25. bool assertionEnded( AssertionStats const& /*_assertionStats*/ ) override { return true; }
  26. void testCaseEnded( TestCaseStats const& _testCaseStats ) override {
  27. // Possible values to emit are PASS, XFAIL, SKIP, FAIL, XPASS and ERROR.
  28. stream << ":test-result: ";
  29. if (_testCaseStats.totals.assertions.allPassed()) {
  30. stream << "PASS";
  31. } else if (_testCaseStats.totals.assertions.allOk()) {
  32. stream << "XFAIL";
  33. } else {
  34. stream << "FAIL";
  35. }
  36. stream << ' ' << _testCaseStats.testInfo.name << '\n';
  37. StreamingReporterBase::testCaseEnded( _testCaseStats );
  38. }
  39. void skipTest( TestCaseInfo const& testInfo ) override {
  40. stream << ":test-result: SKIP " << testInfo.name << '\n';
  41. }
  42. };
  43. #ifdef CATCH_IMPL
  44. AutomakeReporter::~AutomakeReporter() {}
  45. #endif
  46. CATCH_REGISTER_REPORTER( "automake", AutomakeReporter)
  47. } // end namespace Catch
  48. #endif // TWOBLUECUBES_CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED