Hegel 0.18.3
Property-based testing for C++
Loading...
Searching...
No Matches
hegel::stateful::Invariant< T > Class Template Reference

An invariant is a predicate that must hold at any point in the stateful test. They are evaluated in full on the initial and final state and sampled at intermediate join points, unless declared always checked. The invariant function should throw when the invariant is violated. More...

#include <stateful.h>

Public Member Functions

 Invariant (std::string name, std::function< void(const T &)> invariant)
 Declare a new invariant.
 Invariant (std::string name, bool always_check, std::function< void(const T &)> invariant)
 Declare a new invariant that can skip sampling.
 Invariant (InvariantParams< T > params)
 Declare a new invariant from named arguments.
const std::string & name () const
 Returns the name of the invariant.
const std::function< void(const T &)> & invariant () const
 Returns the function representing the predicate of the invariant.
bool pause_faults () const
 Returns true if fault injection is paused while this invariant is checked.
bool always_check () const
 Returns whether the invariant is checked after every step or round instead of sampled.

Detailed Description

template<typename T>
class hegel::stateful::Invariant< T >

An invariant is a predicate that must hold at any point in the stateful test. They are evaluated in full on the initial and final state and sampled at intermediate join points, unless declared always checked. The invariant function should throw when the invariant is violated.

An invariant declared with pause_faults asks the engine to pause fault injection for the duration of each of its checks, so that inside Antithesis no fault lands in the middle of the check. Fault injection resumes when the check returns or throws. Outside Antithesis the flag has no effect.

std::vector<hegel::stateful::Invariant<Bank>> invariants() const {
{.name = "balances_sum_to_total",
.pause_faults = true,
.invariant = [](const Bank& m) { m.verify_total(); }})};
}
An invariant is a predicate that must hold at any point in the stateful test. They are evaluated in f...
Definition stateful.h:939
Template Parameters
TThe state-machine type the invariant checks

Constructor & Destructor Documentation

◆ Invariant() [1/3]

template<typename T>
hegel::stateful::Invariant< T >::Invariant ( std::string name,
std::function< void(const T &)> invariant )
inlineexplicit

Declare a new invariant.

Parameters
nameThe name of the invariant
invariantThe predicate, which throws when violated

◆ Invariant() [2/3]

template<typename T>
hegel::stateful::Invariant< T >::Invariant ( std::string name,
bool always_check,
std::function< void(const T &)> invariant )
inline

Declare a new invariant that can skip sampling.

Parameters
name
always_checkSee InvariantParams::always_check
invariant

◆ Invariant() [3/3]

template<typename T>
hegel::stateful::Invariant< T >::Invariant ( InvariantParams< T > params)
inlineexplicit

Declare a new invariant from named arguments.

Parameters
paramsThe name, always_check and pause_faults flags and predicate of the invariant

Member Function Documentation

◆ always_check()

template<typename T>
bool hegel::stateful::Invariant< T >::always_check ( ) const
inline

Returns whether the invariant is checked after every step or round instead of sampled.

Returns
true if the invariant is not sampled

◆ invariant()

template<typename T>
const std::function< void(const T &)> & hegel::stateful::Invariant< T >::invariant ( ) const
inline

Returns the function representing the predicate of the invariant.

Returns
const std::function<void(const T&)>&

◆ name()

template<typename T>
const std::string & hegel::stateful::Invariant< T >::name ( ) const
inline

Returns the name of the invariant.

Returns
const std::string&

◆ pause_faults()

template<typename T>
bool hegel::stateful::Invariant< T >::pause_faults ( ) const
inline

Returns true if fault injection is paused while this invariant is checked.

Returns
bool

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