Hegel 0.3.5
Property-based testing for C++
Loading...
Searching...
No Matches
hegel::TestCase Class Reference

Handle to the currently-executing test case. More...

#include <test_case.h>

Public Member Functions

 TestCase (const TestCase &)=delete
TestCase & operator= (const TestCase &)=delete
 TestCase (TestCase &&)=delete
TestCase & operator= (TestCase &&)=delete
template<typename T>
draw (const generators::Generator< T > &gen) const
 Draw a random value from a generator.
void assume (bool condition) const
 Reject the current test case if condition is false.
void note (std::string_view message) const
 Record a message that will be printed on the final replay of a failing test case.

Detailed Description

Handle to the currently-executing test case.

A TestCase is passed as the sole argument to the callback given to hegel::test(). It is the main way a test definition interacts with Hegel.

TestCase is a non-owning handle into state managed by the Hegel runner. It is neither copyable nor movable, and must not outlive the test-case callback.

namespace gs = hegel::generators;
auto x = tc.draw(gs::integers<int>({.min_value = 0}));
tc.assume(x != 0);
tc.note("x = " + std::to_string(x));
});
Handle to the currently-executing test case.
Definition test_case.h:34
void assume(bool condition) const
Reject the current test case if condition is false.
void note(std::string_view message) const
Record a message that will be printed on the final replay of a failing test case.
T draw(const generators::Generator< T > &gen) const
Draw a random value from a generator.
Definition core.h:371
Hegel generators.
Definition core.h:16
void test(const std::function< void(TestCase &)> &test_fn, const Settings &settings={})
Run a Hegel test.

Member Function Documentation

◆ assume()

void hegel::TestCase::assume ( bool condition) const

Reject the current test case if condition is false.

auto age = tc.draw(gs::integers<int>());
tc.assume(age >= 18);
Parameters
conditionValue that must be true for the test case to continue. If false, the current test case is rejected.

◆ draw()

template<typename T>
T hegel::TestCase::draw ( const generators::Generator< T > & gen) const

Draw a random value from a generator.

Template Parameters
TThe value type produced by gen
Parameters
genThe generator to draw from
Returns
A freshly generated value of type T

◆ note()

void hegel::TestCase::note ( std::string_view message) const

Record a message that will be printed on the final replay of a failing test case.

Parameters
messageThe message to record.

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