FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

selectors from class fcf::NTest::Options

Property: selectors = []

Type: std::vector<fcf::NTest::Options::Selector>

Class: fcf::NTest::Options

Package: fcfTest

File: test.hpp

Available from version: 1.1.12

A list of selectors used to include specific tests in the execution.

The selectors property is a collection of fcf::NTest::Options::Selector objects. It is used to define which tests should be included during the test run.

Each selector can filter tests based on three hierarchical levels:

  • parts: Filters by the top-level logical grouping.
  • groups: Filters by the sub-grouping level.
  • tests: Filters by the specific test name.

If a selector's vector is empty, it implies that all elements at that level are selected. You can also use the wildcard "*" or an empty string to represent all elements at a specific level.

Multiple selectors are combined using the OR operation. If any selector in the list matches a test, that test will be executed.

Example: Filtering tests using multiple selectors

Demonstrating how to use the fcf::NTest::Options::selectors property to run a specific set of tests by combining different filtering criteria.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <vector> #include <string> // 1. Define a test in the 'Math' part, 'Algebra' group FCF_TEST_DECLARE("Math", "Algebra", "Addition") { FCF_TEST(1 + 1 == 2); } // 2. Define another test in the 'Math' part, 'Geometry' group FCF_TEST_DECLARE("Math", "Geometry", "CircleArea") { FCF_TEST(true); } // 3. Define a test in the 'Physics' part FCF_TEST_DECLARE("Physics", "Mechanics", "Gravity") { FCF_TEST(9.8 > 0); } int main(int a_argc, char* a_argv[]) { // 1. Create an instance of fcf::NTest::Options fcf::NTest::Options options; // 2. Create a selector to include all tests in the 'Math' part // We leave 'groups' and 'tests' empty to select everything within 'Math' fcf::NTest::Options::Selector mathSelector; mathSelector.parts.push_back("Math"); // 3. Create another selector to include only the 'Gravity' test specifically fcf::NTest::Options::Selector gravitySelector; gravitySelector.parts.push_back("Physics"); gravitySelector.groups.push_back("Mechanics"); gravitySelector.tests.push_back("Gravity"); // 4. Add both selectors to the options.selectors list // This will run tests that are in 'Math' OR are the 'Gravity' test options.selectors.push_back(mathSelector); options.selectors.push_back(gravitySelector); // 5. Run the tests bool error = false; fcf::NTest::run(options, &error); return error ? 1 : 0; }

Output:

Performing the test: "Math" -> "Algebra" -> "Addition" ... [SUCCESS] Test completed successfully (0.000`000`291 sec) Performing the test: "Math" -> "Geometry" -> "CircleArea" ... [SUCCESS] Test completed successfully (0.000`000`089 sec) Performing the test: "Physics" -> "Mechanics" -> "Gravity" ... [SUCCESS] Test completed successfully (0.000`000`057 sec) [SUCCESS] All tests were completed. Tests: 3 passed, 0 failed, 0 skipped, 3 total Duration: 0.000`000`437 sec

The test runner executed tests from the "Math" part and the specific "Gravity" test because the selectors were combined using the OR logic.