rippled
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
beast::unit_test::runner Class Reference

Unit test runner interface. More...

#include <runner.h>

Inheritance diagram for beast::unit_test::runner:
Inheritance graph
[legend]
Collaboration diagram for beast::unit_test::runner:
Collaboration graph
[legend]

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 (suite_info 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 run_if (FwdIter first, FwdIter last, Pred pred=Pred{})
 Conditionally run a sequence of suites.
 
template<class SequenceContainer >
bool run_each (SequenceContainer const &c)
 Run all suites in a container.
 
template<class SequenceContainer , class Pred >
bool run_each_if (SequenceContainer const &c, Pred pred=Pred{})
 Conditionally run suites in a container.
 

Protected Member Functions

virtual void on_suite_begin (suite_info const &)
 Called when a new suite starts.
 
virtual void on_suite_end ()
 Called when a suite ends.
 
virtual void on_case_begin (std::string const &)
 Called when a new case starts.
 
virtual void on_case_end ()
 Called when a new case ends.
 
virtual void on_pass ()
 Called for each passing condition.
 
virtual void on_fail (std::string const &)
 Called for each failing condition.
 
virtual void on_log (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 23 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 argumnet string. The same argument is passed to all suites.

Definition at line 46 of file runner.h.

◆ arg() [2/2]

std::string const & beast::unit_test::runner::arg ( ) const

Returns the argument string.

Definition at line 53 of file runner.h.

◆ run() [1/2]

template<class >
bool beast::unit_test::runner::run ( suite_info const &  s)

Run the specified suite.

Returns
true if any conditions failed.

Definition at line 172 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 suite_info.

Returns
true if any conditions failed.

Definition at line 188 of file runner.h.

◆ run_if()

template<class FwdIter , class Pred >
bool beast::unit_test::runner::run_if ( FwdIter  first,
FwdIter  last,
Pred  pred = Pred{} 
)

Conditionally run a sequence of suites.

pred will be called as:

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

Definition at line 198 of file runner.h.

◆ run_each()

template<class SequenceContainer >
bool beast::unit_test::runner::run_each ( SequenceContainer const &  c)

Run all suites in a container.

Returns
true if any conditions failed.

Definition at line 209 of file runner.h.

◆ run_each_if()

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

Conditionally run suites in a container.

pred will be called as:

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

Definition at line 219 of file runner.h.

◆ on_suite_begin()

virtual void beast::unit_test::runner::on_suite_begin ( suite_info const &  )
protectedvirtual

Called when a new suite starts.

Reimplemented in ripple::test::multi_runner_child, beast::unit_test::recorder, and beast::unit_test::detail::reporter< class >.

Definition at line 107 of file runner.h.

◆ on_suite_end()

virtual void beast::unit_test::runner::on_suite_end ( )
protectedvirtual

Called when a suite ends.

Reimplemented in beast::unit_test::recorder, beast::unit_test::detail::reporter< class >, and ripple::test::multi_runner_child.

Definition at line 113 of file runner.h.

◆ on_case_begin()

virtual void beast::unit_test::runner::on_case_begin ( std::string const &  )
protectedvirtual

Called when a new case starts.

Reimplemented in beast::unit_test::recorder, beast::unit_test::detail::reporter< class >, and ripple::test::multi_runner_child.

Definition at line 119 of file runner.h.

◆ on_case_end()

virtual void beast::unit_test::runner::on_case_end ( )
protectedvirtual

Called when a new case ends.

Reimplemented in beast::unit_test::recorder, beast::unit_test::detail::reporter< class >, and ripple::test::multi_runner_child.

Definition at line 125 of file runner.h.

◆ on_pass()

virtual void beast::unit_test::runner::on_pass ( )
protectedvirtual

Called for each passing condition.

Reimplemented in beast::unit_test::recorder, beast::unit_test::detail::reporter< class >, and ripple::test::multi_runner_child.

Definition at line 131 of file runner.h.

◆ on_fail()

virtual void beast::unit_test::runner::on_fail ( std::string const &  )
protectedvirtual

Called for each failing condition.

Reimplemented in beast::unit_test::recorder, beast::unit_test::detail::reporter< class >, and ripple::test::multi_runner_child.

Definition at line 137 of file runner.h.

◆ on_log()

virtual void beast::unit_test::runner::on_log ( std::string const &  )
protectedvirtual

Called when a test logs output.

Reimplemented in beast::unit_test::recorder, beast::unit_test::detail::reporter< class >, and ripple::test::multi_runner_child.

Definition at line 143 of file runner.h.

◆ testcase()

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

Definition at line 230 of file runner.h.

◆ pass()

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

Definition at line 246 of file runner.h.

◆ fail()

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

Definition at line 257 of file runner.h.

◆ log()

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

Definition at line 269 of file runner.h.

Friends And Related Symbol Documentation

◆ suite

friend class suite
friend

Definition at line 148 of file runner.h.

Member Data Documentation

◆ arg_

std::string beast::unit_test::runner::arg_
private

Definition at line 25 of file runner.h.

◆ default_

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

Definition at line 26 of file runner.h.

◆ failed_

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

Definition at line 27 of file runner.h.

◆ cond_

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

Definition at line 28 of file runner.h.

◆ mutex_

std::recursive_mutex beast::unit_test::runner::mutex_
private

Definition at line 29 of file runner.h.