Type: std::vector<std::string>
Class: fcf::NTest::Fixture
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
A list of part names to which this fixture applies.
The parts property is a collection of strings that defines the scope of the fixture at the 'Part' level. If this vector is empty, the fixture is considered universal and will apply to all parts in the test suite.
When specifying names, you can use the wildcard character "*" (or an empty vector or an empty string that will be replaced by "*" when appended) to match all parts in a particular hierarchy, or specify multiple part names to select a particular subset.
Example: Targeting Specific Parts
Demonstrating how to restrict a fixture to only run for specific parts using the parts property.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
// Fixture added by the macro
FCF_TEST_BEFORE_DEFINE("Math", "*", "*", fcf::NTest::FL_PART) {
fcf::NTest::log() << "Running Math part setup..." << std::endl;
// Create user data for the test
fcf::NTest::state().data("math-const", fcf::NTest::SharedPtrAny::make<int>(1));
}
// Fixture handler function added manually
void manualPhysicsBeforeFixture(){
fcf::NTest::log() << "Running Physics part setup..." << std::endl;
// Create user data for the test
fcf::NTest::state().data("physics-const", fcf::NTest::SharedPtrAny::make<int>(1));
}
FCF_TEST_DEFINE("Math", "Algebra", "Add") {
// Get and check user data created by the fixture
int* mathConstPtr = fcf::NTest::state().data("math-const").cast<int>();
FCF_TEST(*mathConstPtr != 0, *mathConstPtr);
}
FCF_TEST_DEFINE("Physics", "Gravity", "Fall") {
// Get and check user data created by the fixture
int* physicsConstPtr = fcf::NTest::state().data("physics-const").cast<int>();
FCF_TEST(*physicsConstPtr != 0, *physicsConstPtr);
}
int main(int a_argc, char* a_argv[]) {
// Manually adding a fixture
fcf::NTest::Fixture fixture;
fixture.parts.push_back("Physics");
fixture.groups.push_back("*");
fixture.tests.push_back("*");
fixture.before = true;
fixture.level = fcf::NTest::FL_PART;
fixture.fixtureFunction = manualPhysicsBeforeFixture;
fixture.file = __FILE__;
fixture.line = 12;
fcf::NTest::storage().appendFixture(fixture);
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
> Running Math part setup...
Performing the test: "Math" -> "Algebra" -> "Add" ...
[SUCCESS] Test completed successfully (0.000`001`485 sec)
> Running Physics part setup...
Performing the test: "Physics" -> "Gravity" -> "Fall" ...
[SUCCESS] Test completed successfully (0.000`000`911 sec)
[SUCCESS] All tests were completed.
Tests: 2 passed, 0 failed, 0 skipped, 2 total
Duration: 0.000`002`396 sec