Example of PicoTest test filter, allows custom filtering of test functions.
#include <stdio.h>
#undef PICOTEST_FILTER
#define PICOTEST_FILTER matchSubstring
return (strstr(testName, cond) == NULL
}
#undef PICOTEST_CASE_ENTER
#undef PICOTEST_CASE_LEAVE
#undef PICOTEST_SUITE_ENTER
#undef PICOTEST_SUITE_LEAVE
#define PICOTEST_CASE_ENTER logCaseEnter
#define PICOTEST_CASE_LEAVE logCaseLeave
#define PICOTEST_SUITE_ENTER logSuiteEnter
#define PICOTEST_SUITE_LEAVE logSuiteLeave
int level = 0;
void indent(int level) {
while (level--) printf(" ");
}
void logCaseEnter(const char *name) {
indent(level++);
printf("running test case %s\n", name);
}
void logCaseLeave(const char *name, int fail) {
level--;
}
void logSuiteEnter(const char *name, int nb) {
indent(level++);
printf("running test suite %s\n", name);
}
void logSuiteLeave(const char *name, int nb, int fail) {
level--;
}
void main() {
printf("Run all tests:\n");
mainSuite(NULL);
printf("\n");
printf("Run tests containing \"Case\":\n");
mainSuite("Case");
printf("\n");
}
int PicoTestProc(const char *cond)
Signature of test functions.
Definition picotest.h:104
PicoTestFilterResult PicoTestFilterProc(PicoTestProc *test, const char *testName, const char *cond)
Signature of test filter functions.
Definition picotest.h:215
PicoTestFilterResult
Result of test filter functions.
Definition picotest.h:175
@ PICOTEST_FILTER_SKIP_PROPAGATE
Test does not match the condition, skip this test but filter its subtests.
Definition picotest.h:185
@ PICOTEST_FILTER_PASS_PROPAGATE
Test matches the condition, run this test but filter its subtests.
Definition picotest.h:188
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
Example of a simple PicoTest suite.
This file defines a minimalist unit testing framework for C programs.