PicoTest
A minimalist unit testing framework for C programs
Loading...
Searching...
No Matches
Test Suites

Test Suite Hooks

PicoTest provides a way for client code to intercept test execution events on test suites and their subtests. This can be used for e.g. logging purpose or reporting.

typedef void PicoTestSuiteEnterProc(const char *suiteName, int nb)
 Function signature of test suite enter hooks.
typedef void PicoTestSuiteLeaveProc(const char *suiteName, int nb, int fail)
 Function signature of test suite leave hooks.
typedef void PicoTestSuiteBeforeSubtestProc(const char *suiteName, int nb, int fail, int index, const char *testName)
 Function signature of test suite before subtest hooks.
typedef void PicoTestSuiteAfterSubtestProc(const char *suiteName, int nb, int fail, int index, const char *testName, int sfail)
 Function signature of test suite after subtest hooks.
#define PICOTEST_SUITE_ENTER_DEFAULT(suiteName, nb)
 Default test suite enter hook.
#define PICOTEST_SUITE_ENTER
 Define the test suite enter hook.
#define PICOTEST_SUITE_LEAVE_DEFAULT(suiteName, nb, fail)
 Default test suite leave hook.
#define PICOTEST_SUITE_LEAVE
 Define the test suite leave hook.
#define PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT(suiteName, nb, fail, index, testName)
 Default test suite before subtest hook.
#define PICOTEST_SUITE_BEFORE_SUBTEST
 Define the test suite before subset hook.
#define PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT(suiteName, nb, fail, index, testName, sfail)
 Default test suite after subtest hook.
#define PICOTEST_SUITE_AFTER_SUBTEST
 Define the test suite after subset hook.

Test Suite Definitions

#define PICOTEST_SUITE(_suiteName, ...)
 Test suite declaration.

Detailed Description

A test suite is a set of subtests in no special order. These subtests can themselves be test suites or test cases.

Macro Definition Documentation

◆ PICOTEST_SUITE

#define PICOTEST_SUITE ( _suiteName,
... )

Test suite declaration.

A test suite is a test function that is made of one or several subtests.

This macro defines a PicoTestProc of the given name that can be called directly.

Parameters
_suiteNameName of the test suite.
...Names of the subtests in the suite.
Returns
Number of failed tests.
See also
PicoTestProc
PICOTEST_CASE
Usage
/* Main test suite */
PICOTEST_SUITE(mainSuite,
testCase1, testCase2, subSuite, testCase3
)
/* Sub-suite */
PICOTEST_SUITE(subSuite,
testCase4, testCase5
)
Examples
mainSuite.inc Example of a simple PicoTest suite.

◆ PICOTEST_SUITE_ENTER_DEFAULT

#define PICOTEST_SUITE_ENTER_DEFAULT ( suiteName,
nb )

Default test suite enter hook.

Does nothing.

See also
PicoTestSuiteEnterProc
PICOTEST_SUITE_ENTER

◆ PICOTEST_SUITE_ENTER

#define PICOTEST_SUITE_ENTER

Define the test suite enter hook.

The default hook does nothing. Redefine this macro to use a custom hook, which must follow the PicoTestSuiteEnterProc signature.

Note
Custom functions only apply to the tests defined after the macro redefinition. As macros can be redefined several times, this means that different functions may apply for the same source.
Usage
/* Hook declarations. */
PicoTestSuiteEnterProc enterTestSuite;
#undef PICOTEST_SUITE_ENTER
#define PICOTEST_SUITE_ENTER enterTestSuite
/* Hook function. */
void enterTestSuite(const char *suiteName, int nb) {
indent(level++);
printf("running test suite %s (%d subtests)...\n", suiteName, nb);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PicoTestSuiteEnterProc
PICOTEST_SUITE_ENTER_DEFAULT
PICOTEST_SUITE_LEAVE

◆ PICOTEST_SUITE_LEAVE_DEFAULT

#define PICOTEST_SUITE_LEAVE_DEFAULT ( suiteName,
nb,
fail )

Default test suite leave hook.

Does nothing.

See also
PicoTestSuiteLeaveProc
PICOTEST_SUITE_LEAVE

◆ PICOTEST_SUITE_LEAVE

#define PICOTEST_SUITE_LEAVE

Define the test suite leave hook.

Called after running all subtests.

The default hook does nothing. Redefine this macro to use a custom hook, which must follow the PicoTestSuiteLeaveProc signature.

Note
Custom functions only apply to the tests defined after the macro redefinition. As macros can be redefined several times, this means that different functions may apply for the same source.
Usage
/* Hook declarations. */
PicoTestSuiteLeaveProc leaveTestSuite;
#undef PICOTEST_SUITE_LEAVE
#define PICOTEST_SUITE_LEAVE leaveTestSuite
/* Hook function. */
void leaveTestSuite(const char *suiteName, int nb, int fail) {
indent(--level);
printf("test suite %s done (%d failures)\n", suiteName, fail);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PicoTestSuiteLeaveProc
PICOTEST_SUITE_LEAVE_DEFAULT
PICOTEST_SUITE_ENTER

◆ PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT

#define PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT ( suiteName,
nb,
fail,
index,
testName )

Default test suite before subtest hook.

Does nothing.

See also
PicoTestSuiteBeforeSubtestProc
PICOTEST_SUITE_BEFORE_SUBTEST

◆ PICOTEST_SUITE_BEFORE_SUBTEST

#define PICOTEST_SUITE_BEFORE_SUBTEST

Define the test suite before subset hook.

The default hook does nothing. Redefine this macro to use a custom hook, which must follow the PicoTestSuiteBeforeSubtestProc signature.

Note
Custom functions only apply to the tests defined after the macro redefinition. As macros can be redefined several times, this means that different functions may apply for the same source.
Usage
/* Hook declarations. */
#undef PICOTEST_SUITE_BEFORE_SUBTEST
#define PICOTEST_SUITE_BEFORE_SUBTEST beforeSubtest
/* Hook function. */
void beforeSubtest(const char *suiteName, int nb, int fail, int index,
const char *testName) {
indent(level++);
printf("subtest %s (%d out of %d)...\n", testName, index+1, nb);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PicoTestSuiteBeforeSubtestProc
PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT
PICOTEST_SUITE_AFTER_SUBTEST

◆ PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT

#define PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT ( suiteName,
nb,
fail,
index,
testName,
sfail )

Default test suite after subtest hook.

Does nothing.

See also
PicoTestSuiteAfterSubtestProc
PICOTEST_SUITE_AFTER_SUBTEST

◆ PICOTEST_SUITE_AFTER_SUBTEST

#define PICOTEST_SUITE_AFTER_SUBTEST

Define the test suite after subset hook.

The default hook does nothing. Redefine this macro to use a custom hook, which must follow the PicoTestSuiteAfterSubtestProc signature.

Note
Custom functions only apply to the tests defined after the macro redefinition. As macros can be redefined several times, this means that different functions may apply for the same source.
Usage
/* Hook declarations. */
#undef PICOTEST_SUITE_AFTER_SUBTEST
#define PICOTEST_SUITE_AFTER_SUBTEST afterSubtest
/* Hook function. */
void afterSubtest(const char *suiteName, int nb, int fail, int index,
const char *testName, int sfail) {
indent(--level);
printf("=> subtest %s done (%d failed)...\n", testName, sfail);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PicoTestSuiteAfterSubtestProc
PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT
PICOTEST_SUITE_BEFORE_SUBTEST

Typedef Documentation

◆ PicoTestSuiteEnterProc

typedef void PicoTestSuiteEnterProc(const char *suiteName, int nb)

Function signature of test suite enter hooks.

Called before running the first subtest.

Parameters
suiteNameTest suite name.
nbNumber of subtests.
Usage
/* Hook declarations. */
PicoTestSuiteEnterProc enterTestSuite;
#undef PICOTEST_SUITE_ENTER
#define PICOTEST_SUITE_ENTER enterTestSuite
/* Hook function. */
void enterTestSuite(const char *suiteName, int nb) {
indent(level++);
printf("running test suite %s (%d subtests)...\n", suiteName, nb);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PICOTEST_SUITE_ENTER

◆ PicoTestSuiteLeaveProc

typedef void PicoTestSuiteLeaveProc(const char *suiteName, int nb, int fail)

Function signature of test suite leave hooks.

Parameters
suiteNameTest suite name.
nbNumber of subtests.
failNumber of failed subtests (including the subtests' subtests if any).
Usage
/* Hook declarations. */
PicoTestSuiteLeaveProc leaveTestSuite;
#undef PICOTEST_SUITE_LEAVE
#define PICOTEST_SUITE_LEAVE leaveTestSuite
/* Hook function. */
void leaveTestSuite(const char *suiteName, int nb, int fail) {
indent(--level);
printf("test suite %s done (%d failures)\n", suiteName, fail);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PICOTEST_SUITE_LEAVE

◆ PicoTestSuiteBeforeSubtestProc

typedef void PicoTestSuiteBeforeSubtestProc(const char *suiteName, int nb, int fail, int index, const char *testName)

Function signature of test suite before subtest hooks.

Called before running each subtest.

Parameters
suiteNameTest suite name.
nbNumber of subtests.
failFailed test suite subtests so far (including its subtests' subtests if any).
indexIndex of subtest.
testNameName of subtest.
Usage
/* Hook declarations. */
#undef PICOTEST_SUITE_BEFORE_SUBTEST
#define PICOTEST_SUITE_BEFORE_SUBTEST beforeSubtest
/* Hook function. */
void beforeSubtest(const char *suiteName, int nb, int fail, int index,
const char *testName) {
indent(level++);
printf("subtest %s (%d out of %d)...\n", testName, index+1, nb);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PICOTEST_SUITE_BEFORE_SUBTEST

◆ PicoTestSuiteAfterSubtestProc

typedef void PicoTestSuiteAfterSubtestProc(const char *suiteName, int nb, int fail, int index, const char *testName, int sfail)

Function signature of test suite after subtest hooks.

Called before running each subtest.

Parameters
suiteNameTest suite name.
nbNumber of subtests.
failFailed test suite subtests so far (including its subtests' subtests if any).
indexIndex of subtest.
testNameName of subtest.
sfailThe subtest's failed tests (including its subtests if any).
Usage
/* Hook declarations. */
#undef PICOTEST_SUITE_AFTER_SUBTEST
#define PICOTEST_SUITE_AFTER_SUBTEST afterSubtest
/* Hook function. */
void afterSubtest(const char *suiteName, int nb, int fail, int index,
const char *testName, int sfail) {
indent(--level);
printf("=> subtest %s done (%d failed)...\n", testName, sfail);
}
Examples
hooks.c Example of PicoTest hooks, prints all events to stdout.
See also
PICOTEST_SUITE_AFTER_SUBTEST