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

Selector class
From fcf::NTest::Options class

Type:
class fcf::NTest::Options::Selector

Owner class: fcf::NTest::Options

Package: fcfTest

File: test.hpp

Available from version: 1.1.12

A filtering criteria structure used to select or exclude tests based on their hierarchical position (Part, Group, or Test name).

The fcf::NTest::Options::Selector class is a specialized structure used to define filtering rules for the test runner. It allows for precise control over which tests are included in or excluded from the execution suite by matching their hierarchical metadata.

A single Selector can contain multiple values for each level, effectively creating an OR relationship between the strings within the same level. For example, if parts contains both "Math" and "Physics", the selector will match any test belonging to either part.

Key features of the selection logic:

  • Hierarchical Filtering: You can filter by parts, groups, or tests.

  • Wildcards: Using an empty string "" or the asterisk "*" in any vector acts as a wildcard, selecting all elements at that specific level. All elements are also selected if the vector is empty.

    Example:

    fcf::NTest::Options::Selector group1 = {{"MyPart"}, {"MyGroup1"}, {"*"}}; fcf::NTest::Options::Selector group2 = {{"MyPart"}, {"MyGroup2"}, {""}}; fcf::NTest::Options::Selector group3 = {{"MyPart"}, {"MyGroup3"}, {}};

  • Multi-element Matching: A single group can contain multiple values. In this case, the OR operation is used during searching/matching..

    Example:

    fcf::NTest::Options::Selector selector = {{"MyPart"}, {"MyGroup"}, {"MyTest1", "MyTest2"}};

  • Multi-level Matching: A selector matches a test only if it satisfies the criteria across all non-empty levels provided (e.g., a specific Part AND a specific Group AND a specific Test).

Properties
std::vector<std::string> parts = []
- A list of part names to include in the test selection.
std::vector<std::string> groups = []
- A list of group names to include in the test selection.
std::vector<std::string> tests = []
- A list of specific test names to include in the test selection.

Example: Manual Selector Configuration

Demonstrating how to manually construct a fcf::NTest::Options::Selector to target a specific group within a specific part.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <vector> #include <string> // 1. Define some tests to have something to select FCF_TEST_DEFINE("Math", "Algebra", "Add") { FCF_TEST(true); } FCF_TEST_DEFINE("Math", "Algebra", "Sub") { FCF_TEST(true); } FCF_TEST_DEFINE("Math", "Geometry", "Area") { FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { // 2. Create the Options object fcf::NTest::Options options; // 3. Create a new Selector instance fcf::NTest::Options::Selector mySelector; // 4. Configure the selector to match: Part "Math" AND Group "Algebra" // We add "Math" to the parts vector mySelector.parts.push_back("Math"); // We add "Algebra" to the groups vector mySelector.groups.push_back("Algebra"); // 5. Add this selector to the options.selectors list options.selectors.push_back(mySelector); // 6. Run the tests. Only 'Add' and 'Sub' should be executed. bool error = false; fcf::NTest::run(options, &error); return error ? 1 : 0; }

Output:

Performing the test: "Math" -> "Algebra" -> "Add" ... [SUCCESS] Test completed successfully (0.000`000`264 sec) Performing the test: "Math" -> "Algebra" -> "Sub" ... [SUCCESS] Test completed successfully (0.000`000`113 sec) [SUCCESS] All tests were completed. Tests: 2 passed, 0 failed, 0 skipped, 2 total Duration: 0.000`000`377 sec

The selector successfully filtered the tests, running only those that belonged to the 'Math' part and the 'Algebra' group, effectively skipping the 'Geometry' group.