fcf::NTest::cmdRun() function
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
- A reference to the fcf::NTest::Options structure, which will be populated with parsing results (filters for parts, groups, tests, logging levels, etc.)
- Number of command line arguments.
- Array of argument strings.
- The parser operation mode (fcf::NTest::ECmdRunMode ):
fcf::NTest::CRM_PARSE : Only populatesa_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.
- 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
- 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
- Parsing: Supports both
--flag valueand--flag=valuesyntax. - Filtering: Processes
--test-part,--test-group,--test-testflags and their inverse counterparts (--test-ignore-*). - Logging: Sets the global logging level via the
--test-log-levelflag. - Error Handling: If
a_errorPtr is provided, exceptions are caught internally to prevent application crashes. Ifa_errorPtr isnullptr , 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;
}
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.