FCF_TEST_CHECK macro
Package: fcfTest
File: test.hpp
Available from version: 1.1.7
A non-throwing assertion macro. It checks a logical expression and, if the check fails, adds the error to the test error list with detailed context, while allowing the test execution to continue.
The
Arguments
- The logical expression to evaluate. If it evaluates to false, the error is logged.
- [OPTIONAL] A list of variables whose values will be included in the error report if the expression fails.
Detailed description
- Evaluates the provided expression.
-
If the result is
false :-
Generates an error message containing:
- A text representation of the original expression.
- The path to the file and line number where the error occurred.
- A list of the names and current values of all passed variables arguments
- Adds error information to the current test state.
- Returns
false . - Does NOT throw an exception, so the current test function continues to run.
-
-
If the result is
true :* Returns
true and continues execution.
Example:
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <vector>
FCF_TEST_DECLARE ("Logic", "Flow", "NonBreakingTest") {
int a = 5;
int b = 10;
int c = 16;
// Using FCF_TEST_CHECK to verify multiple conditions.
// Even if the first check fails, the second one will still be executed.
if (!FCF_TEST_CHECK (a + b == c, a, b, c)) {
fcf::NTest::log () << "First check failed, but I am still running!" << std::endl;
}
// This line will always be reached regardless of the previous check's result.
FCF_TEST_CHECK (c < 0, c) ;
}
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: "Logic" -> "Flow" -> "NonBreakingTest" ...
> First check failed, but I am still running!
Test error: a + b == c [FILE: PATH/main.cpp:12]
Values:
a: 5
b: 10
c: 16
Test error: c < 0 [FILE: PATH/main.cpp:17]
Values:
c: 16
[FAILED] Test failed (0.000`067`480 sec)
[FAILED] Testing completed with failures.
Tests: 0 passed, 1 failed, 0 skipped, 1 total
Duration: 0.000`067`480 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.