xrpld
Loading...
Searching...
No Matches
beast::unit_test::Runner Class Reference

Unit test runner interface. More...

#include <runner.h>

Inheritance diagram for beast::unit_test::Runner:
Collaboration diagram for beast::unit_test::Runner:

Public Member Functions

 Runner ()=default
virtual ~Runner ()=default
 Runner (Runner const &)=delete
Runneroperator= (Runner const &)=delete
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.

Protected Member Functions

virtual void onSuiteBegin (SuiteInfo const &)
 Called when a new suite starts.
virtual void onSuiteEnd ()
 Called when a suite ends.
virtual void onCaseBegin (std::string const &)
 Called when a new case starts.
virtual void onCaseEnd ()
 Called when a new case ends.
virtual void onPass ()
 Called for each passing condition.
virtual void onFail (std::string const &)
 Called for each failing condition.
virtual void onLog (std::string const &)
 Called when a test logs output.

Private Member Functions

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)

Private Attributes

std::string arg_
bool default_ = false
bool failed_ = false
bool cond_ = false
std::recursive_mutex mutex_

Friends

class Suite

Detailed Description

Unit test runner interface.

Derived classes can customize the reporting behavior. This interface is injected into the unit_test class to receive the results of the tests.

Definition at line 21 of file runner.h.

Constructor & Destructor Documentation

◆ Runner() [1/2]

beast::unit_test::Runner::Runner ( )
default

◆ ~Runner()

virtual beast::unit_test::Runner::~Runner ( )
virtualdefault

◆ Runner() [2/2]

beast::unit_test::Runner::Runner ( Runner const & )
delete

Member Function Documentation

◆ operator=()

Runner & beast::unit_test::Runner::operator= ( Runner const & )
delete

◆ arg() [1/2]

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

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
nodiscard

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)

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 )

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{} )

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)

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{} )

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.

◆ onSuiteBegin()

virtual void beast::unit_test::Runner::onSuiteBegin ( SuiteInfo const & )
protectedvirtual

Called when a new suite starts.

Reimplemented in beast::unit_test::detail::Reporter< class >, beast::unit_test::Recorder, and xrpl::test::MultiRunnerChild.

Definition at line 105 of file runner.h.

◆ onSuiteEnd()

virtual void beast::unit_test::Runner::onSuiteEnd ( )
protectedvirtual

Called when a suite ends.

Reimplemented in beast::unit_test::detail::Reporter< class >, beast::unit_test::Recorder, and xrpl::test::MultiRunnerChild.

Definition at line 111 of file runner.h.

◆ onCaseBegin()

virtual void beast::unit_test::Runner::onCaseBegin ( std::string const & )
protectedvirtual

Called when a new case starts.

Reimplemented in beast::unit_test::detail::Reporter< class >, beast::unit_test::Recorder, and xrpl::test::MultiRunnerChild.

Definition at line 117 of file runner.h.

◆ onCaseEnd()

virtual void beast::unit_test::Runner::onCaseEnd ( )
protectedvirtual

Called when a new case ends.

Reimplemented in beast::unit_test::detail::Reporter< class >, beast::unit_test::Recorder, and xrpl::test::MultiRunnerChild.

Definition at line 123 of file runner.h.

◆ onPass()

virtual void beast::unit_test::Runner::onPass ( )
protectedvirtual

Called for each passing condition.

Reimplemented in beast::unit_test::detail::Reporter< class >, beast::unit_test::Recorder, and xrpl::test::MultiRunnerChild.

Definition at line 129 of file runner.h.

◆ onFail()

virtual void beast::unit_test::Runner::onFail ( std::string const & )
protectedvirtual

Called for each failing condition.

Reimplemented in beast::unit_test::detail::Reporter< class >, beast::unit_test::Recorder, and xrpl::test::MultiRunnerChild.

Definition at line 135 of file runner.h.

◆ onLog()

virtual void beast::unit_test::Runner::onLog ( std::string const & )
protectedvirtual

Called when a test logs output.

Reimplemented in beast::unit_test::detail::Reporter< class >, beast::unit_test::Recorder, and xrpl::test::MultiRunnerChild.

Definition at line 141 of file runner.h.

◆ testcase()

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

Definition at line 232 of file runner.h.

◆ pass()

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

Definition at line 248 of file runner.h.

◆ fail()

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

Definition at line 259 of file runner.h.

◆ log()

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

Definition at line 271 of file runner.h.

◆ Suite

friend class Suite
friend

Definition at line 146 of file runner.h.

Member Data Documentation

◆ arg_

std::string beast::unit_test::Runner::arg_
private

Definition at line 23 of file runner.h.

◆ default_

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

Definition at line 24 of file runner.h.

◆ failed_

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

Definition at line 25 of file runner.h.

◆ cond_

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

Definition at line 26 of file runner.h.

◆ mutex_

std::recursive_mutex beast::unit_test::Runner::mutex_
private

Definition at line 27 of file runner.h.