std::set<
fcf::NTest::Test>
selectTests(
const Options& a_options)
const
Class: fcf::NTest::Storage
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
Available from version: 1.2.2
Filters and selects a subset of registered tests based on provided selectors and ignore rules.
The selectTests method is a powerful tool for test filtering. It allows you to precisely define which tests should be included in an execution run and which should be explicitly excluded.
The selection process works by evaluating the provided fcf::NTest::Options::Selector objects against the entire registry of tests.
Filtering logic:
- Inclusion: Tests are selected if they match any of the provided a_options.selectors
- Exclusion: Even if a test matches an inclusion selector, it will be skipped if it also matches any selector in a_options.ignoreSelectors.
- Wildcards: Using "*" or an empty string in a selector component matches all elements at that level (e.g., all groups in a part).
Arguments
const fcf::NTest::Options& a_options
- The configuration object containing inclusion and exclusion selectors.
Result
std::set<fcf::NTest::Test>
- The set where the selected fcf::NTest::Test objects will be stored.
Thrown exceptions
std::runtime_error
- Thrown if a selector specifies a part, group, or test name that does not exist in the registry.
Example: Filtering Tests with Selectors
Demonstrating how to select specific tests using both inclusion and exclusion rules.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE("Lib", "Math", "Add") {
FCF_TEST(true);
}
FCF_TEST_DEFINE("Lib", "Math", "Sub") {
FCF_TEST(true);
}
FCF_TEST_DEFINE("Lib", "IO", "Read") {
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
fcf::NTest::Storage& storage = fcf::NTest::storage();
fcf::NTest::Options options;
// 1. Select all tests in 'Lib' part, but ignore 'Math' group
std::set<fcf::NTest::Test> selectedTests = storage.selectTests(options);
fcf::NTest::log() << "All tests count: " << selectedTests.size() << std::endl;
for(const auto& t : selectedTests) {
fcf::NTest::log() << " " << t.part << "/" << t.group << "/" << t.test << std::endl;
}
// Note: In this example, we manually configure options for the demonstration
options.selectors.push_back({{"Lib"}, {}, {}});
options.ignoreSelectors.push_back({{}, {"Math"}, {}});
// Running selection with configured options
selectedTests = storage.selectTests(options);
fcf::NTest::log() << "Selected tests count: " << selectedTests.size() << std::endl;
for(const auto& t : selectedTests) {
fcf::NTest::log() << " " << t.part << "/" << t.group << "/" << t.test << std::endl;
}
// 3. Run the tests
bool error = false;
fcf::NTest::run(options, &error);
return error ? 1 : 0;
return 0;
}
Output:
> All tests count: 3
> Lib/IO/Read
> Lib/Math/Add
> Lib/Math/Sub
> Selected tests count: 1
> Lib/IO/Read
Performing the test: "Lib" -> "IO" -> "Read" ...
[SUCCESS] Test completed successfully (0.000`000`605 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`000`605 sec