C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
CppSpec::ItBase Class Reference

Base class for it expressions. More...

#include <it_base.hpp>

Inheritance diagram for CppSpec::ItBase:
Collaboration diagram for CppSpec::ItBase:

Public Member Functions

 ItBase (std::source_location location) noexcept
 Create an BaseIt without an explicit description.
 
 ItBase (std::source_location location, const char *description) noexcept
 Create an BaseIt with an explicit description.
 
bool needs_description () noexcept
 Get whether the object needs a description string.
 
std::string get_description () const noexcept
 Get the description string for the it statement.
 
ItBaseset_description (std::string_view description) noexcept
 Set the description string.
 
template<Util::is_not_functional T>
ExpectationValue< T > expect (T value, std::source_location location=std::source_location::current())
 The expect object generator for objects and LiteralTypes.
 
template<Util::is_functional T>
ExpectationFunc< T > expect (T block, std::source_location location=std::source_location::current())
 The expect object generator for lambdas.
 
template<typename T>
ExpectationValue< std::initializer_list< T > > expect (std::initializer_list< T > init_list, std::source_location location=std::source_location::current())
 The expect object generator for initializer lists.
 
template<typename T>
ExpectationValue< T > expect (Let< T > &let, std::source_location location=std::source_location::current())
 The expect object generator for Let.
 
ExpectationValue< std::string > expect (const char *string, std::source_location location=std::source_location::current())
 The expect object generator for const char*.
 
void add_result (const Result &result)
 
std::list< Result > & get_results () noexcept
 
const std::list< Result > & get_results () const noexcept
 
void clear_results () noexcept
 
Result get_result () const override
 
- Public Member Functions inherited from CppSpec::Runnable
 Runnable (std::source_location location)
 
bool has_parent () noexcept
 Check to see if the Runnable has a parent.
 
bool has_parent () const noexcept
 
Runnableget_parent () noexcept
 Get the Runnable's parent.
 
const Runnableget_parent () const noexcept
 
std::list< std::shared_ptr< Runnable > > & get_children () noexcept
 
const std::list< std::shared_ptr< Runnable > > & get_children () const noexcept
 
template<class C>
C * get_parent_as () noexcept
 
template<class C>
const C * get_parent_as () const noexcept
 
template<typename T, typename... Args>
T * make_child (Args &&... args)
 
std::string padding () const noexcept
 Generate padding (indentation) fore the current object.
 
std::source_location get_location () const noexcept
 
void set_location (std::source_location location) noexcept
 
virtual void run ()=0
 
virtual void timed_run ()
 
std::chrono::duration< double > get_runtime () const
 
std::chrono::time_point< std::chrono::system_clock > get_start_time () const
 
size_t num_tests () const noexcept
 
size_t num_failures () const noexcept
 

Detailed Description

Base class for it expressions.

This class is needed to prevent a circular dependency between it.hpp and basematcher.hpp. Matchers need to know whether or not an it has an explicit description string or whether the description should be generated. its need to be able to refer to Expectations, and Expectations need to know about Matchers and execute them. This class is the least common denominator of the it classes, and thus is used to resolve the dependency cycle.

Constructor & Destructor Documentation

◆ ItBase() [1/2]

CppSpec::ItBase::ItBase ( std::source_location location)
inlineexplicitnoexcept

Create an BaseIt without an explicit description.

Returns
the constructed BaseIt

◆ ItBase() [2/2]

CppSpec::ItBase::ItBase ( std::source_location location,
const char * description )
inlineexplicitnoexcept

Create an BaseIt with an explicit description.

Parameters
descriptionthe documentation string of the it statement
Returns
the constructed BaseIt

Member Function Documentation

◆ expect() [1/5]

ExpectationValue< std::string > CppSpec::ItBase::expect ( const char * string,
std::source_location location = std::source_location::current() )
inline

The expect object generator for const char*.

Parameters
stringthe string to wrap
Returns
a ExpectationValue object containing a C++ string

◆ expect() [2/5]

template<typename T>
ExpectationValue< T > CppSpec::ItBase::expect ( Let< T > & let,
std::source_location location = std::source_location::current() )

The expect object generator for Let.

Parameters
blockthe let variable
Template Parameters
Tthe type of the value contained in the ExpectationFunc
Returns
a ExpectationValue object containing the given value.

◆ expect() [3/5]

template<typename T>
ExpectationValue< std::initializer_list< T > > CppSpec::ItBase::expect ( std::initializer_list< T > init_list,
std::source_location location = std::source_location::current() )

The expect object generator for initializer lists.

An expect for initializer_list subjects.

Parameters
init_listthe list to wrap
Template Parameters
Tthe type of the items inside the initializer list
Returns
a ExpectationValue object containing the given init_list.
expect({1,2,3})
ExpectationValue< T > expect(T value, std::source_location location=std::source_location::current())
The expect object generator for objects and LiteralTypes.
Definition it.hpp:129

◆ expect() [4/5]

template<Util::is_functional T>
ExpectationFunc< T > CppSpec::ItBase::expect ( T block,
std::source_location location = std::source_location::current() )

The expect object generator for lambdas.

Parameters
blockthe lambda to wrap.
Template Parameters
Tthe type of the lambda/function contained in the ExpectationFunc
Returns
a ExpectationFunc object containing the given value.

◆ expect() [5/5]

template<Util::is_not_functional T>
ExpectationValue< T > CppSpec::ItBase::expect ( T value,
std::source_location location = std::source_location::current() )

The expect object generator for objects and LiteralTypes.

A simple expect statement.

Parameters
valuethe item to wrap. This parameter is passed by value so that statements like expect(2) or expect(SomeClass()) can be passed in
Template Parameters
Tthe type of the object contained in the ExpectationValue
Returns
a ExpectationValue object containing the given value.
expect(true)
expect([] -> int { return 4; })

◆ get_description()

std::string CppSpec::ItBase::get_description ( ) const
inlinenodiscardnoexcept

Get the description string for the it statement.

Returns
the description string

◆ get_result()

Result CppSpec::ItBase::get_result ( ) const
inlinenodiscardoverridevirtual

Reimplemented from CppSpec::Runnable.

◆ needs_description()

bool CppSpec::ItBase::needs_description ( )
inlinenoexcept

Get whether the object needs a description string.

Returns
whether this object needs a description to be generated or not

◆ set_description()

ItBase & CppSpec::ItBase::set_description ( std::string_view description)
inlinenoexcept

Set the description string.

Returns
a reference to the modified ItBase

The documentation for this class was generated from the following files: