C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
handler.hpp
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <exception>
13#include <string>
14
15#include "result.hpp"
16
17namespace CppSpec {
18
21 template <class Matcher>
22 static Result handle_matcher(Matcher& matcher);
23 static std::string verb() { return "should"; }
24};
25
28 template <class Matcher>
29 static Result handle_matcher(Matcher& matcher);
30 static std::string verb() { return "should not"; }
31};
32
41template <class Matcher>
43 bool matched = false;
44 try {
45 matched = matcher.match();
46 } catch (std::exception& e) {
47 return Result::error_with(matcher.get_location(), e.what());
48 } catch (...) {
49 return Result::error_with(matcher.get_location(), "Unknown exception thrown during matcher execution.");
50 }
51
52 return !matched ? Result::failure_with(matcher.get_location(), matcher.failure_message())
53 : Result::success(matcher.get_location());
54}
55
64template <class Matcher>
66 bool matched = false;
67 try {
68 matched = matcher.negated_match();
69 } catch (std::exception& e) {
70 return Result::error_with(matcher.get_location(), e.what());
71 } catch (...) {
72 return Result::error_with(matcher.get_location(), "Unhandled exception thrown during matcher execution.");
73 }
74 return !matched ? Result::failure_with(matcher.get_location(), matcher.failure_message_when_negated())
75 : Result::success(matcher.get_location());
76}
77
78} // namespace CppSpec
Definition result.hpp:13
Handles "negative" expectations (i.e. negated with '.not_()
Definition handler.hpp:27
static Result handle_matcher(Matcher &matcher)
runs a negative expectation
Definition handler.hpp:65
Handles "positive" expectations (i.e. non-negated)
Definition handler.hpp:20
static Result handle_matcher(Matcher &matcher)
runs a positive expectation
Definition handler.hpp:42