15#ifdef CATCH_PLATFORM_MAC
16 const char* failedString() {
return "FAILED"; }
17 const char* passedString() {
return "PASSED"; }
19 const char* failedString() {
return "failed"; }
20 const char* passedString() {
return "passed"; }
26 std::string bothOrAll( std::size_t
count ) {
27 return count == 1 ? std::string() :
28 count == 2 ?
"both " :
"all " ;
42void printTotals(std::ostream& out,
const Totals& totals) {
43 if (totals.testCases.total() == 0) {
44 out <<
"No tests ran.";
45 }
else if (totals.testCases.failed == totals.testCases.total()) {
47 const std::string qualify_assertions_failed =
48 totals.assertions.failed == totals.assertions.total() ?
49 bothOrAll(totals.assertions.failed) :
std::string();
51 "Failed " << bothOrAll(totals.testCases.failed)
52 << pluralise(totals.testCases.failed,
"test case") <<
", "
53 "failed " << qualify_assertions_failed <<
54 pluralise(totals.assertions.failed,
"assertion") <<
'.';
55 }
else if (totals.assertions.total() == 0) {
57 "Passed " << bothOrAll(totals.testCases.total())
58 << pluralise(totals.testCases.total(),
"test case")
59 <<
" (no assertions).";
60 }
else if (totals.assertions.failed) {
63 "Failed " << pluralise(totals.testCases.failed,
"test case") <<
", "
64 "failed " << pluralise(totals.assertions.failed,
"assertion") <<
'.';
68 "Passed " << bothOrAll(totals.testCases.passed)
69 << pluralise(totals.testCases.passed,
"test case") <<
70 " with " << pluralise(totals.assertions.passed,
"assertion") <<
'.';
75class AssertionPrinter {
77 AssertionPrinter& operator= (AssertionPrinter
const&) =
delete;
78 AssertionPrinter(AssertionPrinter
const&) =
delete;
79 AssertionPrinter(std::ostream& _stream, AssertionStats
const& _stats,
bool _printInfoMessages)
81 , result(_stats.assertionResult)
82 , messages(_stats.infoMessages)
83 , itMessage(_stats.infoMessages.begin())
84 , printInfoMessages(_printInfoMessages) {}
89 itMessage = messages.begin();
91 switch (result.getResultType()) {
94 printOriginalExpression();
95 printReconstructedExpression();
96 if (!result.hasExpression())
99 printRemainingMessages();
106 printOriginalExpression();
107 printReconstructedExpression();
108 printRemainingMessages();
112 printIssue(
"unexpected exception with message:");
114 printExpressionWas();
115 printRemainingMessages();
119 printIssue(
"fatal error condition with message:");
121 printExpressionWas();
122 printRemainingMessages();
126 printIssue(
"expected exception, got none");
127 printExpressionWas();
128 printRemainingMessages();
133 printRemainingMessages();
138 printRemainingMessages();
142 printIssue(
"explicitly");
155 void printSourceInfo()
const {
157 stream << result.getSourceInfo() <<
':';
160 void printResultType(
Colour::Code colour, std::string
const& passOrFail)
const {
161 if (!passOrFail.empty()) {
163 Colour colourGuard(colour);
164 stream <<
' ' << passOrFail;
170 void printIssue(std::string
const& issue)
const {
171 stream <<
' ' << issue;
174 void printExpressionWas() {
175 if (result.hasExpression()) {
178 Colour colour(dimColour());
179 stream <<
" expression was:";
181 printOriginalExpression();
185 void printOriginalExpression()
const {
186 if (result.hasExpression()) {
187 stream <<
' ' << result.getExpression();
191 void printReconstructedExpression()
const {
192 if (result.hasExpandedExpression()) {
194 Colour colour(dimColour());
197 stream << result.getExpandedExpression();
201 void printMessage() {
202 if (itMessage != messages.end()) {
203 stream <<
" '" << itMessage->message <<
'\'';
208 void printRemainingMessages(
Colour::Code colour = dimColour()) {
209 if (itMessage == messages.end())
213 std::vector<MessageInfo>::const_iterator itEnd = messages.end();
214 const std::size_t
N =
static_cast<std::size_t
>(std::distance(itMessage, itEnd));
217 Colour colourGuard(colour);
218 stream <<
" with " << pluralise(
N,
"message") <<
':';
221 for (; itMessage != itEnd; ) {
224 stream <<
" '" << itMessage->message <<
'\'';
225 if (++itMessage != itEnd) {
226 Colour colourGuard(dimColour());
234 std::ostream& stream;
235 AssertionResult
const& result;
236 std::vector<MessageInfo> messages;
237 std::vector<MessageInfo>::const_iterator itMessage;
238 bool printInfoMessages;
244 return "Reports test results on a single line, suitable for IDEs";
252 stream <<
"No test cases matched '" << spec <<
'\'' << std::endl;
260 bool printInfoMessages =
true;
263 if( !
m_config->includeSuccessfulResults() && result.isOk() ) {
266 printInfoMessages =
false;
269 AssertionPrinter printer(
stream, _assertionStats, printInfoMessages );
284 stream <<
'\n' << std::endl;
void print(std::ostream &os, int const level, std::string const &title, Catch::SourceLineInfo const &info)
#define CATCH_REGISTER_REPORTER(name, reporterType)
std::string getFormattedDuration(double duration)
AssertionResult assertionResult
void noMatchingTestCases(std::string const &spec) override
static std::string getDescription()
void assertionStarting(AssertionInfo const &) override
void sectionEnded(SectionStats const &_sectionStats) override
ReporterPreferences getPreferences() const override
~CompactReporter() override
void testRunEnded(TestRunStats const &_testRunStats) override
bool assertionEnded(AssertionStats const &_assertionStats) override
void testRunEnded(TestRunStats const &) override
ReporterPreferences m_reporterPrefs