#include <u.h>
#include <libc.h>
#include "common.h"
#include "debug.h"
#include "unittest.h"
#include "testmain.h"
#define DEBUG_TESTMAIN false
typedef AbstractTest *(*testsuitefactory)(void);
static testsuitefactory testsuite_factories[] =
{
testarray_testsuite,
testconfig_testsuite,
testfilepath_testsuite,
testfile_testsuite,
testset_testsuite,
testdictionary_testsuite
};
static TestSuite *load_testsuites(void)
{
int i;
TestSuite *result = testsuite_new("testmain");
NOISE(DEBUG_TESTMAIN, "about to populate testsuites");
for(i = 0; i < static_array_length(testsuite_factories); ++i)
{
testsuite_add(result, testsuite_factories[i]());
}
return result;
}
static void usage(void)
{
debug_print("Usage", "tests [-d debuglevel]");
exits("usage");
}
static void parse_options(int argc, char **argv)
{
ARGBEGIN
{
case 'd':
debug_set_level(atoi(EARGF(usage())));
break;
default:
usage();
}
ARGEND
}
void main(int argc, char **argv)
{
TestResult result;
TestSuite *suite;
debug_init();
debug_set_level(4);
parse_options(argc, argv);
testresult_init(&result);
suite = load_testsuites();
NOISE(DEBUG_TESTMAIN, "about to run testsuite");
abstracttest_run(suite, &result);
NOISE(DEBUG_TESTMAIN, "about to free testsuite");
abstracttest_free(suite);
testresult_report(&result);
exits(nil);
}
|