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(fcf::NTest::Options& a_dstOptions, int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode, bool* a_errorPtr = 0)
fcf::NTest::ECmdMode fcf::NTest::cmdRun(int a_argc, const char* const* a_argv, fcf::NTest::ECmdRunMode a_runMode, bool* a_errorPtr = 0)

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_dstOptions
- A reference to the fcf::NTest::Options structure, which will be populated with parsing results (filters for parts, groups, tests, logging levels, etc.)

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 a null pointer is passed, 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 a_errorPtr is provided, exceptions are caught internally to prevent application crashes. If a_errorPtr is nullptr, the exception is rethrown.

Example:

#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; }

Example:

#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; }

Example:

#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; }