-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate
47 lines (43 loc) · 1.31 KB
/
template
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
{{#use_header}}
#include "{{source}}"
#include <stdlib.h>
#include <stdio.h>
{{/use_header}}
{{#metadata_list}}
void {{name}}_test(void) {
struct {
char name[100];
struct {
{{#parameters}}
{{type}} {{name}};
{{/parameters}}
} parameters;
{{^is_void}}
{{type}} expected;
{{/is_void}}
} tests[] = {
};
size_t length = sizeof(tests) / sizeof(tests[0]);
printf("Running {{name}}_test\n");
for (size_t idx = 0; idx < length; idx++) {
printf(" %s: \t", tests[idx].name);
{{#is_void}}
// TODO: add check for side effect
{{name}}({{#parameters}}tests[idx].parameters.{{name}}{{^is_last}}, {{/is_last}}{{/parameters}});
{{/is_void}}
{{^is_void}}
{{^is_primitive}}
// TODO: use proper compare function
{{/is_primitive}}
{{type}} result = {{name}}({{#parameters}}tests[idx].parameters.{{name}}{{^is_last}}, {{/is_last}}{{/parameters}});
if (tests[idx].expected == result) {
printf("Success\n");
} else {
printf("Failed\n");
fprintf(stderr, "Failed on %s:\n\tExpecting: %s\n\tGot: %s\n",
tests[idx].name, tests[idx].expected, result);
}
{{/is_void}}
}
}
{{/metadata_list}}