Echo Writes Code

outcome.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
#ifndef CRUCIBLE_TEST_OUTCOME_HPP
#define CRUCIBLE_TEST_OUTCOME_HPP

#include <string>
#include <variant>

namespace crucible::test::outcome
{
  struct Pass final {};

  class Fail final
  {
  public:
    explicit Fail(std::string const &details);

    [[nodiscard]]
    auto get_details() const -> std::string;

  private:
    std::string my_details {};
  };

  class Outcome final
  {
  public:
    Outcome(Pass const &pass);

    Outcome(Fail const &fail);

    [[nodiscard]]
    auto passed() const -> bool;

    [[nodiscard]]
    auto failed() const -> bool;

    [[nodiscard]]
    auto get_details() const -> std::string;

  private:
    std::variant<Pass, Fail> my_state {};
  };

  [[nodiscard]]
  auto make_pass() -> Outcome;

  [[nodiscard]]
  auto make_fail(std::string const &details) -> Outcome;
}

#endif // CRUCIBLE_TEST_OUTCOME_HPP