suite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "crucible/testing/suite.inl" #include <cstddef> #include <memory> namespace crucible::testing::suite { struct Suite::ConstructorPermission {}; auto Suite::get_reference() -> Suite & { static auto instance = std::make_unique<Suite>(ConstructorPermission()); return *instance; } Suite::Suite(ConstructorPermission const &) { } auto Suite::add_scenario(std::string const &name, scenario::ScenarioFunction const &function) -> void { my_scenarios.emplace_back(name, function); } auto Suite::execute(reporter::Reporter &reporter) -> bool { reporter.handle_suite_start(); execute_fixtures<fixture::BeforeAll>(reporter); if (my_scenarios.empty()) { reporter.handle_empty_suite(); } else { execute_scenarios(reporter); } execute_fixtures<fixture::AfterAll>(reporter); reporter.handle_suite_end(my_pass_count, my_fail_count, my_fixture_count); return my_fail_count == 0; } auto Suite::execute_scenarios(reporter::Reporter &reporter) -> void { for (auto &scenario : my_scenarios) { reporter.handle_scenario_start(scenario); execute_fixtures<fixture::BeforeEach>(reporter); auto const outcome = scenario.execute(); reporter.handle_scenario_end(scenario, outcome); execute_fixtures<fixture::AfterEach>(reporter); if (outcome.passed()) { ++my_pass_count; } else { ++my_fail_count; } } } ScenarioRegistrar::ScenarioRegistrar(std::string const &name, scenario::ScenarioFunction const &test) { auto &suite = suite::Suite::get_reference(); suite.add_scenario(name, test); } }