error() method from fcf::NTest::State class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Records an error message in the global state.
The
This is useful for logging failures that occur outside of standard assertions, such as in custom logic or asynchronous tasks.
Arguments
- The error message string to be recorded.
- 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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.