rippled
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
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 >:
Inheritance graph
[legend]
Collaboration diagram for beast::unit_test::detail::reporter< class >:
Collaboration graph
[legend]

Classes

struct  case_results
 
struct  results
 
struct  suite_results
 

Public Member Functions

 reporter (reporter const &)=delete
 
reporteroperator= (reporter const &)=delete
 
 ~reporter ()
 
 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 (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.
 

Private Types

using clock_type = std::chrono::steady_clock
 

Private Member Functions

virtual void on_suite_begin (suite_info const &info) override
 Called when a new suite starts.
 
virtual void on_suite_end () override
 Called when a suite ends.
 
virtual void on_case_begin (std::string const &name) override
 Called when a new case starts.
 
virtual void on_case_end () override
 Called when a new case ends.
 
virtual void on_pass () override
 Called for each passing condition.
 
virtual void on_fail (std::string const &reason) override
 Called for each failing condition.
 
virtual void on_log (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 (typename clock_type::duration const &d)
 

Private Attributes

std::ostreamos_
 
results results_
 
suite_results suite_results_
 
case_results case_results_
 
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 31 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 34 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 _ >
beast::unit_test::detail::reporter< _ >::~reporter ( )

Definition at line 170 of file reporter.h.

◆ reporter() [2/2]

template<class _ >
beast::unit_test::detail::reporter< _ >::reporter ( std::ostream os = std::cout)
explicit

Definition at line 165 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 _ >
std::string beast::unit_test::detail::reporter< _ >::fmtdur ( typename clock_type::duration const &  d)
staticprivate

Definition at line 187 of file reporter.h.

◆ on_suite_begin()

template<class _ >
void beast::unit_test::detail::reporter< _ >::on_suite_begin ( suite_info const &  )
overrideprivatevirtual

Called when a new suite starts.

Reimplemented from beast::unit_test::runner.

Definition at line 200 of file reporter.h.

◆ on_suite_end()

template<class _ >
void beast::unit_test::detail::reporter< _ >::on_suite_end ( )
overrideprivatevirtual

Called when a suite ends.

Reimplemented from beast::unit_test::runner.

Definition at line 207 of file reporter.h.

◆ on_case_begin()

template<class _ >
void beast::unit_test::detail::reporter< _ >::on_case_begin ( std::string const &  )
overrideprivatevirtual

Called when a new case starts.

Reimplemented from beast::unit_test::runner.

Definition at line 214 of file reporter.h.

◆ on_case_end()

template<class _ >
void beast::unit_test::detail::reporter< _ >::on_case_end ( )
overrideprivatevirtual

Called when a new case ends.

Reimplemented from beast::unit_test::runner.

Definition at line 224 of file reporter.h.

◆ on_pass()

template<class _ >
void beast::unit_test::detail::reporter< _ >::on_pass ( )
overrideprivatevirtual

Called for each passing condition.

Reimplemented from beast::unit_test::runner.

Definition at line 231 of file reporter.h.

◆ on_fail()

template<class _ >
void beast::unit_test::detail::reporter< _ >::on_fail ( std::string const &  )
overrideprivatevirtual

Called for each failing condition.

Reimplemented from beast::unit_test::runner.

Definition at line 238 of file reporter.h.

◆ on_log()

template<class _ >
void beast::unit_test::detail::reporter< _ >::on_log ( std::string const &  )
overrideprivatevirtual

Called when a test logs output.

Reimplemented from beast::unit_test::runner.

Definition at line 248 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 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
inherited

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)
inherited

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 
)
inherited

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

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)
inherited

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

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.

◆ testcase()

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

Definition at line 230 of file runner.h.

◆ pass()

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

Definition at line 246 of file runner.h.

◆ fail()

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

Definition at line 257 of file runner.h.

◆ log()

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

Definition at line 269 of file runner.h.

Member Data Documentation

◆ os_

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

Definition at line 80 of file reporter.h.

◆ results_

template<class = void>
results beast::unit_test::detail::reporter< class >::results_
private

Definition at line 81 of file reporter.h.

◆ suite_results_

template<class = void>
suite_results beast::unit_test::detail::reporter< class >::suite_results_
private

Definition at line 82 of file reporter.h.

◆ case_results_

template<class = void>
case_results beast::unit_test::detail::reporter< class >::case_results_
private

Definition at line 83 of file reporter.h.

◆ arg_

std::string beast::unit_test::runner::arg_
privateinherited

Definition at line 25 of file runner.h.

◆ default_

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

Definition at line 26 of file runner.h.

◆ failed_

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

Definition at line 27 of file runner.h.

◆ cond_

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

Definition at line 28 of file runner.h.

◆ mutex_

std::recursive_mutex beast::unit_test::runner::mutex_
privateinherited

Definition at line 29 of file runner.h.