xrpld
Loading...
Searching...
No Matches
beast::unit_test::detail::Reporter< class > Class Template Reference

A simple test runner that writes everything to a stream in real time. More...

#include <reporter.h>

Inheritance diagram for beast::unit_test::detail::Reporter< class >:
Collaboration diagram for beast::unit_test::detail::Reporter< class >:

Classes

struct  CaseResults
struct  SuiteResults
struct  Results

Public Member Functions

 Reporter (Reporter const &)=delete
Reporteroperator= (Reporter const &)=delete
 ~Reporter () override
 Reporter (std::ostream &os=std::cout)
void arg (std::string const &s)
 Set the argument string.
std::string const & arg () const
 Returns the argument string.
template<class = void>
bool run (SuiteInfo const &s)
 Run the specified suite.
template<class FwdIter>
bool run (FwdIter first, FwdIter last)
 Run a sequence of suites.
template<class FwdIter, class Pred>
bool runIf (FwdIter first, FwdIter last, Pred pred=Pred{})
 Conditionally run a sequence of suites.
template<class SequenceContainer>
bool runEach (SequenceContainer const &c)
 Run all suites in a container.
template<class SequenceContainer, class Pred>
bool runEachIf (SequenceContainer const &c, Pred pred=Pred{})
 Conditionally run suites in a container.

Private Types

using clock_type = std::chrono::steady_clock

Private Member Functions

void onSuiteBegin (SuiteInfo const &info) override
 Called when a new suite starts.
void onSuiteEnd () override
 Called when a suite ends.
void onCaseBegin (std::string const &name) override
 Called when a new case starts.
void onCaseEnd () override
 Called when a new case ends.
void onPass () override
 Called for each passing condition.
void onFail (std::string const &reason) override
 Called for each failing condition.
void onLog (std::string const &s) override
 Called when a test logs output.
template<class = void>
void testcase (std::string const &name)
template<class = void>
void pass ()
template<class = void>
void fail (std::string const &reason)
template<class = void>
void log (std::string const &s)

Static Private Member Functions

static std::string fmtdur (clock_type::duration const &d)

Private Attributes

std::ostreamos_
Results results_
SuiteResults suiteResults_
CaseResults caseResults_
std::string arg_
bool default_ = false
bool failed_ = false
bool cond_ = false
std::recursive_mutex mutex_

Detailed Description

template<class = void>
class beast::unit_test::detail::Reporter< class >

A simple test runner that writes everything to a stream in real time.

The totals are output when the object is destroyed.

Definition at line 29 of file reporter.h.

Member Typedef Documentation

◆ clock_type

template<class = void>
using beast::unit_test::detail::Reporter< class >::clock_type = std::chrono::steady_clock
private

Definition at line 32 of file reporter.h.

Constructor & Destructor Documentation

◆ Reporter() [1/2]

template<class = void>
beast::unit_test::detail::Reporter< class >::Reporter ( Reporter< class > const & )
delete

◆ ~Reporter()

template<class Unused>
beast::unit_test::detail::Reporter< Unused >::~Reporter ( )
override

Definition at line 166 of file reporter.h.

◆ Reporter() [2/2]

template<class Unused>
beast::unit_test::detail::Reporter< Unused >::Reporter ( std::ostream & os = std::cout)
explicit

Definition at line 161 of file reporter.h.

Member Function Documentation

◆ operator=()

template<class = void>
Reporter & beast::unit_test::detail::Reporter< class >::operator= ( Reporter< class > const & )
delete

◆ fmtdur()

template<class Unused>
std::string beast::unit_test::detail::Reporter< Unused >::fmtdur ( clock_type::duration const & d)
staticprivate

Definition at line 182 of file reporter.h.

◆ onSuiteBegin()

template<class Unused>
void beast::unit_test::detail::Reporter< Unused >::onSuiteBegin ( SuiteInfo const & )
overrideprivatevirtual

Called when a new suite starts.

Reimplemented from beast::unit_test::Runner.

Definition at line 195 of file reporter.h.

◆ onSuiteEnd()

template<class Unused>
void beast::unit_test::detail::Reporter< Unused >::onSuiteEnd ( )
overrideprivatevirtual

Called when a suite ends.

Reimplemented from beast::unit_test::Runner.

Definition at line 202 of file reporter.h.

◆ onCaseBegin()

template<class Unused>
void beast::unit_test::detail::Reporter< Unused >::onCaseBegin ( std::string const & )
overrideprivatevirtual

Called when a new case starts.

Reimplemented from beast::unit_test::Runner.

Definition at line 209 of file reporter.h.

◆ onCaseEnd()

template<class Unused>
void beast::unit_test::detail::Reporter< Unused >::onCaseEnd ( )
overrideprivatevirtual

Called when a new case ends.

Reimplemented from beast::unit_test::Runner.

Definition at line 218 of file reporter.h.

◆ onPass()

template<class Unused>
void beast::unit_test::detail::Reporter< Unused >::onPass ( )
overrideprivatevirtual

Called for each passing condition.

Reimplemented from beast::unit_test::Runner.

Definition at line 225 of file reporter.h.

◆ onFail()

template<class Unused>
void beast::unit_test::detail::Reporter< Unused >::onFail ( std::string const & )
overrideprivatevirtual

Called for each failing condition.

Reimplemented from beast::unit_test::Runner.

Definition at line 232 of file reporter.h.

◆ onLog()

template<class Unused>
void beast::unit_test::detail::Reporter< Unused >::onLog ( std::string const & )
overrideprivatevirtual

Called when a test logs output.

Reimplemented from beast::unit_test::Runner.

Definition at line 242 of file reporter.h.

◆ arg() [1/2]

void beast::unit_test::Runner::arg ( std::string const & s)
inherited

Set the argument string.

The argument string is available to suites and allows for customization of the test. Each suite defines its own syntax for the argument string. The same argument is passed to all suites.

Definition at line 44 of file runner.h.

◆ arg() [2/2]

std::string const & beast::unit_test::Runner::arg ( ) const
nodiscardinherited

Returns the argument string.

Definition at line 51 of file runner.h.

◆ run() [1/2]

template<class>
bool beast::unit_test::Runner::run ( SuiteInfo const & s)
inherited

Run the specified suite.

Returns
true if any conditions failed.

Definition at line 170 of file runner.h.

◆ run() [2/2]

template<class FwdIter>
bool beast::unit_test::Runner::run ( FwdIter first,
FwdIter last )
inherited

Run a sequence of suites.

The expression FwdIter::value_type must be convertible to SuiteInfo.

Returns
true if any conditions failed.

Definition at line 186 of file runner.h.

◆ runIf()

template<class FwdIter, class Pred>
bool beast::unit_test::Runner::runIf ( FwdIter first,
FwdIter last,
Pred pred = Pred{} )
inherited

Conditionally run a sequence of suites.

pred will be called as:

bool pred(SuiteInfo const&);
Associates a unit test type with metadata.
Definition suite_info.h:18
Returns
true if any conditions failed.

Definition at line 196 of file runner.h.

◆ runEach()

template<class SequenceContainer>
bool beast::unit_test::Runner::runEach ( SequenceContainer const & c)
inherited

Run all suites in a container.

Returns
true if any conditions failed.

Definition at line 209 of file runner.h.

◆ runEachIf()

template<class SequenceContainer, class Pred>
bool beast::unit_test::Runner::runEachIf ( SequenceContainer const & c,
Pred pred = Pred{} )
inherited

Conditionally run suites in a container.

pred will be called as:

bool pred(SuiteInfo const&);
Returns
true if any conditions failed.

Definition at line 219 of file runner.h.

◆ testcase()

template<class>
void beast::unit_test::Runner::testcase ( std::string const & name)
privateinherited

Definition at line 232 of file runner.h.

◆ pass()

template<class>
void beast::unit_test::Runner::pass ( )
privateinherited

Definition at line 248 of file runner.h.

◆ fail()

template<class>
void beast::unit_test::Runner::fail ( std::string const & reason)
privateinherited

Definition at line 259 of file runner.h.

◆ log()

template<class>
void beast::unit_test::Runner::log ( std::string const & s)
privateinherited

Definition at line 271 of file runner.h.

Member Data Documentation

◆ os_

template<class = void>
std::ostream& beast::unit_test::detail::Reporter< class >::os_
private

Definition at line 78 of file reporter.h.

◆ results_

template<class = void>
Results beast::unit_test::detail::Reporter< class >::results_
private

Definition at line 79 of file reporter.h.

◆ suiteResults_

template<class = void>
SuiteResults beast::unit_test::detail::Reporter< class >::suiteResults_
private

Definition at line 80 of file reporter.h.

◆ caseResults_

template<class = void>
CaseResults beast::unit_test::detail::Reporter< class >::caseResults_
private

Definition at line 81 of file reporter.h.

◆ arg_

std::string beast::unit_test::Runner::arg_
privateinherited

Definition at line 23 of file runner.h.

◆ default_

bool beast::unit_test::Runner::default_ = false
privateinherited

Definition at line 24 of file runner.h.

◆ failed_

bool beast::unit_test::Runner::failed_ = false
privateinherited

Definition at line 25 of file runner.h.

◆ cond_

bool beast::unit_test::Runner::cond_ = false
privateinherited

Definition at line 26 of file runner.h.

◆ mutex_

std::recursive_mutex beast::unit_test::Runner::mutex_
privateinherited

Definition at line 27 of file runner.h.