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

error() method from fcf::NTest::State class

void error(const char* a_error, bool a_ignoreExists)

Class: fcf::NTest::State

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Records an error message in the global state.

The error method allows manual recording of error messages into the framework's internal error list.

This is useful for logging failures that occur outside of standard assertions, such as in custom logic or asynchronous tasks.

Arguments

const char* a_error
- The error message string to be recorded.

bool a_ignoreExists = false
- If true, the method will not add the error if an identical message already exists in the error list.

Example: Manually recording an error

Demonstrating how to add a custom error message to the state.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> FCF_TEST_DEFINE("ErrorDemo", "Manual", "RecordError") { fcf::NTest::State& currentState = fcf::NTest::state(); // 1. Record a custom error message currentState.error("Something went wrong manually", false); // 2. Verify that the error was recorded (this test will fail because we added an error) FCF_TEST(!currentState.errors().empty()); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "ErrorDemo" -> "Manual" -> "RecordError" ... Something went wrong manually [FAILED] Test failed (0.000`001`134 sec) [FAILED] Testing completed with failures. Tests: 0 passed, 1 failed, 0 skipped, 1 total Duration: 0.000`001`134 sec