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

fcf::NTest::cmdRun() function

fcf::NTest::ECmdMode fcf::NTest::cmdRun(int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode)
fcf::NTest::ECmdMode fcf::NTest::cmdRun(int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode, bool* a_errorPtr)
fcf::NTest::ECmdMode fcf::NTest::cmdRun(fcf::NTest::Options& a_dstsrcOptions, int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode)
fcf::NTest::ECmdMode fcf::NTest::cmdRun(fcf::NTest::Options& a_dstsrcOptions, int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode, bool* a_errorPtr)

Package: fcfTest

File: test.hpp

Available from version: 1.0.1

The central function for executing the test suite. It performs command-line argument parsing, test filtering, and execution according to the specified run mode.

This function serves as the primary interface for integrating the testing framework into an application. It automates the process of processing user input and managing the execution of test scenarios.

Arguments

fcf::NTest::Options& a_dstsrcOptions
- A reference to the fcf::NTest::Options structure, which stores unit test execution parameters. Parameters entered via the command line will be added to this structure.

int a_argc
- Number of command line arguments.

const char* const* a_argv
- Array of argument strings.

fcf::NTest::ECmdRunMode a_runMode
- The parser operation mode (fcf::NTest::ECmdRunMode):
  • fcf::NTest::CRM_PARSE: Only populates a_dstOptions.
  • fcf::NTest::CRM_EXECUTE: Parses arguments and immediately executes tests (if the --test-run flag is provided) or displays help/list information (if the --test-help/--test-list flags is provided).
  • fcf::NTest::CRM_RUN: Automatically executes all tests unless help or list (--test-help/--test-list) flags are explicitly requested.

bool* a_errorPtr = 0
- A pointer to a variable that receives information about a test error. If an error occurs, the variable's value is set to true; otherwise, it is set to false. If the function instance is called without this argument, the function throws an exception.
Result
fcf::NTest::ECmdMode
- returns the selected mode based on the parameters of the command line a_argv.
  • fcf::NTest::ECmdMode: Indicates the mode selected by the user via command-line arguments:
    • fcf::NTest::CM_NONE: No control flags were detected.
    • fcf::NTest::CM_RUN: The --test-run flag was detected.
    • fcf::NTest::CM_LIST: The --test-list flag was detected.
    • fcf::NTest::CM_HELP: The --test-help flag was detected.
Detailed description

  1. Parsing: Supports both --flag value and --flag=value syntax.
  2. Filtering: Processes --test-part, --test-group, --test-test flags and their inverse counterparts (--test-ignore-*).
  3. Logging: Sets the global logging level via the --test-log-level flag.
  4. Error Handling: If the a_errorPtr parameter is specified, the argument's value is set to true (if non-zero) when an error occurs. If the function instance is called without this argument, the function throws an exception.

Example: The testing application that runs tests on every launch.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> FCF_TEST_DECLARE("Library1", "Base", "Main test"){ } 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" ... [SUCCESS] Test completed successfully (0.000`000`248 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`000`248 sec

Example: The testing application that runs tests only on request.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> FCF_TEST_DECLARE("Library1", "Base", "Main test"){ } int main(int a_argc, char* a_argv[]) { // Standard execution: Parse and run by request. bool error = false; int mode = fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_EXECUTE, &error); if (error) { // An error occurred while running a test. return 1; } if (mode != fcf::NTest::CM_NONE){ // The --test-run | --test-help | ---test-list flags were passed at startup. // And the function performed all the actions return 0; } // .... your application code ... return 0; }

Output:

Performing the test: "Library1" -> "Base" -> "Main test" ... [SUCCESS] Test completed successfully (0.000`000`205 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`000`205 sec

To run the tests, you need to execute it with the command-line argument:

test --test-run

Example: Custom user input handling.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> FCF_TEST_DECLARE("Library1", "Base", "Main test"){ } int main(int a_argc, char* a_argv[]) { // Or custom menu mode: Just parse to see what was asked fcf::NTest::Options options; int mode = fcf::NTest::cmdRun(options, a_argc, a_argv, fcf::NTest::CRM_PARSE); if (mode == fcf::NTest::CM_HELP) { fcf::NTest::cmdHelp(); return 0; } else if (mode == fcf::NTest::CM_LIST) { fcf::NTest::cmdList(); return 0; } else if (mode == fcf::NTest::CM_RUN) { bool error = false; fcf::NTest::run(options, &error); return error ? 1 : 0; } // ... default execution return 0; }