Advanced example of PicoTest test filter, implements a primitive tagging feature for test filtering.
#include <stdio.h>
#undef PICOTEST_FILTER
#define PICOTEST_FILTER matchTag
typedef struct TestTags {
const char *tags[10];
} TestTags;
TestTags taggedTests[];
TestTags *taggedTest;
const char **tag;
int negate = (cond[0] == '!');
if (negate) cond++;
for (taggedTest = taggedTests; taggedTest->test; taggedTest++) {
if (taggedTest->test != test) continue;
for (tag = taggedTest->tags; *tag; tag++) {
if (strcmp(*tag, cond) == 0) {
}
}
break;
}
}
#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--;
}
TestTags taggedTests[] = {
{testCase1, {"tag1", "tag4", NULL}},
{testCase2, {"tag2", NULL}},
{subSuite, {"tag3", NULL}},
{testCase4, {"tag4", NULL}},
{NULL}
};
void main() {
printf("Run all tests:\n");
mainSuite(NULL);
printf("\n");
printf("Run tests tagged \"tag3\":\n");
mainSuite("tag3");
printf("\n");
printf("Run tests not tagged \"tag4\":\n");
mainSuite("!tag4");
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_PASS
Test matches the condition, run this test and all its subtests.
Definition picotest.h:181
@ 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.