rather complex implementation of selective test running (CuTest does not have this feature).

This commit is contained in:
Enno Rehling 2015-10-14 18:34:41 +02:00
parent e6f2864327
commit ba0828afd4

View file

@ -3,10 +3,42 @@
#include <kernel/config.h> #include <kernel/config.h>
#include <CuTest.h> #include <CuTest.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <util/log.h> #include <util/log.h>
#pragma warning(disable: 4210) #pragma warning(disable: 4210)
typedef struct suite {
struct suite *next;
CuSuite *csuite;
char *name;
} suite;
static suite *suites;
static void add_suite(CuSuite *(*csuite)(void), const char *name, int argc, const char *argv[]) {
suite *s = 0;
if (argc > 1) {
int i;
for (i = 0; i != argc; ++i) {
if (strcmp(argv[i], name) == 0) {
s = malloc(sizeof(suite));
break;
}
}
}
else {
s = malloc(sizeof(suite));
}
if (s) {
s->next = suites;
s->name = _strdup(name);
s->csuite = csuite();
suites = s;
}
}
void RunTests(CuSuite * suite, const char *name) { void RunTests(CuSuite * suite, const char *name) {
CuString *output = CuStringNew(); CuString *output = CuStringNew();
@ -17,95 +49,115 @@ void RunTests(CuSuite * suite, const char *name) {
CuStringDelete(output); CuStringDelete(output);
} }
#define RUN_TESTS(suite, name) \ bool list = false;
CuSuite *get_##name##_suite(void); \
CuSuite *name = get_##name##_suite(); \
RunTests(name, #name); \
suite->failCount += name->failCount; \
suite->count += name->count; \
CuSuiteDelete(name);
int RunAllTests(void) #define ADD_SUITE(name) \
CuSuite *get_##name##_suite(void); \
if (list) printf("%s\n", #name); \
if (!list || argc>0) add_suite(get_##name##_suite, #name, argc, argv)
int RunAllTests(int argc, char *argv[])
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *summary = CuSuiteNew();
int fail_count, flags = log_flags; int flags = log_flags;
log_flags = LOG_FLUSH | LOG_CPERROR; log_flags = LOG_FLUSH | LOG_CPERROR;
game_init(); game_init();
/* self-test */ /* self-test */
RUN_TESTS(suite, tests); ADD_SUITE(tests);
RUN_TESTS(suite, callback); ADD_SUITE(callback);
RUN_TESTS(suite, seen); ADD_SUITE(seen);
RUN_TESTS(suite, json); ADD_SUITE(json);
RUN_TESTS(suite, jsonconf); ADD_SUITE(jsonconf);
RUN_TESTS(suite, direction); ADD_SUITE(direction);
RUN_TESTS(suite, skill); ADD_SUITE(skill);
RUN_TESTS(suite, keyword); ADD_SUITE(keyword);
RUN_TESTS(suite, order); ADD_SUITE(order);
RUN_TESTS(suite, race); ADD_SUITE(race);
/* util */ /* util */
RUN_TESTS(suite, config); ADD_SUITE(config);
RUN_TESTS(suite, attrib); ADD_SUITE(attrib);
RUN_TESTS(suite, base36); ADD_SUITE(base36);
RUN_TESTS(suite, bsdstring); ADD_SUITE(bsdstring);
RUN_TESTS(suite, functions); ADD_SUITE(functions);
RUN_TESTS(suite, parser); ADD_SUITE(parser);
RUN_TESTS(suite, umlaut); ADD_SUITE(umlaut);
RUN_TESTS(suite, unicode); ADD_SUITE(unicode);
RUN_TESTS(suite, strings); ADD_SUITE(strings);
RUN_TESTS(suite, rng); ADD_SUITE(rng);
/* items */ /* items */
RUN_TESTS(suite, xerewards); ADD_SUITE(xerewards);
/* kernel */ /* kernel */
RUN_TESTS(suite, alliance); ADD_SUITE(alliance);
RUN_TESTS(suite, unit); ADD_SUITE(unit);
RUN_TESTS(suite, faction); ADD_SUITE(faction);
RUN_TESTS(suite, group); ADD_SUITE(group);
RUN_TESTS(suite, build); ADD_SUITE(build);
RUN_TESTS(suite, pool); ADD_SUITE(pool);
RUN_TESTS(suite, curse); ADD_SUITE(curse);
RUN_TESTS(suite, equipment); ADD_SUITE(equipment);
RUN_TESTS(suite, item); ADD_SUITE(item);
RUN_TESTS(suite, magic); ADD_SUITE(magic);
RUN_TESTS(suite, alchemy); ADD_SUITE(alchemy);
RUN_TESTS(suite, reports); ADD_SUITE(reports);
RUN_TESTS(suite, save); ADD_SUITE(save);
RUN_TESTS(suite, ship); ADD_SUITE(ship);
RUN_TESTS(suite, spellbook); ADD_SUITE(spellbook);
RUN_TESTS(suite, building); ADD_SUITE(building);
RUN_TESTS(suite, spell); ADD_SUITE(spell);
RUN_TESTS(suite, spells); ADD_SUITE(spells);
RUN_TESTS(suite, magicresistance); ADD_SUITE(magicresistance);
RUN_TESTS(suite, ally); ADD_SUITE(ally);
RUN_TESTS(suite, messages); ADD_SUITE(messages);
/* gamecode */ /* gamecode */
RUN_TESTS(suite, prefix); ADD_SUITE(prefix);
RUN_TESTS(suite, battle); ADD_SUITE(battle);
RUN_TESTS(suite, donations); ADD_SUITE(donations);
RUN_TESTS(suite, travelthru); ADD_SUITE(travelthru);
RUN_TESTS(suite, economy); ADD_SUITE(economy);
RUN_TESTS(suite, give); ADD_SUITE(give);
RUN_TESTS(suite, laws); ADD_SUITE(laws);
RUN_TESTS(suite, market); ADD_SUITE(market);
RUN_TESTS(suite, move); ADD_SUITE(move);
RUN_TESTS(suite, piracy); ADD_SUITE(piracy);
RUN_TESTS(suite, stealth); ADD_SUITE(stealth);
RUN_TESTS(suite, upkeep); ADD_SUITE(upkeep);
RUN_TESTS(suite, vortex); ADD_SUITE(vortex);
RUN_TESTS(suite, wormhole); ADD_SUITE(wormhole);
RUN_TESTS(suite, spy); ADD_SUITE(spy);
RUN_TESTS(suite, study); ADD_SUITE(study);
printf("\ntest summary: %d tests, %d failed\n", suite->count, suite->failCount); if (suites) {
int fail_count;
while (suites) {
suite *s = suites->next;
RunTests(suites->csuite, suites->name);
summary->failCount += suites->csuite->failCount;
summary->count += suites->csuite->count;
CuSuiteDelete(suites->csuite);
free(suites->name);
free(suites);
suites = s;
}
printf("\ntest summary: %d tests, %d failed\n", summary->count, summary->failCount);
log_flags = flags; log_flags = flags;
fail_count = suite->failCount; fail_count = summary->failCount;
CuSuiteDelete(suite); CuSuiteDelete(summary);
game_done(); game_done();
return fail_count; return fail_count;
}
return 0;
} }
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
log_stderr = 0; log_stderr = 0;
return RunAllTests(); ++argv;
--argc;
if (argc > 0 && strcmp("--list", argv[0]) == 0) {
list = true;
++argv;
--argc;
}
return RunAllTests(argc, argv);
} }