UTPP
Loading...
Searching...
No Matches
reporter_stream.h
Go to the documentation of this file.
1#pragma once
2/*
3 UTPP - A New Generation of UnitTest++
4 (c) Mircea Neacsu 2017-2023
5
6 See LICENSE file for full copyright information.
7*/
8
13
14#include <iostream>
15#include <iomanip>
16
17namespace UnitTest {
18
20class ReporterStream : public Reporter
21{
22public:
23 ReporterStream (std::ostream& strm = std::cout);
24
25protected:
26 void SuiteStart (const TestSuite& suite) override;
27 void TestStart (const Test& test) override;
28 void TestFinish (const Test& test) override;
29 int SuiteFinish (const TestSuite& suite) override;
30
31 void ReportFailure (const Failure& failure) override;
32 int Summary () override;
33
34 std::ostream& out;
35};
36
42inline
44 : out (strm)
45{
46}
47
49inline
51{
53 if (!trace)
54 return;
55 out << "Begin suite: " << suite.name << std::endl;
56}
57
59inline
61{
63 if (!trace)
64 return;
65 out << "Start test: " << test.test_name () << std::endl;
66}
67
69inline
71{
72 if (trace)
73 std::cout << "End test: " << test.test_name () << std::endl;
75}
76
78inline
80{
81 if (trace)
82 out << "End suite: " << suite.name << std::endl;
83 return Reporter::SuiteFinish (suite);
84}
85
86
93inline
95{
96 out << "Failure in ";
97 if (CurrentTest)
98 {
100 out << "suite " << CurrentSuite << ' ';
101 out << "test " << CurrentTest->test_name ();
102 }
103
104#if defined(__APPLE__) || defined(__GNUG__)
105 out << std::endl << failure.filename << ":" << failure.line_number << ": error: "
106 << failure.message << std::endl;
107#else
108 out << std::endl << failure.filename << "(" << failure.line_number << "): error: "
109 << failure.message << std::endl;
110#endif
111 Reporter::ReportFailure (failure);
112}
113
118inline
120{
121 if (total_failed_count > 0)
122 {
123 out << "FAILURE: " << total_failed_count << " out of "
124 << total_test_count << " tests failed (" << total_failures_count
125 << " failures)." << std::endl;
126 }
127 else
128 out << "Success: " << total_test_count << " tests passed." << std::endl;
129
130 out.setf (std::ios::fixed);
131 out << "Run time: " << std::setprecision (2) << total_time_msec / 1000. << std::endl;
132 return Reporter::Summary ();
133}
134
140class ReporterStdout : public ReporterStream
141{
142public:
143 ReporterStdout () : ReporterStream () {};
144};
145
146} //namespace UnitTest
int total_failures_count
total number of failures
Definition utpp.h:317
virtual void SuiteStart(const TestSuite &suite)
Invoked at the beginning of a test suite.
Definition utpp.h:581
virtual void TestStart(const Test &test)
Invoked at the beginning of a test.
Definition utpp.h:588
bool trace
true if tracing is enabled
Definition utpp.h:321
virtual void TestFinish(const Test &test)
Invoked at the end of a test.
Definition utpp.h:600
int total_test_count
total number of tests
Definition utpp.h:315
virtual void ReportFailure(const Failure &failure)
Called when a test has failed.
Definition utpp.h:595
virtual int Summary()
Generate results report.
Definition utpp.h:304
int total_failed_count
total number of failed tests
Definition utpp.h:316
virtual int SuiteFinish(const TestSuite &suite)
Invoked at the end of a test suite.
Definition utpp.h:617
int total_time_msec
total running time in milliseconds
Definition utpp.h:318
void TestFinish(const Test &test) override
If tracing is enabled, show a test finish message.
Definition reporter_stream.h:70
int Summary() override
Definition reporter_stream.h:119
ReporterStream(std::ostream &strm=std::cout)
Definition reporter_stream.h:43
void ReportFailure(const Failure &failure) override
Definition reporter_stream.h:94
void TestStart(const Test &test) override
If tracing is enabled, show a test start message.
Definition reporter_stream.h:60
int SuiteFinish(const TestSuite &suite) override
If tracing is enabled, show a suite finish message.
Definition reporter_stream.h:79
void SuiteStart(const TestSuite &suite) override
If tracing is enabled, show a suite start message.
Definition reporter_stream.h:50
Representation of a test case.
Definition utpp.h:240
const std::string & test_name() const
Return test name.
Definition utpp.h:544
Definition utpp.h:362
std::string name
Suite name.
Definition utpp.h:389
The failure object records the file name, the line number and a message.
Definition utpp.h:271
int line_number
Line number where the failure has occurred.
Definition utpp.h:274
std::string message
Description of failure.
Definition utpp.h:273
std::string filename
Name of file where a failure has occurred.
Definition utpp.h:272
#define DEFAULT_SUITE
Name of default suite.
Definition utpp.h:54
Test * CurrentTest
Currently executing test.
std::string CurrentSuite
Name of currently running suite.