C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
have_error.hpp
1#pragma once
2#include <expected>
3
5
6namespace CppSpec::Matchers {
7
8template <typename T>
9concept expected = requires(T t) {
10 { t.error() } -> std::same_as<typename T::error_type&>;
11};
12
13template <expected T>
14class HaveError : public MatcherBase<T, void*> {
15 public:
16 HaveError(Expectation<T>& expectation) : MatcherBase<T, void*>(expectation) {}
17
18 std::string verb() override { return "have an error"; }
19 std::string description() override { return verb(); }
20
21 bool match() override { return (!this->actual().has_value()); }
22};
23
24template <expected T, typename E>
25class HaveErrorEqualTo : public MatcherBase<T, E> {
26 public:
27 static_assert(std::is_same_v<typename T::error_type, E>, "the contained error_type must match the expected type");
28 HaveErrorEqualTo(Expectation<T>& expectation, E expected) : MatcherBase<T, E>(expectation, expected) {}
29
30 bool match() { return (this->actual().error() == this->expected()); }
31};
32
33} // namespace CppSpec::Matchers
Wraps the target of an expectation.
Definition expectation.hpp:47
std::string description() override
Get the description of the Matcher.
Definition have_error.hpp:19
Definition have_error.hpp:9
Contains the base class for all Matchers.