Hegel 0.18.2
Property-based testing for C++
Loading...
Searching...
No Matches
errors.h
1#pragma once
2
3#include <cstddef>
4#include <exception>
5#include <optional>
6#include <stdexcept>
7#include <string>
8#include <utility>
9#include <vector>
10
11#include "settings.h"
12
13namespace hegel {
14
24 class RunError : public std::runtime_error {
25 public:
27 explicit RunError(const std::string& message)
28 : std::runtime_error(message) {}
29 };
30
39 class FailedHealthCheck : public RunError {
40 public:
44 FailedHealthCheck(const std::string& message,
45 std::optional<HealthCheck> health_check)
46 : RunError(message), health_check_(health_check) {}
47
50 std::optional<HealthCheck> health_check() const {
51 return health_check_;
52 }
53
54 private:
55 std::optional<HealthCheck> health_check_;
56 };
57
67 class Flaky : public RunError {
68 public:
70 explicit Flaky(const std::string& message) : RunError(message) {}
71 };
72
77 class Unsatisfiable : public RunError {
78 public:
80 explicit Unsatisfiable(const std::string& message)
81 : RunError(message) {}
82 };
83
91 class DidNotReproduce : public std::runtime_error {
92 public:
94 explicit DidNotReproduce(const std::string& message)
95 : std::runtime_error(message) {}
96 };
97
106 class MultipleFailures : public std::runtime_error {
107 public:
109 explicit MultipleFailures(std::vector<std::exception_ptr> failures)
110 : std::runtime_error(describe(failures)),
111 failures_(std::move(failures)) {}
112
115 const std::vector<std::exception_ptr>& failures() const {
116 return failures_;
117 }
118
119 private:
120 static std::string
121 describe(const std::vector<std::exception_ptr>& failures) {
122 std::string out = "Property-based test failed with " +
123 std::to_string(failures.size()) +
124 " distinct failures.";
125 for (const std::exception_ptr& failure : failures) {
126 out += "\n";
127 try {
128 std::rethrow_exception(failure);
129 } catch (const std::exception& error) {
130 out += error.what();
131 } catch (...) {
132 out += "(an exception that is not a std::exception)";
133 }
134 }
135 return out;
136 }
137
138 std::vector<std::exception_ptr> failures_;
139 };
140
141} // namespace hegel
DidNotReproduce(const std::string &message)
Definition errors.h:94
std::optional< HealthCheck > health_check() const
Definition errors.h:50
FailedHealthCheck(const std::string &message, std::optional< HealthCheck > health_check)
Definition errors.h:44
Flaky(const std::string &message)
Definition errors.h:70
const std::vector< std::exception_ptr > & failures() const
Definition errors.h:115
MultipleFailures(std::vector< std::exception_ptr > failures)
Definition errors.h:109
RunError(const std::string &message)
Definition errors.h:27
Unsatisfiable(const std::string &message)
Definition errors.h:80
Main namespace.
Definition config.h:29