mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
Add ability to pass arguments to unit tests from the CLI
Unit tests can now be passed custom arguments from the command line. For example, the following command would run the "mytest" test in the "/main/mycat" category with the option "myoption=54" `CLI> test execute category /main/mycat name mytest options myoption=54` You can also pass options to an entire category... `CLI> test execute category /main/mycat options myoption=54` Basically, everything after the "options" keyword is passed verbatim to the test which must decide what to do with it. * A new API ast_test_get_cli_args() was created to give the tests access to the cli_args->argc and cli_args->argv elements. * Although not needed for the option processing, a new macro ast_test_validate_cleanup_custom() was added to test.h that allows you to specify a custom error message instead of just "Condition failed". * The test_skel.c was updated to demonstrate parsing options and the use of the ast_test_validate_cleanup_custom() macro.
This commit is contained in:
@@ -438,6 +438,30 @@ int __ast_test_status_update(const char *file, const char *func, int line, struc
|
||||
} \
|
||||
})
|
||||
|
||||
/*!
|
||||
* \brief Check a test condition and if false, report custom error message and goto cleanup label.
|
||||
*
|
||||
* This macro evaluates \a condition. If the condition evaluates to true (non-zero),
|
||||
* nothing happens. If it evaluates to false (zero), then the message provided
|
||||
* is printed using \ref ast_test_status_update, the variable \a rc_variable is set
|
||||
* to AST_TEST_FAIL, and a goto to \a cleanup_label is executed.
|
||||
*
|
||||
* \param test Currently executing test
|
||||
* \param condition Boolean condition to check.
|
||||
* \param rc_variable Variable to receive AST_TEST_FAIL.
|
||||
* \param cleanup_label The label to go to on failure.
|
||||
* \param fmt printf type format string
|
||||
* \param ... printf arguments
|
||||
*/
|
||||
#define ast_test_validate_cleanup_custom(test, condition, rc_variable, cleanup_label, fmt, ...) \
|
||||
({ \
|
||||
if (!(condition)) { \
|
||||
__ast_test_status_update(__FILE__, __PRETTY_FUNCTION__, __LINE__, (test), fmt, ## __VA_ARGS__); \
|
||||
rc_variable = AST_TEST_FAIL; \
|
||||
goto cleanup_label; \
|
||||
} \
|
||||
})
|
||||
|
||||
/*!
|
||||
* \brief Initialize the capture structure.
|
||||
*
|
||||
@@ -483,5 +507,14 @@ void ast_test_capture_free(struct ast_test_capture *capture);
|
||||
|
||||
int ast_test_capture_command(struct ast_test_capture *capture, const char *file, char *const argv[], const char *data, unsigned datalen);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the cli arguments from the ast_test structure
|
||||
*
|
||||
* \param test Currently executing test
|
||||
*
|
||||
* \retval A pointer to the ast_cli_args structure used to invoke the test
|
||||
*/
|
||||
struct ast_cli_args *ast_test_get_cli_args(struct ast_test *test);
|
||||
|
||||
#endif /* TEST_FRAMEWORK */
|
||||
#endif /* _AST_TEST_H */
|
||||
|
Reference in New Issue
Block a user