Hegel 0.11.4
Property-based testing for C++
Loading...
Searching...
No Matches
hegel::FailureOrigin Class Referenceabstract

Interface for an exception that names its own failure origin. More...

#include <hegel.h>

Inheritance diagram for hegel::FailureOrigin:
hegel::GTestFailure

Public Member Functions

 FailureOrigin (const FailureOrigin &)=default
 Copy-constructs. An origin holds no state of its own.
FailureOrigin & operator= (const FailureOrigin &)=default
virtual std::string failure_origin () const =0
 The origin grouping this failure.

Detailed Description

Interface for an exception that names its own failure origin.

Hegel groups counterexamples by origin to tell one bug from another. By default, the origin of a thrown exception is its type and the site it was thrown from.

Derive from this interface to define origins some other way. The origin must be stable.

class CheckFailed : public std::runtime_error,
public:
CheckFailed(const char* file, int line, const std::string& message)
: std::runtime_error(message),
origin_(std::string(file) + ":" + std::to_string(line)) {}
std::string failure_origin() const override { return origin_; }
private:
std::string origin_;
};
Interface for an exception that names its own failure origin.
Definition hegel.h:389
virtual std::string failure_origin() const =0
The origin grouping this failure.

Member Function Documentation

◆ failure_origin()

virtual std::string hegel::FailureOrigin::failure_origin ( ) const
pure virtual

The origin grouping this failure.

Returns
A string naming the bug this exception stands for.

Implemented in hegel::GTestFailure.

◆ operator=()

FailureOrigin & hegel::FailureOrigin::operator= ( const FailureOrigin & )
default

Copy-assigns. An origin holds no state of its own.

Returns
Reference to this interface.

The documentation for this class was generated from the following file: