summaryrefslogtreecommitdiff
path: root/main.c
blob: e37601673398e151d81fa53b71e0679e49f3b1bc (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <string.h>
#include <stdio.h>
#include "test.h"

void test_assert_h(void);
void test_complex_h(void);
void test_ctype_h(void);
void test_errno_h(void);
void test_fenv_h(void);
void test_float_h(void);
void test_inttypes_h(void);
void test_iso646_h(void);
void test_limits_h(void);
void test_locale_h(void);
void test_math_h(void);
void test_setjmp_h(void);
void test_signal_h(void);
void test_stdalign_h(void);
void test_stdarg_h(void);
void test_stdatomic_h(void);
void test_stdbool_h(void);
void test_stddef_h(void);
void test_stdint_h(void);
void test_stdio_h(void);
void test_stdlib_h(void);
void test_stdnoreturn_h(void);
void test_string_h(void);
void test_tgmath_h(void);
void test_threads_h(void);
void test_time_h(void);
void test_uchar_h(void);
void test_wchar_h(void);
void test_wctype_h(void);

static struct {
	char *name;
	void (*fn)(void);
	int run;
} tests[] = {
	{ "assert",	test_assert_h,		0 },
	{ "complex",	test_complex_h,		1 },
	{ "ctype",	test_ctype_h,		1 },
	{ "errno",	test_errno_h,		1 },
	{ "fenv",	test_fenv_h,		1 },
	{ "float",	test_float_h,		1 },
	{ "inttypes",	test_inttypes_h,	1 },
	{ "iso646",	test_iso646_h,		1 },
	{ "limits",	test_limits_h,		1 },
	{ "locale",	test_locale_h,		1 },
	{ "math",	test_math_h,		1 },
	{ "setjmp",	test_setjmp_h,		1 },
	{ "signal",	test_signal_h,		1 },
	{ "stdalign",	test_stdalign_h,	1 },
	{ "stdarg",	test_stdarg_h,		1 },
	{ "stdatomic",	test_stdatomic_h,	1 },
	{ "stdbool",	test_stdbool_h,		1 },
	{ "stddef",	test_stddef_h,		1 },
	{ "stdint",	test_stdint_h,		1 },
	{ "stdio",	test_stdio_h,		1 },
	{ "stdlib",	test_stdlib_h,		1 },
	{ "stdnoreturn",test_stdnoreturn_h,	1 },
	{ "string",	test_string_h,		1 },
	{ "tgmath",	test_tgmath_h,		1 },
	{ "threads",	test_threads_h,		1 },
	{ "time",	test_time_h,		1 },
	{ "uchar",	test_uchar_h,		1 },
	{ "wchar",	test_wchar_h,		1 },
	{ "wctype",	test_wctype_h,		1 },
};

void show_tests(void)
{
	size_t i;
	printf("Valid tests: %s", tests[0].name);
	for (i = 1; i < sizeof(tests) / sizeof(tests[0]); i++) {
		printf(", %s", tests[i].name);
	}
	printf("\n");
}

void usage(const char *argv0)
{
	printf("Usage: %s [-v] [test...]\n", argv0);
	show_tests();
}

int main(int argc, char *argv[])
{
	int torun = 1;
	int a;
	size_t i, j;

	for (a = 1; a < argc; a++) {
		int ok = 0;

		if (!strcmp("-v", argv[a])) {
			verbose = 1;
			ok = 1;
		}

		for (j = 0; j < sizeof(tests) / sizeof(tests[0]); j++) {
			if (!strcmp(tests[j].name, argv[a])) {
				torun = 2;
				tests[j].run = 2;
				ok = 1;
			}
		}

		if (!ok) {
			usage(argv[0]);
			return 1;
		}
	}

	if (argc == 2) {
		if (!strcmp(argv[1], "assert")) {
			test_assert_h();
		}
	}

	for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
		if (tests[i].run == torun) {
			tests[i].fn();
		}
	}

	printf("Total: %u passed, %u failed\n", total_passed, total_failed);
	return 0;
}