|
Hegel 0.17.5
Property-based testing for C++
|
Main namespace. More...
Namespaces | |
| namespace | generators |
| Hegel generators. | |
| namespace | stateful |
| Stateful (model-based) property testing. | |
Classes | |
| class | RunError |
| The engine stopped the run without a verdict on the property. More... | |
| class | FailedHealthCheck |
| A health check failed. More... | |
| class | Flaky |
| The test behaved nondeterministically under NondeterminismStrictness::Error. More... | |
| class | Unsatisfiable |
| The engine could not find inputs that satisfy the test's assumptions and filters. More... | |
| class | DidNotReproduce |
| No failure blob given to hegel::test() or HEGEL_REPRODUCE_FAILURE made the test fail. More... | |
| class | MultipleFailures |
| The run found more than one distinct failure. More... | |
| struct | NamedValue |
| A value of an ExplicitTestCase that a named draw takes. More... | |
| class | ExplicitTestCase |
| Values to run a test with before Hegel generates any. More... | |
| class | GTestFailure |
| The exception the GoogleTest integration raises for a test case that fails an assertion. More... | |
| class | FailureOrigin |
| Interface for an exception that names its own failure origin. More... | |
| struct | TestLocation |
| Where a test is defined. More... | |
| class | Printer |
| Writes to the document that a failure report shows. More... | |
| class | Speculation |
| An open speculative region; see Printer::speculate(). More... | |
| class | Document |
| A document of its own, outside a test case. More... | |
| class | Database |
| Configure the Hegel database. More... | |
| struct | Settings |
| Configuration options for hegel::test(). More... | |
| class | TestCase |
| Handle to the currently-executing test case. More... | |
| class | Worker |
| Handle to a worker started by TestCase::spawn(). More... | |
Enumerations | |
| enum class | Verbosity { Quiet , Normal , Verbose , Debug } |
| Verbosity levels. More... | |
| enum class | HealthCheck { FilterTooMuch , TooSlow , TestCasesTooLarge , LargeInitialTestCase } |
| Health checks. More... | |
| enum class | Phase { Explicit , Reuse , Generate , Target , Shrink } |
| Phases of a property-test run. More... | |
| enum class | Backend { Auto , Default , Urandom } |
| Source of randomness the engine draws from. More... | |
| enum class | NondeterminismStrictness { Quiet , Warn , Error } |
| How a run reacts when it detects nondeterministic test behavior: a test whose structure or outcome changes when the same choices are replayed. More... | |
Functions | |
| template<typename T> | |
| NamedValue< std::decay_t< T > > | named (std::string name, T &&value) |
Give a value of an ExplicitTestCase to the draw named name. | |
| void | test (const std::function< void(TestCase &)> &test_fn, const Settings &settings={}, const std::vector< std::string > &failure_blobs={}, const std::vector< ExplicitTestCase > &explicit_cases={}, const char *caller_file=HEGEL_CALLER_FILE, const char *caller_function=HEGEL_CALLER_FUNCTION, int caller_line=HEGEL_CALLER_LINE) |
| Run a Hegel test. | |
| void | test (const std::function< void(TestCase &)> &test_fn, const TestLocation &location, const Settings &settings={}, const std::vector< std::string > &failure_blobs={}, const std::vector< ExplicitTestCase > &explicit_cases={}) |
| Run a Hegel test at a location you name. | |
| std::vector< HealthCheck > | all_health_checks () |
| All health checks, suitable for full suppression. | |
| std::vector< Phase > | all_phases () |
| All phases, the base value of Settings::phases. | |
| void | register_profile (const std::string &name, const Settings &settings) |
| Register settings as a named settings profile. | |
| void | set_default_profile (const std::string &name) |
| Set the default settings profile for the whole process. | |
| std::string | engine_version () |
| The version of libhegel, the engine that Hegel for C++ drives. | |
Variables | |
| template<typename T> | |
| constexpr bool | is_representable_v |
| Whether Printer::repr() has a C++ representation for T. | |
Main namespace.
|
strong |
Source of randomness the engine draws from.
|
strong |
|
strong |
How a run reacts when it detects nondeterministic test behavior: a test whose structure or outcome changes when the same choices are replayed.
|
strong |
|
strong |
Verbosity levels.
| Enumerator | |
|---|---|
| Quiet | Minimal output (used by TUI). |
| Normal | Default - standard test output. |
| Verbose | More detailed output. |
| Debug | Maximum verbosity + engine-side shrinker tracing. |
|
inline |
All health checks, suitable for full suppression.
|
inline |
All phases, the base value of Settings::phases.
| std::string hegel::engine_version | ( | ) |
The version of libhegel, the engine that Hegel for C++ drives.
| NamedValue< std::decay_t< T > > hegel::named | ( | std::string | name, |
| T && | value ) |
Give a value of an ExplicitTestCase to the draw named name.
| T | The value type. It must be the type the draw produces. |
| name | The name the draw prints under: x_1 for the first tc.draw("x", ...), x_2 for the second, draw_1 for the first unnamed draw. |
| value | The value the draw returns. |
| void hegel::register_profile | ( | const std::string & | name, |
| const Settings & | settings ) |
Register settings as a named settings profile.
The profile holds a complete snapshot of settings. Settings::database_key is not part of the snapshot. Registration is process-wide and replaces an earlier registration of the same name. It is not retroactive: a Settings created before it keeps its values, so register a profile before creating the Settings that use it. A hegel.toml section for name still applies over the snapshot.
| name | The profile name: ASCII letters, digits, - and _. The reserved names base and default are not permitted. |
| settings | The settings to register. |
| std::invalid_argument | for an invalid or reserved name, or when settings name a profile that does not exist. |
| void hegel::set_default_profile | ( | const std::string & | name | ) |
Set the default settings profile for the whole process.
The default profile then resolves to name. This takes precedence over the HEGEL_DEFAULT_PROFILE environment variable, the default entry in hegel.toml, and the detected environment. It is not retroactive: a Settings created before it keeps its values. The profile does not have to exist yet.
| name | The profile name, or an empty string to remove an earlier call's selection. |
| std::invalid_argument | for an invalid name. |
| void hegel::test | ( | const std::function< void(TestCase &)> & | test_fn, |
| const Settings & | settings = {}, | ||
| const std::vector< std::string > & | failure_blobs = {}, | ||
| const std::vector< ExplicitTestCase > & | explicit_cases = {}, | ||
| const char * | caller_file = HEGEL_CALLER_FILE, | ||
| const char * | caller_function = HEGEL_CALLER_FUNCTION, | ||
| int | caller_line = HEGEL_CALLER_LINE ) |
Run a Hegel test.
This is the underlying entry point that HEGEL_TEST expands to.
Settings::database_key defaults to "<file>::<name>", where the file is the one holding the call and the name is the enclosing GoogleTest test (Suite.Name) or, outside a test framework, the enclosing function. The key is derived also when the database is disabled, because a derandomized run derives its seed from it.
Inside a GoogleTest test, the test location is that test and the line of the call. Pass a TestLocation to the overload below to name it yourself.
| test_fn | The test function to run repeatedly. Receives a TestCase which it uses to draw values, make assumptions, and record notes. |
| settings | Configuration settings (test count, debug mode, etc.) |
| failure_blobs | Reproduce blobs from earlier failure reports. If any are given, the test replays each blob instead of generating test cases. |
| explicit_cases | Test cases to run with the values they give, before any generated test case, when the Explicit phase is enabled. See ExplicitTestCase. |
| caller_file | Filled in by the compiler with the file of the call. |
| caller_function | Filled in by the compiler with the function holding the call. |
| caller_line | Filled in by the compiler with the line of the call. |
| MultipleFailures | if the run reports more than one failure. For a single failure, the test's own exception propagates. |
| RunError | (or a subclass) if the run stops without a verdict, for example because a health check fails. |
| DidNotReproduce | if no blob in failure_blobs makes the test fail. |
| std::invalid_argument | for invalid settings, an unknown Settings::from_profile(), or a blob that is not valid. |
| void hegel::test | ( | const std::function< void(TestCase &)> & | test_fn, |
| const TestLocation & | location, | ||
| const Settings & | settings = {}, | ||
| const std::vector< std::string > & | failure_blobs = {}, | ||
| const std::vector< ExplicitTestCase > & | explicit_cases = {} ) |
Run a Hegel test at a location you name.
Behaves like the overload above, except that the test location is location and Settings::database_key defaults to the location's file and name.
| test_fn | The test function to run repeatedly. |
| location | Where the test is defined. |
| settings | Configuration settings (test count, debug mode, etc.) |
| failure_blobs | Reproduce blobs from earlier failure reports. If any are given, the test replays each blob instead of generating test cases. |
| explicit_cases | Test cases to run with the values they give, before any generated test case, when the Explicit phase is enabled. See ExplicitTestCase. |
| MultipleFailures,RunError,DidNotReproduce,std::invalid_argument | as the overload above. |
|
inlineconstexpr |
Whether Printer::repr() has a C++ representation for T.
True for arithmetic types, enums, std::string, std::monostate, a type with a void print_to(hegel::Printer&) const member, the standard pairs, tuples, variants, optionals, vectors, sets, arrays and maps of such types, a reflectable aggregate (C++20), and a type with an operator<<. For a reflectable aggregate it does not look at the fields: a field with no representation prints as <unprintable ...>.
A generator that prints the value it produced (map, just, sampled_from, compose) is printable only for such a type.
| T | The type to check |