Echo Writes Code

outcome.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
#include "crucible/testing/outcome.hpp"

namespace crucible::testing::outcome {
  Fail::Fail(std::string const &details) :
    my_details { details } {
  }

  auto Fail::get_details() const -> std::string {
    return my_details;
  }

  Outcome::Outcome(Pass const &pass) :
    my_state { pass } {
  }

  Outcome::Outcome(Fail const &fail) :
    my_state { fail } {
  }

  auto Outcome::passed() const -> bool {
    return std::holds_alternative<Pass>(my_state);
  }

  auto Outcome::failed() const -> bool {
    return std::holds_alternative<Fail>(my_state);
  }

  auto Outcome::get_details() const -> std::string {
    if (passed()) {
      return "";
    } else {
      return std::get<Fail>(my_state).get_details();
    }
  }

  auto make_pass() -> Outcome {
    return Pass {};
  }

  auto make_fail(std::string const &details) -> Outcome {
    return Fail { details };
  }
}