kaycxx-test
C++ unit test framework
Loading...
Searching...
No Matches
Public Member Functions | List of all members
kaycxx::test::test_registry Class Reference

Owns a set of test suites and the registration stack used while suite bodies execute. More...

#include <kaycxx/test/test_registry.hpp>

Public Member Functions

 test_registry ()
 Creates an empty test registry.
 
 ~test_registry ()
 Destroys the test registry and all registered suites.
 
 test_registry (test_registry const &)=delete
 
test_registryoperator= (test_registry const &)=delete
 
void add_suite (std::string_view description, callback body, std::source_location location=std::source_location::current())
 Adds a suite and immediately executes its registration body.
 
void add_test (std::string_view description, callback body, std::source_location location=std::source_location::current())
 Adds a test case to the current suite.
 
void add_test (std::string_view description, skip_condition condition, callback body, std::source_location location=std::source_location::current())
 Adds a test case with a skip condition to the current suite.
 
void add_before_all_hook (hook value)
 Adds a before_all hook to the current suite.
 
void add_before_each_hook (hook value)
 Adds a before_each hook to the current suite.
 
void add_after_each_hook (hook value)
 Adds an after_each hook to the current suite.
 
void add_after_all_hook (hook value)
 Adds an after_all hook to the current suite.
 
bool run (reporter &reporter, run_options const &options={})
 Executes all registered top-level suites in declaration order.
 
bool run (reporter &reporter, test_filter const &filter, run_options const &options={})
 Executes registered tests selected by a filter.
 
std::vector< std::string > list_tests () const
 Lists all registered test cases in execution order.
 
std::vector< std::string > list_tests (test_filter const &filter) const
 Lists registered test cases selected by a filter in execution order.
 
std::size_t num_test_suites () const
 Returns the number of all registered top-level and nested suites.
 
std::size_t num_test_suites (test_filter const &filter) const
 Returns the number of suites containing tests selected by a filter.
 
std::size_t num_test_cases () const
 Returns the number of all registered test cases.
 
std::size_t num_test_cases (test_filter const &filter) const
 Returns the number of test cases selected by a filter.
 

Detailed Description

Owns a set of test suites and the registration stack used while suite bodies execute.

Member Function Documentation

◆ add_after_all_hook()

void kaycxx::test::test_registry::add_after_all_hook ( hook  value)

Adds an after_all hook to the current suite.

Parameters
valueHook to register.

◆ add_after_each_hook()

void kaycxx::test::test_registry::add_after_each_hook ( hook  value)

Adds an after_each hook to the current suite.

Parameters
valueHook to register.

◆ add_before_all_hook()

void kaycxx::test::test_registry::add_before_all_hook ( hook  value)

Adds a before_all hook to the current suite.

Parameters
valueHook to register.

◆ add_before_each_hook()

void kaycxx::test::test_registry::add_before_each_hook ( hook  value)

Adds a before_each hook to the current suite.

Parameters
valueHook to register.

◆ add_suite()

void kaycxx::test::test_registry::add_suite ( std::string_view  description,
callback  body,
std::source_location  location = std::source_location::current() 
)

Adds a suite and immediately executes its registration body.

If no suite is currently active, this adds a top-level suite. Otherwise it adds a nested suite to the current suite.

Parameters
descriptionHuman-readable suite description.
bodyRegistration callback that defines child suites, tests, and hooks.
locationSource location of the suite declaration.

◆ add_test() [1/2]

void kaycxx::test::test_registry::add_test ( std::string_view  description,
callback  body,
std::source_location  location = std::source_location::current() 
)

Adds a test case to the current suite.

Parameters
descriptionHuman-readable test description.
bodyTest callback to execute.
locationSource location of the test registration.

◆ add_test() [2/2]

void kaycxx::test::test_registry::add_test ( std::string_view  description,
skip_condition  condition,
callback  body,
std::source_location  location = std::source_location::current() 
)

Adds a test case with a skip condition to the current suite.

Parameters
descriptionHuman-readable test description.
conditionCondition deciding if the test should be skipped.
bodyTest callback to execute.
locationSource location of the test registration.

◆ list_tests() [1/2]

std::vector< std::string > kaycxx::test::test_registry::list_tests ( ) const

Lists all registered test cases in execution order.

Duplicate full descriptions are returned only once.

Returns
Unique full descriptions of registered test cases.

◆ list_tests() [2/2]

std::vector< std::string > kaycxx::test::test_registry::list_tests ( test_filter const &  filter) const

Lists registered test cases selected by a filter in execution order.

Parameters
filterTest selection filter. Duplicate full descriptions are returned only once.
Returns
Unique full descriptions of selected test cases.

◆ num_test_cases() [1/2]

std::size_t kaycxx::test::test_registry::num_test_cases ( ) const

Returns the number of all registered test cases.

Returns
The number of all registered test cases.

◆ num_test_cases() [2/2]

std::size_t kaycxx::test::test_registry::num_test_cases ( test_filter const &  filter) const

Returns the number of test cases selected by a filter.

Parameters
filterTest selection filter.
Returns
The number of selected test cases.

◆ num_test_suites() [1/2]

std::size_t kaycxx::test::test_registry::num_test_suites ( ) const

Returns the number of all registered top-level and nested suites.

Returns
The number of all registered top-level and nested suites.

◆ num_test_suites() [2/2]

std::size_t kaycxx::test::test_registry::num_test_suites ( test_filter const &  filter) const

Returns the number of suites containing tests selected by a filter.

Parameters
filterTest selection filter.
Returns
The number of selected top-level and nested suites.

◆ run() [1/2]

bool kaycxx::test::test_registry::run ( reporter reporter,
run_options const &  options = {} 
)

Executes all registered top-level suites in declaration order.

Parameters
reporterReporter receiving lifecycle events.
optionsTest execution options.
Returns
True if all suites passed, false if any suite failed.

◆ run() [2/2]

bool kaycxx::test::test_registry::run ( reporter reporter,
test_filter const &  filter,
run_options const &  options = {} 
)

Executes registered tests selected by a filter.

Suites without selected tests are not executed or reported. Suite hooks execute once for each selected suite.

Parameters
reporterReporter receiving lifecycle events.
filterTest selection filter.
optionsTest execution options.
Returns
True if all selected suites passed, false if any selected suite failed.

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