summaryrefslogtreecommitdiff
path: root/test/test.cc
blob: 520286c1b763f51c06527e07cfea1ded3c373513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


static int succeeded;
static int failed;
static bool verbose;

void log_test(bool predicate, const char *file, int line, const char *message)
{
	if (predicate)
	{
		if (verbose)
		{
			printf("Test passed: %s:%d: %s\n", file, line, message);
		}
		succeeded++;
		return;
	}
	failed++;
	printf("Test failed: %s:%d: %s\n", file, line, message);
}

static void log_totals(void)
{
	printf("\n%d tests, %d passed, %d failed\n", succeeded+failed, succeeded, failed);
}

static void __attribute__((constructor)) init(void)
{
	atexit(log_totals);
}

void test_type_info(void);
void test_exceptions();
void test_guards(void);
int main(int argc, char **argv)
{
	int ch;

	while ((ch = getopt(argc, argv, "v")) != -1)
	{
		switch (ch)
		{
			case 'v':
				verbose = true;
			default: break;
		}
	}

	test_type_info();
	test_guards();
	test_exceptions();
	return 0;
}