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

FCF_TEST macro

FCF_TEST (bool am_expression, [mixed am_displayVariable...])

Package: fcfTest

File: test.hpp

Available from version: 1.0.1

The basic assertion macro. Checks a logical expression and, if it fails, throws std::runtime_error with a detailed report: the original expression, file, line of code, and the values ​​of the passed variables.

The macro is designed to perform checks (assertions) within test scenarios.

Arguments

bool am_expression
- The value of the checked expression. If this expression is false, the test is interrupted and the error is displayed.

mixed am_displayVariable
- [OPTIONAL] The variables that will be displayed with their values if the check is unsuccessful.
Detailed description

Behavior:

  1. Evaluates expression
  2. 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.

  3. 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