PicoTest
A minimalist unit testing framework for C programs
|
Topics | |
Test Cases | |
Assertions | |
Test Fixtures | |
Test Suites |
Data Structures | |
struct | PicoTestMetadata |
Test metadata. More... |
Test Filters | |
PicoTest provides a way for client code to select tests to be run using custom filter functions. | |
enum | PicoTestFilterResult { PICOTEST_FILTER_SKIP , PICOTEST_FILTER_PASS , PICOTEST_FILTER_SKIP_PROPAGATE , PICOTEST_FILTER_PASS_PROPAGATE } |
Result of test filter functions. More... | |
typedef PicoTestFilterResult | PicoTestFilterProc(PicoTestProc *test, const char *testName, const char *cond) |
Signature of test filter functions. | |
#define | PICOTEST_FILTER_DEFAULT |
Default test filter function. | |
#define | PICOTEST_FILTER |
Define the test filter function. |
Test hierarchy traversal | |
Tests can form hierarchies of test suites and test cases. PicoTest provides two ways to traverse such hierarchies with a simple visitor pattern. This can be used for e.g. test list discovery in build systems. | |
enum | PicoTestVisitStep { PICOTEST_VISIT_ENTER , PICOTEST_VISIT_LEAVE } |
Test visit step. More... | |
typedef void | PicoTestTraverseProc(const char *name, int nb) |
Function signature of test traversal proc. | |
typedef void | PicoTestVisitProc(const PicoTestMetadata *metadata, PicoTestVisitStep step) |
Function signature of test visit proc. | |
#define | PICOTEST_TRAVERSE(_testName, _proc) |
Traverse a test hierarchy depth-first. | |
#define | PICOTEST_VISIT(_testName, _proc) |
Visit a test hierarchy depth-first. |
Test Functions | |
typedef int | PicoTestProc(const char *cond) |
Signature of test functions. | |
#define | PICOTEST_EXTERN(_testName) |
Declare an extern test for metadata access. | |
#define | PICOTEST_METADATA(_testName) |
Get test metadata. |
Logging | |
PicoTest provides a way for client code to intercept test failure events. This can be used for e.g. logging purpose or reporting. | |
typedef void | PicoTestFailureLoggerProc(const char *file, int line, const char *type, const char *test, const char *msg, va_list args) |
Function signature of test failure log handlers. | |
#define | PICOTEST_FAILURE_LOGGER_DEFAULT |
Default test failure log handler. | |
#define | PICOTEST_FAILURE_LOGGER |
Define the test failure log handler. |
struct PicoTestMetadata |
Test metadata.
Data Fields | ||
---|---|---|
const char * | name |
Test name. |
const char * | file |
Test file location. |
int | line |
Test line location. |
PicoTestProc *const | test |
Test function. |
int | nbSubtests |
Number of subtests. |
const struct PicoTestMetadata ** | subtests |
Subtests (NULL-terminated array for test suites, NULL pointer for test cases). |
#define PICOTEST_EXTERN | ( | _testName | ) |
Declare an extern test for metadata access.
_testName | Test name. |
#define PICOTEST_METADATA | ( | _testName | ) |
Get test metadata.
_testName | Test name. |
#define PICOTEST_FILTER_DEFAULT |
Default test filter function.
Does a simple string equality test between testName and cond, and propagates to subtests if it doesn't match.
#define PICOTEST_FILTER |
Define the test filter function.
Called before calling a test with a non- NULL condition.
The default filter does a simple string equality test between its testName and cond arguments, and propagates to subtests if it doesn't match. Redefine this macro to use a custom filter function, which must follow the PicoTestFilterProc signature.
#define PICOTEST_TRAVERSE | ( | _testName, | |
_proc ) |
Traverse a test hierarchy depth-first.
This feature covers simple use cases such as getting the flat list of all test names. For more advanced usage, see PICOTEST_VISIT.
_testName | Name of the traversed test. |
_proc | Test traversal proc. Must follow the PicoTestTraverseProc signature. |
#define PICOTEST_VISIT | ( | _testName, | |
_proc ) |
Visit a test hierarchy depth-first.
This feature covers more advanced use cases than PICOTEST_TRAVERSE, such as exporting the test hierarchy as a structured format such as XML or JSON, or accessing test metadata.
_testName | Name of the visited test. |
_proc | Test visit proc. Must follow the PicoTestVisitProc signature. |
#define PICOTEST_FAILURE_LOGGER_DEFAULT |
Default test failure log handler.
Does nothing.
#define PICOTEST_FAILURE_LOGGER |
Define the test failure log handler.
Called when a test fails.
The default handler does nothing. Redefine this macro to use a custom handler, which must follow the PicoTestFailureLoggerProc signature.
typedef int PicoTestProc(const char *cond) |
Signature of test functions.
Both Test Suites and Test Cases follow this signature.
cond | Test filtering condition, or NULL. In the former case, passed to the active test filter before running the test. |
typedef PicoTestFilterResult PicoTestFilterProc(PicoTestProc *test, const char *testName, const char *cond) |
Signature of test filter functions.
A test called with a non- NULL condition must match this condition to be run. The test filter is set using the PICOTEST_FILTER macro.
test | Test function to filter. |
testName | Name of test to filter. |
cond | Test filtering condition. |
typedef void PicoTestTraverseProc(const char *name, int nb) |
Function signature of test traversal proc.
name | Name of traversed test. |
nb | Number of subtests (zero for simple test cases, at least one for test suites). |
typedef void PicoTestVisitProc(const PicoTestMetadata *metadata, PicoTestVisitStep step) |
Function signature of test visit proc.
Proc is called once for each value of PicoTestVisitStep.
metadata | Metadata of the visited test. |
step | Visit step. |
typedef void PicoTestFailureLoggerProc(const char *file, int line, const char *type, const char *test, const char *msg, va_list args) |
Function signature of test failure log handlers.
file | File name where the test was defined. |
line | Location of test in file. |
type | Type of test that failed (e.g. "ASSERT"). |
test | Tested expression. |
msg | Optional message format string, or NULL. |
args | Optional message string parameter list, or NULL. |
enum PicoTestFilterResult |
Result of test filter functions.
enum PicoTestVisitStep |
Test visit step.
Enumerator | |
---|---|
PICOTEST_VISIT_ENTER | Enter the test. |
PICOTEST_VISIT_LEAVE | Leave the test. |