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

line from class fcf::NTest::Fixture

Property: line = 0

Type: unsigned int

Class: fcf::NTest::Fixture

Package: fcfTest

File: test.hpp

Available from version: 1.2.2

The source line number where the fixture was defined.

The line property stores the exact line number in the source code where the fixture was declared via a macro.

Similar to the file property, this is used for error reporting. When a fixture fails, the framework includes this line number in the error message, allowing developers to pinpoint the exact location of the faulty setup or teardown code.

Example: Pinpointing Fixture Errors

Demonstrating how the line property assists in locating the source of a fixture failure.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <stdexcept> // This fixture will fail and throw an exception void demoSetup() { fcf::NTest::log() << "Initializing..." << std::endl; throw std::runtime_error("Critical setup failure!"); } FCF_TEST_DEFINE("ErrorDemo", "Fixture", "Test1") { fcf::NTest::log() << "This test will not run due to fixture error." << std::endl; FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { // Manually adding a setup fixture fcf::NTest::Fixture fixture; fixture.parts.push_back("ErrorDemo"); fixture.groups.push_back("*"); fixture.tests.push_back("*"); fixture.before = true; fixture.level = fcf::NTest::FL_PART; fixture.fixtureFunction = demoSetup; fixture.file = __FILE__; fixture.line = 6; 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:

> Initializing... Performing the test: "ErrorDemo" -> "Fixture" -> "Test1" ... Fixture error [FILE: PATH/main.cpp:6]: Critical setup failure! [FAILED] Test failed (0.000`000`411 sec) [FAILED] Testing completed with failures. Tests: 0 passed, 1 failed, 0 skipped, 1 total Duration: 0.000`000`411 sec