|
Hegel 0.17.5
Property-based testing for C++
|
Macros for defining Hegel property tests. More...
Macros | |
| #define | HEGEL_TEST(name, ...) |
| Define a Hegel property test. | |
| #define | HEGEL_MAIN(name, ...) |
| Define a standalone test binary that runs one test case. | |
| #define | HEGEL_REPRODUCE_FAILURE(name, blob, ...) |
| Replay a failing example for a HEGEL_TEST from its blob. | |
| #define | HEGEL_EXPLICIT_TEST_CASE(name, ...) |
| Add an explicit test case to a HEGEL_TEST. | |
Macros for defining Hegel property tests.
| #define HEGEL_EXPLICIT_TEST_CASE | ( | name, | |
| ... ) |
Add an explicit test case to a HEGEL_TEST.
Place it above the matching HEGEL_TEST, keyed by the same name. The arguments are the values of a hegel::ExplicitTestCase: positional values, taken by the test's draws in order, and hegel::named() values, taken by the draw of that name. Each explicit test case runs once, in the order they appear, before any generated test case.
| #define HEGEL_MAIN | ( | name, | |
| ... ) |
Define a standalone test binary that runs one test case.
Settings::test_cases has no effect, and the TooSlow and TestCasesTooLarge health checks are always suppressed.
Each setting is a command-line option named after its hegel.toml key (e.g. --seed 42, --phases generate,shrink, ...). Each option also takes the form --option=VALUE. Options override settings in the test code, and --profile selects the settings profile those settings are created from.
A failure report ends with the option that replays it, then the test case's exception:
The program exits with status 0 if the test case passes, 1 if it fails, and 2 for a usage error. HEGEL_REPRODUCE_FAILURE and HEGEL_EXPLICIT_TEST_CASE work with the same name.
| #define HEGEL_REPRODUCE_FAILURE | ( | name, | |
| blob, | |||
| ... ) |
Replay a failing example for a HEGEL_TEST from its blob.
Place it above the matching HEGEL_TEST, keyed by the same name. The test then replays that example instead of generating new cases. Delete the annotation to return to a normal run. Settings::print_blob controls whether the report prints the line.
At least one blob is required. Each blob is replayed. If more than one of them makes the test fail, the test throws hegel::MultipleFailures. If none does, it throws hegel::DidNotReproduce.
| #define HEGEL_TEST | ( | name, | |
| ... ) |
Define a Hegel property test.
It expands to a function name(hegel::Settings = ...) that runs that body via hegel::test() with Settings::database_key defaulted to "file.cpp::name" so counterexamples persisted to the database are scoped to this test and replayed on later runs. A database_key set explicitly in the Settings overrides the derived one.
Settings for the test are written inline after the name. They become the function's default argument, and settings passed at the call site replace them entirely.
With a test framework, write the property inside one of its tests and call hegel::test() instead. If you use HEGEL_TEST, it must be used outside of the test framework's test macro/function then call the named Hegel test.