|
micro-test-plus 4.1.0
µTest++ Testing Framework
|
A named, runnable test case that lives inside a suite. More...
#include <micro-os-plus/micro-test-plus.h>
Public Member Functions | |
| template<typename Callable_T, typename... Args_T> | |
| subtest (const char *name, class runner &runner, suite &parent_suite, size_t own_index, size_t nesting_depth, Callable_T &&callable, Args_T &&... arguments) | |
| Constructs a subtest with a name, runner, parent suite, index, nesting depth, and callable. | |
| subtest (const subtest &)=delete | |
| Deleted copy constructor to prevent copying. | |
| subtest (subtest &&)=delete | |
| Deleted move constructor to prevent moving. | |
| virtual | ~subtest () override |
| Virtual destructor. | |
| void | abort (const reflection::source_location &sl=reflection::source_location::current()) |
| Aborts test execution via the owning runner. | |
| template<class Expr_T> requires type_traits::checkable<Expr_T> | |
| auto | assume (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current()) |
| Check a condition and, if false, abort test execution. | |
| size_t | children_subtests_count (void) const noexcept |
| Returns the number of direct child subtests owned by this node. | |
| size_t | current_subtest_index () const noexcept |
| Returns the index of the most recently created child subtest. | |
| template<class Expr_T> requires type_traits::checkable<Expr_T> | |
| auto | expect (const Expr_T &expr, const reflection::source_location &sl=reflection::source_location::current()) |
| Evaluate a generic condition and report the results. | |
| size_t | increment_subtest_index () noexcept |
| Increments and returns the child subtest sequential index. | |
| const char * | name (void) const noexcept |
| Gets the node name. | |
| size_t | nesting_depth () const noexcept |
| Returns the nesting depth of this subtest. | |
| subtest & | operator= (const subtest &)=delete |
| Deleted copy assignment operator to prevent copying. | |
| subtest & | operator= (subtest &&)=delete |
| Deleted move assignment operator to prevent moving. | |
| size_t | own_index () const noexcept |
| Returns the positional index of this object within its parent. | |
| void | own_index (size_t index) noexcept |
| Sets the positional index of this object within its parent. | |
| class reporter & | reporter (void) const noexcept |
| Gets the test reporter associated with this test runnable. | |
| virtual void | run (void) override |
| Executes the subtest body by invoking the stored callable. | |
| class runner & | runner (void) const noexcept |
| Gets the test runner associated with this test runnable. | |
| template<typename Callable_T, typename... Args_T> | |
| void | test (const char *name, Callable_T &&callable, Args_T &&... arguments) |
| Adds a test case to the suite. | |
| const runner_totals & | totals () const noexcept |
| Gets the totals for the test (const overload). | |
| runner_totals & | totals () noexcept |
| Gets the totals for the test. | |
Protected Member Functions | |
| void | after_subtest_create_ (std::unique_ptr< subtest > child_test, suite &suite) |
| Registers a newly constructed child subtest and executes it immediately. | |
Protected Attributes | |
| std::function< void(subtest &)> | callable_ |
| Callable storing the test body and any bound arguments. Invoked with a reference to the derived Self_T instance. | |
| std::vector< std::unique_ptr< subtest > > | children_subtests_ |
| Owning collection of direct child subtests. | |
| size_t | current_subtest_index_ |
| The subtest index, counting from 1. | |
| const char * | name_ |
| The test node name. | |
| size_t | nesting_depth_ |
| The nesting depth of this subtest within the suite. | |
| size_t | own_index_ |
| The test index, counting from 1. | |
| suite & | parent_suite_ |
| Reference to the parent suite that owns this subtest. | |
| class runner & | runner_ |
| Reference to the test runner that owns this object. | |
| runner_totals | totals_ |
| Totals for the test node, including nested cases. | |
subtest represents a single, named test case or a nested group of checks within a parent suite or subtest. It is constructed by calling suite::test() or subtest::test(), both of which create the object, immediately execute its callable body via run(), and register the result with the parent node.
The body of the subtest is supplied as a callable (typically a lambda) that receives a subtest& reference as its first argument. Inside the body, expect() and assume() are used to evaluate conditions and record the results. Subtests may be nested to an arbitrary depth.
The class is non-copyable and non-movable to preserve unique ownership and consistent state throughout the test session.
| micro_os_plus::micro_test_plus::subtest::subtest | ( | const char * | name, |
| class runner & | runner, | ||
| suite & | parent_suite, | ||
| size_t | own_index, | ||
| size_t | nesting_depth, | ||
| Callable_T && | callable, | ||
| Args_T &&... | arguments ) |
| Callable_T | The type of a callable object. |
| Args_T | The types of the callable arguments. |
| [in] | name | The subtest name or description, used in reports. |
| [in] | runner | The test runner managing this subtest. |
| [in] | parent_suite | The suite that owns this subtest. |
| [in] | own_index | The one-based positional index within the parent. |
| [in] | nesting_depth | The depth of nesting; 1 for top-level subtests. |
| [in] | callable | A generic callable object, usually a lambda, invoked when the subtest executes. |
| [in] | arguments | A possibly empty list of arguments forwarded to the callable after the leading subtest& reference. |
Delegates to runnable, which binds the callable with its arguments.
Definition at line 262 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::runnable< subtest >::runnable(), subtest(), micro_os_plus::micro_test_plus::detail::runnable< subtest >::name(), nesting_depth(), micro_os_plus::micro_test_plus::detail::runnable< subtest >::own_index(), and micro_os_plus::micro_test_plus::detail::runnable< subtest >::runner().
Referenced by subtest(), subtest(), subtest(), operator=(), and operator=().
|
delete |
References subtest().
|
delete |
References subtest().
|
overridevirtual |
The destructor releases any resources associated with the subtest instance. If tracing is enabled, it outputs the function signature for diagnostic purposes. This ensures that the test suite is properly cleaned up after execution, supporting robust and reliable test management across all files and folders within the µTest++ framework.
Definition at line 275 of file test.cpp.
References micro_os_plus::micro_test_plus::detail::runnable< subtest >::name_.
|
inherited |
| sl | The source location from which the abort is triggered. |
Delegates immediately to runner_.abort(), passing the supplied source location so that the error message identifies the call site before the process is terminated via ::abort().
Definition at line 369 of file test.cpp.
References name_, and reporter().
|
protectedinherited |
| child_test | Owning pointer to the newly created subtest. |
| suite | The parent suite to which execution results are reported. |
Transfers ownership of child_test into children_subtests_ and immediately invokes subtest::run() on the newly stored subtest. The parent's executed-subtest counter is then incremented. The child's check counters are intentionally not merged into the parent totals; each subtest reports only its own counters. The child's totals are, however, accumulated into suite so that the suite summary reflects all checks performed by its subtests.
Definition at line 394 of file test.cpp.
|
inlinenodiscardnoexceptinherited |
Returns the number of child subtests owned by this node.
Definition at line 349 of file test-inlines.h.
|
inlinenodiscardnoexceptinherited |
Returns the sequential index of the most recently created child subtest.
Definition at line 329 of file test-inlines.h.
|
inlinenoexceptinherited |
Each call to test() invokes this method before constructing the new subtest, so the index values form a strictly increasing, one-based sequence.
Definition at line 339 of file test-inlines.h.
|
inlinenodiscardnoexceptinherited |
Returns a pointer to the null-terminated name stored in name_.
Definition at line 194 of file test-inlines.h.
Referenced by micro_os_plus::micro_test_plus::subtest::subtest(), micro_os_plus::micro_test_plus::subtest::operator=(), own_index(), runner(), micro_os_plus::micro_test_plus::subtest::test(), and totals().
|
inlinenodiscardnoexcept |
Top-level subtests (direct children of a suite) have depth 1. Each additional level of nesting increments the depth by 1.
Definition at line 357 of file test-inlines.h.
References nesting_depth_.
Referenced by subtest(), micro_os_plus::micro_test_plus::reporter_human::begin_subtest(), micro_os_plus::micro_test_plus::reporter_tap::begin_subtest(), micro_os_plus::micro_test_plus::reporter_human::end_subtest(), micro_os_plus::micro_test_plus::reporter_tap::end_subtest(), operator=(), micro_os_plus::micro_test_plus::reporter_human::output_fail_prefix_(), micro_os_plus::micro_test_plus::reporter_tap::output_fail_prefix_(), micro_os_plus::micro_test_plus::reporter_tap::output_fail_suffix_(), micro_os_plus::micro_test_plus::reporter_human::output_pass_prefix_(), and micro_os_plus::micro_test_plus::reporter_tap::output_pass_prefix_().
References subtest().
|
inlinenodiscardnoexceptinherited |
Returns the one-based positional index of this object within its parent.
Definition at line 305 of file test-inlines.h.
References name(), own_index(), and runner().
Referenced by micro_os_plus::micro_test_plus::subtest::subtest(), and own_index().
|
inlinenoexceptinherited |
| index | The new index value. |
Sets the positional index of this object within its parent.
Definition at line 319 of file test-inlines.h.
|
nodiscardnoexceptinherited |
Delegates immediately to runner_.reporter(), returning the reporter associated with the owning runner instance.
Definition at line 359 of file test.cpp.
Referenced by abort(), micro_os_plus::micro_test_plus::subtest::assume(), micro_os_plus::micro_test_plus::subtest::expect(), and micro_os_plus::micro_test_plus::subtest::run().
|
overridevirtual |
Invokes the stored callable with the Self_T instance, surrounded by reporter calls to begin and end the subtest.
Implements micro_os_plus::micro_test_plus::detail::runnable< subtest >.
Definition at line 298 of file test.cpp.
References micro_os_plus::micro_test_plus::reporter::begin_subtest(), micro_os_plus::micro_test_plus::detail::runnable< subtest >::callable_, micro_os_plus::micro_test_plus::detail::runnable< subtest >::name_, and micro_os_plus::micro_test_plus::detail::runnable< subtest >::reporter().
Referenced by micro_os_plus::micro_test_plus::detail::runnable_base::after_subtest_create_(), and operator=().
|
inlinenodiscardnoexceptinherited |
Returns a reference to the owning test runner.
Definition at line 380 of file test-inlines.h.
References name(), and own_index_.
Referenced by micro_os_plus::micro_test_plus::subtest::subtest(), and own_index().
| void micro_os_plus::micro_test_plus::subtest::test | ( | const char * | name, |
| Callable_T && | callable, | ||
| Args_T &&... | arguments ) |
| Callable_T | The type of a callable object. |
| Args_T | The types of the callable arguments. |
| [in] | name | The test case name or description, used in reports. |
| [in] | callable | A generic callable object, usually a lambda, invoked to perform the test. |
| [in] | arguments | A possibly empty list of arguments to be passed to the callable. |
Allocates a child subtest on the heap, incrementing the subtest index and deepening the nesting level by one relative to this subtest's depth, then transfers ownership to the framework via after_subtest_create_().
Definition at line 295 of file test-inlines.h.
References micro_os_plus::micro_test_plus::detail::runnable< subtest >::name().
Referenced by operator=().
|
inlinenodiscardnoexceptinherited |
Returns a const reference to the runner_totals member.
Definition at line 215 of file test-inlines.h.
References name(), and own_index_.
|
inlinenodiscardnoexceptinherited |
Returns a reference to the runner_totals member.
Definition at line 205 of file test-inlines.h.
References callable_.
|
protectedinherited |
Definition at line 512 of file test.h.
Referenced by micro_os_plus::micro_test_plus::subtest::run(), and totals().
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
Definition at line 224 of file test.h.
Referenced by micro_os_plus::micro_test_plus::subtest::~subtest(), abort(), and micro_os_plus::micro_test_plus::subtest::run().
|
protected |
Definition at line 688 of file test.h.
Referenced by nesting_depth().
|
protectedinherited |
|
protected |
|
protectedinherited |
|
protectedinherited |