C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
fail.hpp
1#pragma once
2
4
5namespace CppSpec::Matchers {
6
7template <typename A>
8class Fail : public MatcherBase<A, void*> {
9 public:
10 static_assert(is_result_v<A>, ".fail must() be matched against a Matcher.");
11 explicit Fail(Expectation<A>& expectation) : MatcherBase<A, void*>(expectation, nullptr) {}
12 std::string verb() override { return "fail"; }
13 bool match() override { return this->actual().is_failure(); }
14};
15
16template <typename A>
17class FailWith : public MatcherBase<A, std::string> {
18 public:
19 static_assert(is_result_v<A>, ".fail_with() must be matched against a Result.");
20 FailWith(Expectation<A>& expectation, std::string expected) : MatcherBase<A, std::string>(expectation, expected) {}
21
22 std::string verb() override { return "fail with"; }
23 std::string description() override { return std::format(R"(fail with "{}")", this->expected()); }
24
25 bool match() override {
26 auto message = this->actual().get_message();
27 return this->actual().is_failure() && message == this->expected();
28 }
29};
30
31} // namespace CppSpec::Matchers
Wraps the target of an expectation.
Definition expectation.hpp:47
std::string description() override
Get the description of the Matcher.
Definition fail.hpp:23
Definition have_error.hpp:9
Contains the base class for all Matchers.