Echo Writes Code

suite.hpp

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef CRUCIBLE_TEST_SUITE_HPP
#define CRUCIBLE_TEST_SUITE_HPP

#include "crucible/test/fixture.hpp"
#include "crucible/test/reporter.hpp"
#include "crucible/test/scenario.hpp"

#include <cstddef>
#include <map>
#include <set>
#include <string>
#include <vector>

#define CRUCIBLE_BEFORE_ALL(GROUP, NAME) \
  auto NAME() -> void; \
  \
  crucible::test::suite::FixtureRegistrar<crucible::test::fixture::BeforeAll> crucible_test_before_all_registrar_for__##GROUP##__##NAME(#GROUP, #NAME, NAME); \
  \
  auto NAME() -> void

#define CRUCIBLE_AFTER_ALL(GROUP, NAME) \
  auto NAME() -> void; \
  \
  crucible::test::suite::FixtureRegistrar<crucible::test::fixture::AfterAll> crucible_test_after_all_registrar_for__##GROUP##__##NAME(#GROUP, #NAME, NAME); \
  \
  auto NAME() -> void

#define CRUCIBLE_BEFORE_EACH(GROUP, NAME) \
  auto NAME() -> void; \
  \
  crucible::test::suite::FixtureRegistrar<crucible::test::fixture::BeforeEach> crucible_test_before_each_registrar_for__##GROUP##__##NAME(#GROUP, #NAME, NAME); \
  \
  auto NAME() -> void

#define CRUCIBLE_AFTER_EACH(GROUP, NAME) \
  auto NAME() -> void; \
  \
  crucible::test::suite::FixtureRegistrar<crucible::test::fixture::AfterEach> crucible_test_after_each_registrar_for__##GROUP##__##NAME(#GROUP, #NAME, NAME); \
  \
  auto NAME() -> void

#define CRUCIBLE_SCENARIO(GROUP, NAME) \
  auto NAME() -> void; \
  \
  crucible::test::suite::ScenarioRegistrar crucible_test_scenario_registrar_for__##GROUP##__##NAME(#GROUP, #NAME, NAME); \
  \
  auto NAME() -> void

namespace crucible::test::suite
{
  class Suite final
  {
    struct ConstructorPermission;

  public:
    [[nodiscard]]
    static auto get_reference() -> Suite &;

    Suite(Suite const &) = delete;

    Suite(Suite &&) = delete;

    Suite &operator=(Suite const &) = delete;

    Suite &operator=(Suite &&) = delete;

    explicit Suite(ConstructorPermission const &);

    auto set_name(std::string const &name) -> void;

    auto set_group_filter(std::set<std::string> const &group_filter) -> void;

    auto add_scenario(std::string const &group, std::string const &name, scenario::ScenarioFunction const &function) -> void;

    template<typename VARIANT>
    auto add_fixture(std::string const &group, std::string const &name, fixture::FixtureFunction const &function) -> void;

    [[nodiscard]]
    auto execute(reporter::Reporter &reporter) -> bool;

  private:
    std::string my_name {};

    std::set<std::string> my_group_filter {};

    std::map<std::string, std::vector<scenario::Scenario>> my_scenarios_by_group {};

    std::map<std::string, std::vector<fixture::Fixture>> my_fixtures_by_group {};

    std::size_t my_pass_count { 0 };

    std::size_t my_fail_count { 0 };

    std::size_t my_scenario_count { 0 };

    std::size_t my_fixture_count { 0 };

    auto execute_scenarios(reporter::Reporter &reporter) -> void;

    template<typename VARIANT>
    auto execute_fixtures_with_group(std::string const &group, reporter::Reporter &reporter) -> void;
  };

  template<typename VARIANT>
  struct FixtureRegistrar final
  {
    FixtureRegistrar(std::string const &group, std::string const &name, fixture::FixtureFunction const &function);
  };

  struct ScenarioRegistrar final
  {
    ScenarioRegistrar(std::string const &group, std::string const &name, scenario::ScenarioFunction const &function);
  };
}

#endif // CRUCIBLE_TEST_SUITE_HPP

#include "crucible/test/suite.inl"