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

#include <GlobalSpecGroup.h>

Public Member Functions

 GlobalSpecGroup ()
 
 GlobalSpecGroup (ISpecGroup *rootGroup)
 
ISpecGrouproot () const
 
ISpecGroupget () const
 
void set (ISpecGroup *group)
 
void push (ISpecGroup *group)
 
void pop ()
 
void clear_group_stack ()
 
void reset_group_stack ()
 
void save_group_stack ()
 
void restore_group_stack ()
 
void define_template (std::string_view templateName, std::unique_ptr< SpecCodeBlock > codeBlock)
 
void define_group (std::string_view description, std::unique_ptr< SpecCodeBlock > codeBlock, bool removeUnderscores=false)
 
void define_spec (std::string_view description, std::unique_ptr< SpecCodeBlock > codeBlock, bool skip=false)
 
void define_setup (std::unique_ptr< SpecCodeBlock > codeBlock, bool skip=false)
 
void define_teardown (std::unique_ptr< SpecCodeBlock > codeBlock, bool skip=false)
 
void define_one_time_setup (std::unique_ptr< SpecCodeBlock > codeBlock, bool skip=false)
 
void define_one_time_teardown (std::unique_ptr< SpecCodeBlock > codeBlock, bool skip=false)
 
void clear_top_level_group ()
 
void declare_top_level_group (std::string_view description)
 
void clear_file_group ()
 
void declare_file_group (std::string_view description, bool removeUnderscores=true)
 
void declare_top_level_template (std::string_view templateName, bool clearFileGroup=false, bool removeUnderscores=true)
 
void declare_group (std::string_view description, bool removeUnderscores=true)
 
void declare_groups (std::vector< std::string > descriptions)
 
void use_template (std::string_view templateName)
 
void use_templates (std::vector< std::string_view > templateNames)
 
void add_meta_data_for_next_component (ISpecDataValue *value)
 
void add_tag_for_next_component (std::string_view value)
 
void add_tags_for_next_component (std::vector< std::string_view > values)
 

Static Public Member Functions

static GlobalSpecGroupinstance ()
 

Detailed Description

Definition at line 22 of file GlobalSpecGroup.h.

Constructor & Destructor Documentation

◆ GlobalSpecGroup() [1/2]

SpecsCpp::GlobalSpecGroup::GlobalSpecGroup ( )
inline

Definition at line 70 of file GlobalSpecGroup.h.

70 {
71 // GlobalSpecGroup comes with a root group
72 auto rootGroup = std::make_unique<SpecGroup>(nullptr, "");
73 _registeredGroups.push_back(std::move(rootGroup));
74 _currentGroupStack.push_back(_registeredGroups.back().get());
75 }

◆ GlobalSpecGroup() [2/2]

SpecsCpp::GlobalSpecGroup::GlobalSpecGroup ( ISpecGroup rootGroup)
inline

Definition at line 78 of file GlobalSpecGroup.h.

78{ _currentGroupStack.push_back(rootGroup); }

Member Function Documentation

◆ add_meta_data_for_next_component()

void SpecsCpp::GlobalSpecGroup::add_meta_data_for_next_component ( ISpecDataValue value)
inline

Definition at line 349 of file GlobalSpecGroup.h.

349 {
350 _metaDataForNextComponent.add(value);
351 }
void add(ISpecDataValue *value) override

Referenced by SpecsCpp::DSLs::Functions::set_timeout(), and SpecsCpp::DSLs::Functions::skip().

◆ add_tag_for_next_component()

void SpecsCpp::GlobalSpecGroup::add_tag_for_next_component ( std::string_view  value)
inline

Definition at line 353 of file GlobalSpecGroup.h.

353 {
354 _tagsForNextComponent.add(value.data());
355 }
void add(const char *value) override

Referenced by add_tags_for_next_component().

◆ add_tags_for_next_component()

void SpecsCpp::GlobalSpecGroup::add_tags_for_next_component ( std::vector< std::string_view >  values)
inline

Definition at line 357 of file GlobalSpecGroup.h.

357 {
358 for (auto& value : values) add_tag_for_next_component(value.data());
359 }
void add_tag_for_next_component(std::string_view value)

◆ clear_file_group()

void SpecsCpp::GlobalSpecGroup::clear_file_group ( )
inline

Definition at line 250 of file GlobalSpecGroup.h.

250 {
251 if (auto* group = get()) {
252 // Is there another top-level group? Let's pop it off
253 if (_currentFileGroup) {
254 while (get() != _currentFileGroup) pop();
255 if (get() == _currentFileGroup) pop();
256 }
257 _currentFileGroup = nullptr;
258 }
259 }
ISpecGroup * get() const

Referenced by declare_file_group(), and declare_top_level_template().

◆ clear_group_stack()

void SpecsCpp::GlobalSpecGroup::clear_group_stack ( )
inline

Definition at line 93 of file GlobalSpecGroup.h.

93 {
94 _currentGroupStack.clear();
95
96 // This makes the current group / file notes no longer valid
97 _currentFileGroup = nullptr;
98 _currentTopLevelGroup = nullptr;
99 }

Referenced by declare_top_level_template(), and reset_group_stack().

◆ clear_top_level_group()

void SpecsCpp::GlobalSpecGroup::clear_top_level_group ( )
inline

Definition at line 224 of file GlobalSpecGroup.h.

224 {
225 if (auto* group = get()) {
226 // Is there another top-level group? Let's pop it off
227 if (_currentTopLevelGroup) {
228 while (get() != _currentTopLevelGroup) pop();
229 if (get() == _currentTopLevelGroup) pop();
230 }
231 _currentTopLevelGroup = nullptr;
232 }
233 }

Referenced by declare_file_group(), declare_top_level_group(), and declare_top_level_template().

◆ declare_file_group()

void SpecsCpp::GlobalSpecGroup::declare_file_group ( std::string_view  description,
bool  removeUnderscores = true 
)
inline

Definition at line 261 of file GlobalSpecGroup.h.

261 {
264
265 if (auto* group = get()) {
266 std::string descriptionText{description};
267 if (removeUnderscores) {
268 std::replace(descriptionText.begin(), descriptionText.end(), '_', ' ');
269 description = descriptionText;
270 }
271 auto specGroup = std::make_unique<SpecGroup>(get(), descriptionText);
272 auto* specGroupPtr = specGroup.get();
273 component_defined(specGroupPtr);
274
275 _currentFileGroup = specGroupPtr;
276 _registeredGroups.push_back(std::move(specGroup));
277 group->add_group(specGroupPtr);
278 push(specGroupPtr);
279 }
280 }
void push(ISpecGroup *group)

◆ declare_group()

void SpecsCpp::GlobalSpecGroup::declare_group ( std::string_view  description,
bool  removeUnderscores = true 
)
inline

Definition at line 310 of file GlobalSpecGroup.h.

310 {
311 if (auto* group = get()) {
312 std::string descriptionText{description};
313 if (removeUnderscores) {
314 std::replace(descriptionText.begin(), descriptionText.end(), '_', ' ');
315 description = descriptionText;
316 }
317 auto specGroup = std::make_unique<SpecGroup>(get(), descriptionText);
318 auto* specGroupPtr = specGroup.get();
319 component_defined(specGroupPtr);
320
321 _registeredGroups.push_back(std::move(specGroup));
322 group->add_group(_registeredGroups.back().get());
323 push(specGroupPtr);
324 }
325 }

Referenced by declare_groups().

◆ declare_groups()

void SpecsCpp::GlobalSpecGroup::declare_groups ( std::vector< std::string >  descriptions)
inline

Definition at line 327 of file GlobalSpecGroup.h.

327 {
328 for (auto& description : descriptions) declare_group(description);
329 }
void declare_group(std::string_view description, bool removeUnderscores=true)

◆ declare_top_level_group()

void SpecsCpp::GlobalSpecGroup::declare_top_level_group ( std::string_view  description)
inline

Definition at line 235 of file GlobalSpecGroup.h.

235 {
237
238 if (auto* group = get()) {
239 auto specGroup = std::make_unique<SpecGroup>(get(), description);
240 auto* specGroupPtr = specGroup.get();
241 component_defined(specGroupPtr);
242
243 _currentTopLevelGroup = specGroupPtr;
244 _registeredGroups.push_back(std::move(specGroup));
245 group->add_group(specGroupPtr);
246 push(specGroupPtr);
247 }
248 }

◆ declare_top_level_template()

void SpecsCpp::GlobalSpecGroup::declare_top_level_template ( std::string_view  templateName,
bool  clearFileGroup = false,
bool  removeUnderscores = true 
)
inline

Definition at line 282 of file GlobalSpecGroup.h.

285 {
287 if (clearFileGroup) clear_file_group();
288
289 if (auto* group = get()) {
290 std::string descriptionText{templateName};
291 if (removeUnderscores) {
292 std::replace(descriptionText.begin(), descriptionText.end(), '_', ' ');
293 templateName = descriptionText;
294 }
295 auto foundExisting = _testTemplateGroups.find(descriptionText.data());
296 if (foundExisting != _testTemplateGroups.end()) {
297 clear_group_stack(); // The top-level things should NOT be registered anywhere
298 } else {
299 auto specGroup = std::make_unique<SpecGroup>(get(), descriptionText);
300 auto* specGroupPtr = specGroup.get();
301 component_defined(specGroupPtr);
302
303 _currentTopLevelGroup = specGroupPtr;
304 _testTemplateGroups[descriptionText] = std::move(specGroup);
305 push(specGroupPtr);
306 }
307 }
308 }

◆ define_group()

void SpecsCpp::GlobalSpecGroup::define_group ( std::string_view  description,
std::unique_ptr< SpecCodeBlock codeBlock,
bool  removeUnderscores = false 
)
inline

Definition at line 133 of file GlobalSpecGroup.h.

136 {
137 if (auto* group = get()) {
138 std::string descriptionText{description};
139 if (removeUnderscores) {
140 std::replace(descriptionText.begin(), descriptionText.end(), '_', ' ');
141 description = descriptionText;
142 }
143 auto specGroup = std::make_unique<SpecGroup>(get(), descriptionText);
144 auto* specGroupPtr = specGroup.get();
145 component_defined(specGroupPtr);
146
147 _registeredGroups.push_back(std::move(specGroup));
148 group->add_group(_registeredGroups.back().get());
149
150 // Evaluate the group block (with this group being the 'current group')
151 push(specGroupPtr);
152 codeBlock->run(specGroupPtr, specGroupPtr, nullptr, nullptr);
153 pop();
154 } else {
155 _Log_("define_group() called but no group is active!");
156 }
157 }

Referenced by SpecsCpp::DSLs::GlobalInterface::define_group_fn(), and SpecsCpp::DSLs::GlobalInterface::define_group_fn().

◆ define_one_time_setup()

void SpecsCpp::GlobalSpecGroup::define_one_time_setup ( std::unique_ptr< SpecCodeBlock codeBlock,
bool  skip = false 
)
inline

Definition at line 200 of file GlobalSpecGroup.h.

200 {
201 if (auto* group = get()) {
202 auto setup = std::make_unique<SpecSetup>(get(), std::move(codeBlock));
203 if (skip) setup->mark_skipped(true);
204 auto* setupPtr = setup.get();
205 component_defined(setupPtr);
206
207 _registeredOneTimesetups.push_back(std::move(setup));
208 group->add_one_time_setup(setupPtr);
209 }
210 }
void setup(std::function< void()> body)
Definition setup.h:12

Referenced by SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), and SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn().

◆ define_one_time_teardown()

void SpecsCpp::GlobalSpecGroup::define_one_time_teardown ( std::unique_ptr< SpecCodeBlock codeBlock,
bool  skip = false 
)
inline

Definition at line 212 of file GlobalSpecGroup.h.

212 {
213 if (auto* group = get()) {
214 auto teardown = std::make_unique<SpecTeardown>(get(), std::move(codeBlock));
215 if (skip) teardown->mark_skipped(true);
216 auto* teardownPtr = teardown.get();
217 component_defined(teardownPtr);
218
219 _registeredOneTimeteardowns.push_back(std::move(teardown));
220 group->add_one_time_teardown(teardownPtr);
221 }
222 }
void teardown(std::function< void()> body)
Definition teardown.h:12

Referenced by SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), and SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn().

◆ define_setup()

void SpecsCpp::GlobalSpecGroup::define_setup ( std::unique_ptr< SpecCodeBlock codeBlock,
bool  skip = false 
)
inline

Definition at line 176 of file GlobalSpecGroup.h.

176 {
177 if (auto* group = get()) {
178 auto setup = std::make_unique<SpecSetup>(get(), std::move(codeBlock));
179 if (skip) setup->mark_skipped(true);
180 auto* setupPtr = setup.get();
181 component_defined(setupPtr);
182
183 _registeredsetups.push_back(std::move(setup));
184 group->add_setup(setupPtr);
185 }
186 }

Referenced by SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), and SpecsCpp::DSLs::GlobalInterface::define_setup_fn().

◆ define_spec()

void SpecsCpp::GlobalSpecGroup::define_spec ( std::string_view  description,
std::unique_ptr< SpecCodeBlock codeBlock,
bool  skip = false 
)
inline

Definition at line 159 of file GlobalSpecGroup.h.

162 {
163 if (auto* group = get()) {
164 auto spec = std::make_unique<SpecTest>(get(), description, std::move(codeBlock));
165 if (skip) spec->mark_skipped(true);
166 auto* specPtr = spec.get();
167 component_defined(specPtr);
168
169 _registeredSpecs.push_back(std::move(spec));
170 group->add_test(specPtr);
171 } else {
172 _Log_("define_spec() called but no group is active!");
173 }
174 }
void spec(std::string_view description, std::function< void()> body)
Definition spec.h:12

Referenced by SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), and SpecsCpp::DSLs::GlobalInterface::define_test_fn().

◆ define_teardown()

void SpecsCpp::GlobalSpecGroup::define_teardown ( std::unique_ptr< SpecCodeBlock codeBlock,
bool  skip = false 
)
inline

Definition at line 188 of file GlobalSpecGroup.h.

188 {
189 if (auto* group = get()) {
190 auto teardown = std::make_unique<SpecTeardown>(get(), std::move(codeBlock));
191 if (skip) teardown->mark_skipped(true);
192 auto* teardownPtr = teardown.get();
193 component_defined(teardownPtr);
194
195 _registeredteardowns.push_back(std::move(teardown));
196 group->add_teardown(teardownPtr);
197 }
198 }

Referenced by SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), and SpecsCpp::DSLs::GlobalInterface::define_teardown_fn().

◆ define_template()

void SpecsCpp::GlobalSpecGroup::define_template ( std::string_view  templateName,
std::unique_ptr< SpecCodeBlock codeBlock 
)
inline

Definition at line 118 of file GlobalSpecGroup.h.

120 {
121 auto templateGroup = std::make_unique<SpecGroup>(nullptr, templateName);
122 auto* templateGroupPtr = templateGroup.get();
123 component_defined(templateGroupPtr);
124
125 auto* currentGroup = get();
126 set(templateGroupPtr);
127 codeBlock->run(templateGroupPtr, templateGroupPtr, nullptr, nullptr);
128 set(currentGroup);
129
130 _testTemplateGroups[templateName.data()] = std::move(templateGroup);
131 }
void set(ISpecGroup *group)

Referenced by SpecsCpp::DSLs::GlobalInterface::define_template_fn().

◆ get()

ISpecGroup * SpecsCpp::GlobalSpecGroup::get ( ) const
inline

◆ instance()

static GlobalSpecGroup & SpecsCpp::GlobalSpecGroup::instance ( )
inlinestatic

Definition at line 80 of file GlobalSpecGroup.h.

80 {
82 return instance;
83 }
static GlobalSpecGroup & instance()

Referenced by SpecsCpp::DSLs::GlobalInterface::define_group_fn(), SpecsCpp::DSLs::GlobalInterface::define_group_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_one_time_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_setup_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_teardown_fn(), SpecsCpp::DSLs::GlobalInterface::define_template_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), SpecsCpp::DSLs::GlobalInterface::define_test_fn(), instance(), SpecsCpp::Entrypoint::main(), SpecsCpp::DSLs::Functions::set_timeout(), SpecsCpp::DSLs::Functions::skip(), SpecsCpp_Load(), and SpecsCpp::DSLs::Functions::use_template().

◆ pop()

void SpecsCpp::GlobalSpecGroup::pop ( )
inline

Definition at line 91 of file GlobalSpecGroup.h.

91{ _currentGroupStack.pop_back(); }

Referenced by clear_file_group(), clear_top_level_group(), and define_group().

◆ push()

void SpecsCpp::GlobalSpecGroup::push ( ISpecGroup group)
inline

Definition at line 90 of file GlobalSpecGroup.h.

90{ _currentGroupStack.push_back(group); }

Referenced by declare_file_group(), declare_group(), declare_top_level_group(), declare_top_level_template(), define_group(), and reset_group_stack().

◆ reset_group_stack()

void SpecsCpp::GlobalSpecGroup::reset_group_stack ( )
inline

Definition at line 101 of file GlobalSpecGroup.h.

101 {
103 if (auto* rootGroup = root()) push(rootGroup);
104 }
ISpecGroup * root() const

◆ restore_group_stack()

void SpecsCpp::GlobalSpecGroup::restore_group_stack ( )
inline

Definition at line 112 of file GlobalSpecGroup.h.

112 {
113 _currentFileGroup = _savedFileGroup;
114 _currentTopLevelGroup = _savedTopLevelGroup;
115 _currentGroupStack = _savedGroupStack;
116 }

◆ root()

ISpecGroup * SpecsCpp::GlobalSpecGroup::root ( ) const
inline

Definition at line 85 of file GlobalSpecGroup.h.

85{ return _registeredGroups.front().get(); }

Referenced by reset_group_stack(), and SpecsCpp_Load().

◆ save_group_stack()

void SpecsCpp::GlobalSpecGroup::save_group_stack ( )
inline

Definition at line 106 of file GlobalSpecGroup.h.

106 {
107 _savedFileGroup = _currentFileGroup;
108 _savedTopLevelGroup = _currentTopLevelGroup;
109 _savedGroupStack = _currentGroupStack;
110 }

◆ set()

void SpecsCpp::GlobalSpecGroup::set ( ISpecGroup group)
inline

Definition at line 89 of file GlobalSpecGroup.h.

89{ _currentGroupStack.back() = group; }

Referenced by define_template().

◆ use_template()

void SpecsCpp::GlobalSpecGroup::use_template ( std::string_view  templateName)
inline

Definition at line 331 of file GlobalSpecGroup.h.

331 {
332 if (auto* group = get()) {
333 auto found = _testTemplateGroups.find(templateName.data());
334 if (found == _testTemplateGroups.end()) {
335 _Error_("Test template not found: {}", templateName);
336 return;
337 }
338
339 auto* templateGroup = found->second.get();
340 group->merge(templateGroup);
341 }
342 }

Referenced by SpecsCpp::DSLs::Functions::use_template(), and use_templates().

◆ use_templates()

void SpecsCpp::GlobalSpecGroup::use_templates ( std::vector< std::string_view >  templateNames)
inline

Definition at line 344 of file GlobalSpecGroup.h.

344 {
345 if (auto* group = get())
346 for (auto& templateName : templateNames) use_template(templateName);
347 }
void use_template(std::string_view templateName)

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