selectTests() method from fcf::NTest::Storage class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.2
Filters and selects a subset of registered tests based on provided selectors and ignore rules.
The
The selection process works by evaluating the provided
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). - Exclusion: Even if a test matches an inclusion selector, it will be skipped if it also matches any selector in
Arguments
- The configuration object containing inclusion and exclusion selectors.
Result
- The set where the selected fcf::NTest::Test objects will be stored.
Thrown exceptions
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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.