|
kaycxx-test
C++ unit test framework
|
Unit test framework functions and types. More...
Classes | |
| class | failure |
| Failure result passed to reporters when a test case or suite fails. More... | |
| class | hook |
| Registered setup or teardown hook. More... | |
| class | reporter |
| Receives lifecycle events from the test runner. More... | |
| struct | run_options |
| Configures the execution of registered tests. More... | |
| class | skip_condition |
| Condition used by a test case to decide whether it should be skipped before running hooks and test code. More... | |
| class | skipped |
| Result object passed to reporters when a test case was skipped. More... | |
| struct | test_filter |
| Selects registered tests by source path and full description. More... | |
| class | test_registry |
| Owns a set of test suites and the registration stack used while suite bodies execute. More... | |
Typedefs | |
| using | callback = std::move_only_function< void()> |
| Callable block used by tests, suites, and hooks. | |
Functions | |
| void | after_all (callback body, std::source_location location=std::source_location::current()) |
| Registers a hook that runs once after all tests in the current suite have finished. | |
| void | after_all (hook value) |
| Registers a hook that runs once after all tests in the current suite have finished. | |
| void | after_each (callback body, std::source_location location=std::source_location::current()) |
| Registers a hook that runs after each test in the current suite and its child suites. | |
| void | after_each (hook value) |
| Registers a hook that runs after each test in the current suite and its child suites. | |
| void | before_all (callback body, std::source_location location=std::source_location::current()) |
| Registers a hook that runs once before any tests in the current suite are executed. | |
| void | before_all (hook value) |
| Registers a hook that runs once before any tests in the current suite are executed. | |
| void | before_each (callback body, std::source_location location=std::source_location::current()) |
| Registers a hook that runs before each test in the current suite and its child suites. | |
| void | before_each (hook value) |
| Registers a hook that runs before each test in the current suite and its child suites. | |
| void | describe (std::string_view description, callback body, std::source_location location=std::source_location::current()) |
| Defines a nested test suite and immediately executes its registration body. | |
| void | it (std::string_view description, callback body, std::source_location location=std::source_location::current()) |
| Registers a test case in the current suite. | |
| void | it (std::string_view description, skip_condition skip_condition, callback body, std::source_location location=std::source_location::current()) |
| Registers a test case in the current suite with a skip condition. | |
| int | run_tests () |
| Runs the global test registry and writes the report to standard output. | |
| int | run_tests (int argc, char *argv[]) |
| Runs the global test registry according to command-line arguments. | |
| int | run_tests (std::ostream &output) |
| Runs the global test registry and writes the report to the given stream. | |
| int | run_tests (std::ostream &output, kaycxx::term::ansi_mode ansi_mode) |
| Runs the global test registry and writes the report to the given stream. | |
| int | run_tests (test_registry ®istry, std::ostream &output) |
| Runs the given test registry and writes the report to the given stream. | |
| int | run_tests (test_registry ®istry, std::ostream &output, kaycxx::term::ansi_mode ansi_mode) |
| Runs the given test registry and writes the report to the given stream. | |
| skip_condition | skip (std::string_view reason="") |
| Creates a condition that always skips the test. | |
| skip_condition | skip_if (std::move_only_function< bool()> condition, std::string_view reason="") |
| Creates a condition that skips the test when the callback returns true. | |
| skip_condition | skip_unless (std::move_only_function< bool()> condition, std::string_view reason="") |
| Creates a condition that skips the test unless the callback returns true. | |
| test_registry & | default_registry () |
| Returns the global registry used by the public DSL functions. | |
| test_registry & | active_registry () |
| Returns the registry currently used by the public DSL functions. | |
| test_registry & | set_active_registry (test_registry ®istry) |
| Changes the registry used by the public DSL functions. | |
| void | reset_active_registry () |
| Resets the active registry to the default registry. | |
Unit test framework functions and types.
| using kaycxx::test::callback = typedef std::move_only_function<void()> |
Callable block used by tests, suites, and hooks.
The callback is move-only so test code can capture move-only resources.
| test_registry & kaycxx::test::active_registry | ( | ) |
Returns the registry currently used by the public DSL functions.
The active registry is the default registry unless it has been changed explicitly. This is mainly useful for self-tests and custom embedding scenarios that need to collect DSL registrations in an isolated registry.
| void kaycxx::test::after_all | ( | callback | body, |
| std::source_location | location = std::source_location::current() |
||
| ) |
Registers a hook that runs once after all tests in the current suite have finished.
| body | The hook callback to register. |
| location | Source location used when the hook throws an exception without its own location. |
| void kaycxx::test::after_all | ( | hook | value | ) |
Registers a hook that runs once after all tests in the current suite have finished.
| value | The hook to register. |
| void kaycxx::test::after_each | ( | callback | body, |
| std::source_location | location = std::source_location::current() |
||
| ) |
Registers a hook that runs after each test in the current suite and its child suites.
Hooks run from the innermost suite to the outermost suite.
| body | The hook callback to register. |
| location | Source location used when the hook throws an exception without its own location. |
| void kaycxx::test::after_each | ( | hook | value | ) |
Registers a hook that runs after each test in the current suite and its child suites.
| value | The hook to register. |
| void kaycxx::test::before_all | ( | callback | body, |
| std::source_location | location = std::source_location::current() |
||
| ) |
Registers a hook that runs once before any tests in the current suite are executed.
| body | The hook callback to register. |
| location | Source location used when the hook throws an exception without its own location. |
| void kaycxx::test::before_all | ( | hook | value | ) |
Registers a hook that runs once before any tests in the current suite are executed.
| value | The hook to register. |
| void kaycxx::test::before_each | ( | callback | body, |
| std::source_location | location = std::source_location::current() |
||
| ) |
Registers a hook that runs before each test in the current suite and its child suites.
Hooks run from the outermost suite to the innermost suite.
| body | The hook callback to register. |
| location | Source location used when the hook throws an exception without its own location. |
| void kaycxx::test::before_each | ( | hook | value | ) |
Registers a hook that runs before each test in the current suite and its child suites.
| value | The hook to register. |
| test_registry & kaycxx::test::default_registry | ( | ) |
Returns the global registry used by the public DSL functions.
| void kaycxx::test::describe | ( | std::string_view | description, |
| callback | body, | ||
| std::source_location | location = std::source_location::current() |
||
| ) |
Defines a nested test suite and immediately executes its registration body.
Tests and hooks registered inside the body are added to the nested suite.
| description | Human-readable suite description. |
| body | Registration callback that defines child suites, tests, and hooks. |
| location | Source location of the describe() call. |
| void kaycxx::test::it | ( | std::string_view | description, |
| callback | body, | ||
| std::source_location | location = std::source_location::current() |
||
| ) |
Registers a test case in the current suite.
| description | Human-readable test description. |
| body | Test callback to execute when the test case runs. |
| location | Source location of the test registration. |
| void kaycxx::test::it | ( | std::string_view | description, |
| skip_condition | skip_condition, | ||
| callback | body, | ||
| std::source_location | location = std::source_location::current() |
||
| ) |
Registers a test case in the current suite with a skip condition.
The skip condition is checked before before_each hooks and test code are executed.
| description | Human-readable test description. |
| skip_condition | Condition deciding if the test should be skipped. |
| body | Test callback to execute when the test case runs. |
| location | Source location of the test registration. |
| int kaycxx::test::run_tests | ( | ) |
Runs the global test registry and writes the report to standard output.
| int kaycxx::test::run_tests | ( | int | argc, |
| char * | argv[] | ||
| ) |
Runs the global test registry according to command-line arguments.
Positional path filters select tests by source file or directory. The repeatable -t and –test-name-pattern options select full descriptions with regular expressions. Supported actions are –help and –write-ctest.
| argc | Number of command-line arguments. |
| argv | Command-line argument values. |
| int kaycxx::test::run_tests | ( | std::ostream & | output | ) |
Runs the global test registry and writes the report to the given stream.
| output | Output stream receiving the test report. |
| int kaycxx::test::run_tests | ( | std::ostream & | output, |
| kaycxx::term::ansi_mode | ansi_mode | ||
| ) |
Runs the global test registry and writes the report to the given stream.
| output | Output stream receiving the test report. |
| ansi_mode | Controls ANSI/VT control sequence output. |
| int kaycxx::test::run_tests | ( | test_registry & | registry, |
| std::ostream & | output | ||
| ) |
Runs the given test registry and writes the report to the given stream.
| registry | Registry containing the suites to run. |
| output | Output stream receiving the test report. |
| int kaycxx::test::run_tests | ( | test_registry & | registry, |
| std::ostream & | output, | ||
| kaycxx::term::ansi_mode | ansi_mode | ||
| ) |
Runs the given test registry and writes the report to the given stream.
| registry | Registry containing the suites to run. |
| output | Output stream receiving the test report. |
| ansi_mode | Controls ANSI/VT control sequence output. |
| test_registry & kaycxx::test::set_active_registry | ( | test_registry & | registry | ) |
Changes the registry used by the public DSL functions.
| registry | Registry to use for following DSL registrations. |
| skip_condition kaycxx::test::skip | ( | std::string_view | reason = "" | ) |
Creates a condition that always skips the test.
| reason | Optional reason why the test should be skipped. |
| skip_condition kaycxx::test::skip_if | ( | std::move_only_function< bool()> | condition, |
| std::string_view | reason = "" |
||
| ) |
Creates a condition that skips the test when the callback returns true.
| condition | Callback returning true when the test should be skipped. |
| reason | Optional reason why the test should be skipped. |
| skip_condition kaycxx::test::skip_unless | ( | std::move_only_function< bool()> | condition, |
| std::string_view | reason = "" |
||
| ) |
Creates a condition that skips the test unless the callback returns true.
| condition | Callback returning true when the test should run. |
| reason | Optional reason why the test should be skipped. |