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

FCF_TEST_CHECK macro

bool FCF_TEST_CHECK (bool am_expression, [mixed am_observedVariable...])

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 FCF_TEST_CHECK macro is a non-interrupting assertion. It is particularly useful when you want to perform multiple checks within a single test case and want to see all failures at once, rather than stopping at the first one.

Arguments

bool am_expression
- The logical expression to evaluate. If it evaluates to false, the error is logged.

mixed am_observedVariable
- [OPTIONAL] A list of variables whose values will be included in the error report if the expression fails.
Detailed description

Behavior:

  1. Evaluates the provided 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.
    • Returns false.
    • Does NOT throw an exception, so the current test function continues to run.
  3. 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