mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Provide CompactReporter declaration with EXTERNAL_INTERFACES
Related to #991
This commit is contained in:
parent
a3cba7a0d5
commit
6acdacfde0
@ -247,6 +247,7 @@ CheckFileList(INTERNAL_FILES ${HEADER_DIR}/internal)
|
|||||||
set(REPORTER_HEADERS
|
set(REPORTER_HEADERS
|
||||||
${HEADER_DIR}/reporters/catch_reporter_automake.hpp
|
${HEADER_DIR}/reporters/catch_reporter_automake.hpp
|
||||||
${HEADER_DIR}/reporters/catch_reporter_bases.hpp
|
${HEADER_DIR}/reporters/catch_reporter_bases.hpp
|
||||||
|
${HEADER_DIR}/reporters/catch_reporter_compact.h
|
||||||
${HEADER_DIR}/reporters/catch_reporter_multi.h
|
${HEADER_DIR}/reporters/catch_reporter_multi.h
|
||||||
${HEADER_DIR}/reporters/catch_reporter_tap.hpp
|
${HEADER_DIR}/reporters/catch_reporter_tap.hpp
|
||||||
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
|
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
|
||||||
|
@ -11,4 +11,7 @@
|
|||||||
#include "catch_console_colour.h"
|
#include "catch_console_colour.h"
|
||||||
#include "catch_reporter_registrars.hpp"
|
#include "catch_reporter_registrars.hpp"
|
||||||
|
|
||||||
|
// Allow users to base their work off existing reporters
|
||||||
|
#include "../reporters/catch_reporter_compact.h"
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_EXTERNAL_INTERFACES_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_EXTERNAL_INTERFACES_H_INCLUDED
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Created by Martin Moene on 2013-12-05.
|
* Created by Martin on 2017-11-14.
|
||||||
* Copyright 2012 Martin Moene. All rights reserved.
|
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "catch_reporter_bases.hpp"
|
#include "catch_reporter_compact.h"
|
||||||
|
|
||||||
#include "../internal/catch_reporter_registrars.hpp"
|
#include "../internal/catch_reporter_registrars.hpp"
|
||||||
#include "internal/catch_console_colour.h"
|
#include "internal/catch_console_colour.h"
|
||||||
@ -28,64 +27,51 @@ namespace {
|
|||||||
return count == 1 ? std::string() :
|
return count == 1 ? std::string() :
|
||||||
count == 2 ? "both " : "all " ;
|
count == 2 ? "both " : "all " ;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
} // anon namespace
|
||||||
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
namespace {
|
||||||
struct CompactReporter : StreamingReporterBase<CompactReporter> {
|
// Colour, message variants:
|
||||||
|
// - white: No tests ran.
|
||||||
using StreamingReporterBase::StreamingReporterBase;
|
// - red: Failed [both/all] N test cases, failed [both/all] M assertions.
|
||||||
|
// - white: Passed [both/all] N test cases (no assertions).
|
||||||
~CompactReporter() override;
|
// - red: Failed N tests cases, failed M assertions.
|
||||||
|
// - green: Passed [both/all] N tests cases with M assertions.
|
||||||
static std::string getDescription() {
|
void printTotals(std::ostream& out, const Totals& totals) {
|
||||||
return "Reports test results on a single line, suitable for IDEs";
|
if (totals.testCases.total() == 0) {
|
||||||
}
|
out << "No tests ran.";
|
||||||
|
} else if (totals.testCases.failed == totals.testCases.total()) {
|
||||||
ReporterPreferences getPreferences() const override {
|
Colour colour(Colour::ResultError);
|
||||||
ReporterPreferences prefs;
|
const std::string qualify_assertions_failed =
|
||||||
prefs.shouldRedirectStdOut = false;
|
totals.assertions.failed == totals.assertions.total() ?
|
||||||
return prefs;
|
bothOrAll(totals.assertions.failed) : std::string();
|
||||||
}
|
out <<
|
||||||
|
"Failed " << bothOrAll(totals.testCases.failed)
|
||||||
void noMatchingTestCases( std::string const& spec ) override {
|
<< pluralise(totals.testCases.failed, "test case") << ", "
|
||||||
stream << "No test cases matched '" << spec << '\'' << std::endl;
|
"failed " << qualify_assertions_failed <<
|
||||||
}
|
pluralise(totals.assertions.failed, "assertion") << '.';
|
||||||
|
} else if (totals.assertions.total() == 0) {
|
||||||
void assertionStarting( AssertionInfo const& ) override {}
|
out <<
|
||||||
|
"Passed " << bothOrAll(totals.testCases.total())
|
||||||
bool assertionEnded( AssertionStats const& _assertionStats ) override {
|
<< pluralise(totals.testCases.total(), "test case")
|
||||||
AssertionResult const& result = _assertionStats.assertionResult;
|
<< " (no assertions).";
|
||||||
|
} else if (totals.assertions.failed) {
|
||||||
bool printInfoMessages = true;
|
Colour colour(Colour::ResultError);
|
||||||
|
out <<
|
||||||
// Drop out if result was successful and we're not printing those
|
"Failed " << pluralise(totals.testCases.failed, "test case") << ", "
|
||||||
if( !m_config->includeSuccessfulResults() && result.isOk() ) {
|
"failed " << pluralise(totals.assertions.failed, "assertion") << '.';
|
||||||
if( result.getResultType() != ResultWas::Warning )
|
} else {
|
||||||
return false;
|
Colour colour(Colour::ResultSuccess);
|
||||||
printInfoMessages = false;
|
out <<
|
||||||
}
|
"Passed " << bothOrAll(totals.testCases.passed)
|
||||||
|
<< pluralise(totals.testCases.passed, "test case") <<
|
||||||
AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
|
" with " << pluralise(totals.assertions.passed, "assertion") << '.';
|
||||||
printer.print();
|
|
||||||
|
|
||||||
stream << std::endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sectionEnded(SectionStats const& _sectionStats) override {
|
|
||||||
if (m_config->showDurations() == ShowDurations::Always) {
|
|
||||||
stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void testRunEnded( TestRunStats const& _testRunStats ) override {
|
// Implementation of CompactReporter formatting
|
||||||
printTotals( _testRunStats.totals );
|
|
||||||
stream << '\n' << std::endl;
|
|
||||||
StreamingReporterBase::testRunEnded( _testRunStats );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
class AssertionPrinter {
|
class AssertionPrinter {
|
||||||
public:
|
public:
|
||||||
AssertionPrinter& operator= (AssertionPrinter const&) = delete;
|
AssertionPrinter& operator= (AssertionPrinter const&) = delete;
|
||||||
@ -95,8 +81,7 @@ namespace Catch {
|
|||||||
, result(_stats.assertionResult)
|
, result(_stats.assertionResult)
|
||||||
, messages(_stats.infoMessages)
|
, messages(_stats.infoMessages)
|
||||||
, itMessage(_stats.infoMessages.begin())
|
, itMessage(_stats.infoMessages.begin())
|
||||||
, printInfoMessages( _printInfoMessages )
|
, printInfoMessages(_printInfoMessages) {}
|
||||||
{}
|
|
||||||
|
|
||||||
void print() {
|
void print() {
|
||||||
printSourceInfo();
|
printSourceInfo();
|
||||||
@ -253,49 +238,54 @@ namespace Catch {
|
|||||||
bool printInfoMessages;
|
bool printInfoMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Colour, message variants:
|
} // anon namespace
|
||||||
// - white: No tests ran.
|
|
||||||
// - red: Failed [both/all] N test cases, failed [both/all] M assertions.
|
|
||||||
// - white: Passed [both/all] N test cases (no assertions).
|
|
||||||
// - red: Failed N tests cases, failed M assertions.
|
|
||||||
// - green: Passed [both/all] N tests cases with M assertions.
|
|
||||||
|
|
||||||
void printTotals( const Totals& totals ) const {
|
std::string CompactReporter::getDescription() {
|
||||||
if( totals.testCases.total() == 0 ) {
|
return "Reports test results on a single line, suitable for IDEs";
|
||||||
stream << "No tests ran.";
|
|
||||||
}
|
}
|
||||||
else if( totals.testCases.failed == totals.testCases.total() ) {
|
|
||||||
Colour colour( Colour::ResultError );
|
ReporterPreferences CompactReporter::getPreferences() const {
|
||||||
const std::string qualify_assertions_failed =
|
ReporterPreferences prefs;
|
||||||
totals.assertions.failed == totals.assertions.total() ?
|
prefs.shouldRedirectStdOut = false;
|
||||||
bothOrAll( totals.assertions.failed ) : std::string();
|
return prefs;
|
||||||
stream <<
|
|
||||||
"Failed " << bothOrAll( totals.testCases.failed )
|
|
||||||
<< pluralise( totals.testCases.failed, "test case" ) << ", "
|
|
||||||
"failed " << qualify_assertions_failed <<
|
|
||||||
pluralise( totals.assertions.failed, "assertion" ) << '.';
|
|
||||||
}
|
}
|
||||||
else if( totals.assertions.total() == 0 ) {
|
|
||||||
stream <<
|
void CompactReporter::noMatchingTestCases( std::string const& spec ) {
|
||||||
"Passed " << bothOrAll( totals.testCases.total() )
|
stream << "No test cases matched '" << spec << '\'' << std::endl;
|
||||||
<< pluralise( totals.testCases.total(), "test case" )
|
|
||||||
<< " (no assertions).";
|
|
||||||
}
|
}
|
||||||
else if( totals.assertions.failed ) {
|
|
||||||
Colour colour( Colour::ResultError );
|
void CompactReporter::assertionStarting( AssertionInfo const& ) {}
|
||||||
stream <<
|
|
||||||
"Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
|
bool CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) {
|
||||||
"failed " << pluralise( totals.assertions.failed, "assertion" ) << '.';
|
AssertionResult const& result = _assertionStats.assertionResult;
|
||||||
|
|
||||||
|
bool printInfoMessages = true;
|
||||||
|
|
||||||
|
// Drop out if result was successful and we're not printing those
|
||||||
|
if( !m_config->includeSuccessfulResults() && result.isOk() ) {
|
||||||
|
if( result.getResultType() != ResultWas::Warning )
|
||||||
|
return false;
|
||||||
|
printInfoMessages = false;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Colour colour( Colour::ResultSuccess );
|
AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
|
||||||
stream <<
|
printer.print();
|
||||||
"Passed " << bothOrAll( totals.testCases.passed )
|
|
||||||
<< pluralise( totals.testCases.passed, "test case" ) <<
|
stream << std::endl;
|
||||||
" with " << pluralise( totals.assertions.passed, "assertion" ) << '.';
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompactReporter::sectionEnded(SectionStats const& _sectionStats) {
|
||||||
|
if (m_config->showDurations() == ShowDurations::Always) {
|
||||||
|
stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
void CompactReporter::testRunEnded( TestRunStats const& _testRunStats ) {
|
||||||
|
printTotals( stream, _testRunStats.totals );
|
||||||
|
stream << '\n' << std::endl;
|
||||||
|
StreamingReporterBase::testRunEnded( _testRunStats );
|
||||||
|
}
|
||||||
|
|
||||||
CompactReporter::~CompactReporter() {}
|
CompactReporter::~CompactReporter() {}
|
||||||
|
|
||||||
|
41
include/reporters/catch_reporter_compact.h
Normal file
41
include/reporters/catch_reporter_compact.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin Moene on 2013-12-05.
|
||||||
|
* Copyright 2012 Martin Moene. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_REPORTER_COMPACT_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_REPORTER_COMPACT_H_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
|
#include "catch_reporter_bases.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct CompactReporter : StreamingReporterBase<CompactReporter> {
|
||||||
|
|
||||||
|
using StreamingReporterBase::StreamingReporterBase;
|
||||||
|
|
||||||
|
~CompactReporter() override;
|
||||||
|
|
||||||
|
static std::string getDescription();
|
||||||
|
|
||||||
|
ReporterPreferences getPreferences() const override;
|
||||||
|
|
||||||
|
void noMatchingTestCases(std::string const& spec) override;
|
||||||
|
|
||||||
|
void assertionStarting(AssertionInfo const&) override;
|
||||||
|
|
||||||
|
bool assertionEnded(AssertionStats const& _assertionStats) override;
|
||||||
|
|
||||||
|
void sectionEnded(SectionStats const& _sectionStats) override;
|
||||||
|
|
||||||
|
void testRunEnded(TestRunStats const& _testRunStats) override;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_REPORTER_COMPACT_H_INCLUDED
|
Loading…
Reference in New Issue
Block a user