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

    * Throws a std::runtime_error exception.

  3. If the result is true:

    * Continues execution without further action.

Example:

int expected = 10; int actual = get_value(); // Check the value with context output on error FCF_TEST(actual == expected, actual, expected);

Output:

Test error: actual == expected [FILE: main.cpp:15] Values: actual: 7 expected: 10