Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
SpecsCpp::SpecGroup Class Reference

#include <SpecGroup.h>

Inheritance diagram for SpecsCpp::SpecGroup:
SpecsCpp::ISpecGroup SpecsCpp::SpecComponent SpecsCpp::SpecDocumented SpecsCpp::ISpecComponent SpecsCpp::ISpecDocumented SpecsCpp::ISpecHasVariables SpecsCpp::ISpecComponent SpecsCpp::ISpecDocumented

Public Member Functions

 SpecGroup (ISpecGroup *parent=nullptr, std::string_view description="")
 
 SpecGroup (std::string_view description)
 
void foreach_group (ForEachGroupFn *callback) const override
 
void foreach_test (ForEachSpecFn *callback) const override
 
void foreach_setup (ForEachSetupFn *callback) const override
 
void foreach_teardown (ForEachTeardownFn *callback) const override
 
void foreach_one_time_setup (ForEachSetupFn *callback) const override
 
void foreach_one_time_teardown (ForEachTeardownFn *callback) const override
 
void add_group (ISpecGroup *group) override
 
void add_test (ISpec *spec) override
 
void add_setup (ISpecSetup *setup) override
 
void add_teardown (ISpecTeardown *teardown) override
 
void add_one_time_setup (ISpecSetup *setup) override
 
void add_one_time_teardown (ISpecTeardown *teardown) override
 
const char * full_description () const override
 
void merge (ISpecGroup *other) override
 
ISpecVariableCollectionvariables () const override
 
- Public Member Functions inherited from SpecsCpp::ISpecGroup
virtual ~ISpecGroup ()=default
 
virtual void add_group (ISpecGroup *)=0
 
virtual void add_test (ISpec *)=0
 
virtual void add_setup (ISpecSetup *)=0
 
virtual void add_teardown (ISpecTeardown *)=0
 
virtual void add_one_time_setup (ISpecSetup *)=0
 
virtual void add_one_time_teardown (ISpecTeardown *)=0
 
virtual void foreach_group (ForEachGroupFn *) const =0
 
virtual void foreach_test (ForEachSpecFn *) const =0
 
virtual void foreach_setup (ForEachSetupFn *) const =0
 
virtual void foreach_teardown (ForEachTeardownFn *) const =0
 
virtual void foreach_one_time_setup (ForEachSetupFn *) const =0
 
virtual void foreach_one_time_teardown (ForEachTeardownFn *) const =0
 
virtual void merge (ISpecGroup *)=0
 
void foreach_group (std::function< void(ISpecGroup *)> fn) const
 
void foreach_test (std::function< void(ISpec *)> fn) const
 
void foreach_setup (std::function< void(ISpecSetup *)> fn) const
 
void foreach_teardown (std::function< void(ISpecTeardown *)> fn) const
 
void foreach_one_time_setup (std::function< void(ISpecSetup *)> fn) const
 
void foreach_one_time_teardown (std::function< void(ISpecTeardown *)> fn) const
 
- Public Member Functions inherited from SpecsCpp::ISpecComponent
virtual ~ISpecComponent ()=default
 
virtual ISpecGroupgroup () const =0
 
virtual void set_group (ISpecGroup *group)=0
 
virtual ISpecDataValueCollectiondata () const =0
 
virtual ISpecTagCollectiontags () const =0
 
virtual SpecComponentType type () const =0
 
virtual bool skip () const =0
 
virtual void mark_skipped (bool skip=true)=0
 
- Public Member Functions inherited from SpecsCpp::ISpecDocumented
virtual ~ISpecDocumented ()=default
 
virtual const char * description () const =0
 
virtual const char * full_description () const =0
 
- Public Member Functions inherited from SpecsCpp::ISpecHasVariables
virtual ~ISpecHasVariables ()=default
 
virtual ISpecVariableCollectionvariables () const =0
 
ISpecVariableCollectionvars () const
 
bool has_var (const char *name) const
 
IVoidPointer * var (const char *name) const
 
template<typename T >
var (const char *name) const
 
template<typename T >
T * var (const char *name, T *value, bool destructable=true)
 
template<typename T >
void var (const char *name, T &&value, bool destructable=true)
 
template<typename T >
T * managed_var (const char *name, T *value)
 
template<typename T >
void managed_var (const char *name, T &&value)
 
template<typename T >
T * unmanaged_var (const char *name, T *value)
 
template<typename T >
void unmanaged_var (const char *name, T &&value)
 
const char * var_text (const char *name)
 
const char * var_text (const char *name, const char *value)
 
- Public Member Functions inherited from SpecsCpp::SpecComponent
 SpecComponent (SpecComponentType type, ISpecGroup *parentGroup, bool skip=false)
 
ISpecGroupgroup () const override
 
void set_group (ISpecGroup *group) override
 
ISpecDataValueCollectiondata () const override
 
ISpecTagCollectiontags () const override
 
SpecComponentType type () const override
 
bool skip () const override
 
void mark_skipped (bool skip=true) override
 
- Public Member Functions inherited from SpecsCpp::SpecDocumented
 SpecDocumented (std::string_view description)
 
const char * description () const override
 

Additional Inherited Members

- Public Types inherited from SpecsCpp::ISpecGroup
using ForEachGroupFn = IFunctionPointer< void(ISpecGroup *)>
 
using ForEachSpecFn = IFunctionPointer< void(ISpec *)>
 
using ForEachSetupFn = IFunctionPointer< void(ISpecSetup *)>
 
using ForEachTeardownFn = IFunctionPointer< void(ISpecTeardown *)>
 

Detailed Description

Definition at line 15 of file SpecGroup.h.

Constructor & Destructor Documentation

◆ SpecGroup() [1/2]

SpecsCpp::SpecGroup::SpecGroup ( ISpecGroup parent = nullptr,
std::string_view  description = "" 
)
inline

Definition at line 48 of file SpecGroup.h.

51 _variables(std::make_unique<SpecVariableCollection>(parent)) {
52 if (parent == nullptr || strlen(parent->full_description()) == 0)
53 _fullDescription = description;
54 else
55 _fullDescription =
56 string_format("{} > {}", parent->full_description(), description);
57 }
SpecComponent(SpecComponentType type, ISpecGroup *parentGroup, bool skip=false)
SpecDocumented(std::string_view description)
const char * description() const override

◆ SpecGroup() [2/2]

SpecsCpp::SpecGroup::SpecGroup ( std::string_view  description)
inline

Definition at line 59 of file SpecGroup.h.

59: SpecGroup(nullptr, description) {}
SpecGroup(ISpecGroup *parent=nullptr, std::string_view description="")
Definition SpecGroup.h:48

Member Function Documentation

◆ add_group()

void SpecsCpp::SpecGroup::add_group ( ISpecGroup group)
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 85 of file SpecGroup.h.

85{ _childGroups.push_back(group); }
ISpecGroup * group() const override

◆ add_one_time_setup()

void SpecsCpp::SpecGroup::add_one_time_setup ( ISpecSetup setup)
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 89 of file SpecGroup.h.

89{ _oneTimeSetups.push_back(setup); }

◆ add_one_time_teardown()

void SpecsCpp::SpecGroup::add_one_time_teardown ( ISpecTeardown teardown)
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 90 of file SpecGroup.h.

90 {
91 _oneTimeTeardowns.push_back(teardown);
92 }

◆ add_setup()

void SpecsCpp::SpecGroup::add_setup ( ISpecSetup setup)
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 87 of file SpecGroup.h.

87{ _setups.push_back(setup); }

◆ add_teardown()

void SpecsCpp::SpecGroup::add_teardown ( ISpecTeardown teardown)
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 88 of file SpecGroup.h.

88{ _teardowns.push_back(teardown); }

◆ add_test()

void SpecsCpp::SpecGroup::add_test ( ISpec spec)
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 86 of file SpecGroup.h.

86{ _specs.push_back(spec); }

◆ foreach_group()

void SpecsCpp::SpecGroup::foreach_group ( ForEachGroupFn callback) const
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 61 of file SpecGroup.h.

61 {
62 for (auto* group : _childGroups) callback->invoke(group);
63 }

◆ foreach_one_time_setup()

void SpecsCpp::SpecGroup::foreach_one_time_setup ( ForEachSetupFn callback) const
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 77 of file SpecGroup.h.

77 {
78 for (auto* setup : _oneTimeSetups) callback->invoke(setup);
79 }
void setup(std::function< void()> body)
Definition setup.h:12

◆ foreach_one_time_teardown()

void SpecsCpp::SpecGroup::foreach_one_time_teardown ( ForEachTeardownFn callback) const
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 81 of file SpecGroup.h.

81 {
82 for (auto* teardown : _oneTimeTeardowns) callback->invoke(teardown);
83 }
void teardown(std::function< void()> body)
Definition teardown.h:12

◆ foreach_setup()

void SpecsCpp::SpecGroup::foreach_setup ( ForEachSetupFn callback) const
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 69 of file SpecGroup.h.

69 {
70 for (auto* setup : _setups) callback->invoke(setup);
71 }

◆ foreach_teardown()

void SpecsCpp::SpecGroup::foreach_teardown ( ForEachTeardownFn callback) const
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 73 of file SpecGroup.h.

73 {
74 for (auto* teardown : _teardowns) callback->invoke(teardown);
75 }

◆ foreach_test()

void SpecsCpp::SpecGroup::foreach_test ( ForEachSpecFn callback) const
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 65 of file SpecGroup.h.

65 {
66 for (auto* spec : _specs) callback->invoke(spec);
67 }
void spec(std::string_view description, std::function< void()> body)
Definition spec.h:12

◆ full_description()

const char * SpecsCpp::SpecGroup::full_description ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecDocumented.

Definition at line 94 of file SpecGroup.h.

94{ return _fullDescription.c_str(); }

◆ merge()

void SpecsCpp::SpecGroup::merge ( ISpecGroup other)
inlineoverridevirtual

Implements SpecsCpp::ISpecGroup.

Definition at line 96 of file SpecGroup.h.

96 {
97 other->foreach_group(&_merge_child_groups_fn);
98 other->foreach_test(&_merge_tests_fn);
99 other->foreach_setup(&_merge_setups_fn);
100 other->foreach_teardown(&_merge_teardowns_fn);
101 other->foreach_one_time_setup(&_merge_one_time_setups_fn);
102 other->foreach_one_time_teardown(&_merge_one_time_teardowns_fn);
103 }

◆ variables()

ISpecVariableCollection * SpecsCpp::SpecGroup::variables ( ) const
inlineoverridevirtual

Implements SpecsCpp::ISpecHasVariables.

Definition at line 105 of file SpecGroup.h.

105{ return _variables.get(); }

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