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 
11 // Don't #include any Catch headers here - we can assume they are already
12 // included before this header.
13 // This is not good practice in general but is necessary in this case so this
14 // file can be distributed as a single header that works with the main
15 // Catch single header.
16 
17 namespace Catch {
18 
19     struct AutomakeReporter : StreamingReporterBase<AutomakeReporter> {
AutomakeReporterCatch::AutomakeReporter20         AutomakeReporter( ReporterConfig const& _config )
21           :   StreamingReporterBase( _config )
22         {}
23 
24         ~AutomakeReporter() override;
25 
getDescriptionCatch::AutomakeReporter26         static std::string getDescription() {
27             return "Reports test results in the format of Automake .trs files";
28         }
29 
assertionStartingCatch::AutomakeReporter30         void assertionStarting( AssertionInfo const& ) override {}
31 
assertionEndedCatch::AutomakeReporter32         bool assertionEnded( AssertionStats const& /*_assertionStats*/ ) override { return true; }
33 
testCaseEndedCatch::AutomakeReporter34         void testCaseEnded( TestCaseStats const& _testCaseStats ) override {
35             // Possible values to emit are PASS, XFAIL, SKIP, FAIL, XPASS and ERROR.
36             stream << ":test-result: ";
37             if (_testCaseStats.totals.assertions.allPassed()) {
38                 stream << "PASS";
39             } else if (_testCaseStats.totals.assertions.allOk()) {
40                 stream << "XFAIL";
41             } else {
42                 stream << "FAIL";
43             }
44             stream << ' ' << _testCaseStats.testInfo.name << '\n';
45             StreamingReporterBase::testCaseEnded( _testCaseStats );
46         }
47 
skipTestCatch::AutomakeReporter48         void skipTest( TestCaseInfo const& testInfo ) override {
49             stream << ":test-result: SKIP " << testInfo.name << '\n';
50         }
51 
52     };
53 
54 #ifdef CATCH_IMPL
~AutomakeReporter()55     AutomakeReporter::~AutomakeReporter() {}
56 #endif
57 
58     CATCH_REGISTER_REPORTER( "automake", AutomakeReporter)
59 
60 } // end namespace Catch
61 
62 #endif // TWOBLUECUBES_CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
63