Example of PicoTest hooks, prints all events to stdout.
#include <stdio.h>
int level = 0;
void indent(int level) {
while (level--) printf(" ");
}
#undef PICOTEST_SUITE_ENTER
#define PICOTEST_SUITE_ENTER enterTestSuite
void enterTestSuite(const char *suiteName, int nb) {
indent(level++);
printf("running test suite %s (%d subtests)...\n", suiteName, nb);
}
#undef PICOTEST_SUITE_LEAVE
#define PICOTEST_SUITE_LEAVE leaveTestSuite
void leaveTestSuite(const char *suiteName, int nb, int fail) {
indent(--level);
printf("test suite %s done (%d failures)\n", suiteName, fail);
}
#undef PICOTEST_SUITE_BEFORE_SUBTEST
#define PICOTEST_SUITE_BEFORE_SUBTEST beforeSubtest
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);
}
#undef PICOTEST_SUITE_AFTER_SUBTEST
#define PICOTEST_SUITE_AFTER_SUBTEST afterSubtest
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);
}
#undef PICOTEST_FIXTURE_BEFORE_SETUP
#define PICOTEST_FIXTURE_BEFORE_SETUP beforeSetup
void beforeSetup(const char *fixtureName, const char *testName) {
indent(level++);
printf("fixture %s setup...", fixtureName);
}
#undef PICOTEST_FIXTURE_AFTER_SETUP
#define PICOTEST_FIXTURE_AFTER_SETUP afterSetup
void afterSetup(const char *fixtureName, const char *testName) {
printf(" done\n");
--level;
}
#undef PICOTEST_FIXTURE_BEFORE_TEARDOWN
#define PICOTEST_FIXTURE_BEFORE_TEARDOWN beforeTeardown
void beforeTeardown(const char *fixtureName, const char *testName, int fail) {
indent(level++);
printf("fixture %s teardown...", fixtureName);
}
#undef PICOTEST_FIXTURE_AFTER_TEARDOWN
#define PICOTEST_FIXTURE_AFTER_TEARDOWN afterTeardown
void afterTeardown(const char *fixtureName, const char *testName, int fail) {
printf(" done\n");
--level;
}
#undef PICOTEST_CASE_ENTER
#define PICOTEST_CASE_ENTER enterTestCase
void enterTestCase(const char *testName) {
indent(level++);
printf("running test case %s...\n", testName);
}
#undef PICOTEST_CASE_LEAVE
#define PICOTEST_CASE_LEAVE leaveTestCase
void leaveTestCase(const char *testName, int fail) {
indent(--level);
printf("test case %s done (%d failures)\n", testName, fail);
}
#undef PICOTEST_ASSERT_BEFORE
#define PICOTEST_ASSERT_BEFORE beforeAssert
void beforeAssert(const char *type, const char *test) {
indent(level++);
printf("before assertion %s(%s)...\n", type, test);
}
#undef PICOTEST_ASSERT_AFTER
#define PICOTEST_ASSERT_AFTER afterAssert
void afterAssert(const char *type, const char *test, int fail) {
indent(--level);
printf("after assertion %s(%s) => %s\n", type, test, fail ? "fails" : "passes");
}
void main() {
mainSuite(NULL);
}
void PicoTestAssertBeforeProc(const char *type, const char *test)
Function signature of assert before hooks.
Definition picotest.h:905
void PicoTestAssertAfterProc(const char *type, const char *test, int fail)
Function signature of assert after hooks.
Definition picotest.h:954
void PicoTestFixtureAfterSetupProc(const char *fixtureName, const char *testName)
Function signature of test fixture after setup hooks.
Definition picotest.h:1214
void PicoTestFixtureBeforeSetupProc(const char *fixtureName, const char *testName)
Function signature of test fixture before setup hooks.
Definition picotest.h:1165
void PicoTestFixtureBeforeTeardownProc(const char *fixtureName, const char *testName, int fail)
Function signature of test fixture before teardown hooks.
Definition picotest.h:1264
void PicoTestFixtureAfterTeardownProc(const char *fixtureName, const char *testName, int fail)
Function signature of test fixture after teardown hooks.
Definition picotest.h:1315
void PicoTestCaseEnterProc(const char *testName)
Function signature of test case enter hooks.
Definition picotest.h:633
void PicoTestCaseLeaveProc(const char *testName, int fail)
Function signature of test case leave hooks.
Definition picotest.h:681
void PicoTestSuiteEnterProc(const char *suiteName, int nb)
Function signature of test suite enter hooks.
Definition picotest.h:1469
void PicoTestSuiteLeaveProc(const char *suiteName, int nb, int fail)
Function signature of test suite leave hooks.
Definition picotest.h:1517
void PicoTestSuiteBeforeSubtestProc(const char *suiteName, int nb, int fail, int index, const char *testName)
Function signature of test suite before subtest hooks.
Definition picotest.h:1571
void PicoTestSuiteAfterSubtestProc(const char *suiteName, int nb, int fail, int index, const char *testName, int sfail)
Function signature of test suite after subtest hooks.
Definition picotest.h:1628
Example of a simple PicoTest suite.
This file defines a minimalist unit testing framework for C programs.