FCF_TEST macro
Package: fcfTest
File: test.hpp
Available from version: 1.0.1
The basic assertion macro. Checks a logical expression and, if it fails, throws
The macro is designed to perform checks (assertions) within test scenarios.
Arguments
- The value of the checked expression. If this expression is false, the test is interrupted and the error is displayed.
- [OPTIONAL] The variables that will be displayed with their values if the check is unsuccessful.
Detailed description
- Evaluates 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.
* Throws a
std::runtime_error exception. -
If the result is
true :* Continues execution without further action.
Example:
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
int getValue() {
return 1;
}
FCF_TEST_DEFINE ("Library1", "Base", "Main test"){
int expected = 10;
// Check the value with context output on error
FCF_TEST (getValue() == expected, getValue(), expected);
}
int main(int a_argc, char* a_argv[]) {
// Standard execution: Parse and run.
bool error = false;
fcf::NTest::cmdRun (a_argc, a_argv, fcf::NTest::CRM_RUN , &error);
return error ? 1 : 0;
}
Output:
Performing the test: "Library1" -> "Base" -> "Main test" ...
Test error: getValue() == expected [FILE: PATH/main.cpp:12]
Values:
getValue(): 1
expected: 10
[FAILED] Test failed (0.000`059`781 sec)
[FAILED] Testing completed with failures.
Tests: 0 passed, 1 failed, 0 skipped, 1 total
Duration: 0.000`059`781 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.