errors() method from fcf::NTest::State class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Returns or sets the list of recorded error messages.
The
This method has two distinct behaviors depending on whether it is used for reading or writing:
- Read Mode: When called without arguments, it returns a copy of the current list of errors (
std::vector<std::string> ). - Write Mode: When called with a
std::vector<std::string> object as an argument, it replaces the existing error list with the provided one.
Arguments
- The new list of error messages to be set in the state.
Result
- A copy of the current list of error messages.
Example: Retrieving recorded errors
Demonstrating how to inspect the errors that have been recorded in the state.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE ("ErrorDemo", "Inspection", "ListErrors") {
fcf::NTest::State & currentState = fcf::NTest::state ();
// 1. Manually add an error for demonstration
currentState.error ("Manual error 1", false);
currentState.error ("Manual error 2", false);
// 2. Retrieve the list of errors
std::vector<std::string> errorList = currentState.errors ();
// 3. Print all errors
fcf::NTest::log () << "Recorded errors:" << std::endl;
for (const auto& errorMsg : errorList) {
fcf::NTest::log () << " - " << errorMsg << std::endl;
}
FCF_TEST (errorList.size() == 2);
}
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" -> "Inspection" -> "ListErrors" ...
> Recorded errors:
> - Manual error 1
> - Manual error 2
Manual error 1
Manual error 2
[FAILED] Test failed (0.000`008`416 sec)
[FAILED] Testing completed with failures.
Tests: 0 passed, 1 failed, 0 skipped, 1 total
Duration: 0.000`008`416 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.