-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkrunner.h
54 lines (43 loc) · 1.44 KB
/
checkrunner.h
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
#ifndef _CHECKRUNNER_H
#define _CHECKRUNNER_H
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#include <check.h>
#pragma clang diagnostic pop
#define ASSERT_PTR_NULL(ptr) ck_assert_ptr_eq(ptr, NULL)
#define ASSERT_PTR_NOT_NULL(ptr) ck_assert_ptr_ne(ptr, NULL)
#define ASSERT_STRNCMP_EQUAL(a, b, n) ck_assert(strncmp(a, b, n) == 0)
#include <setjmp.h>
// A setjmp buffer for catching fatal errors in tests
jmp_buf check_jump;
/*
* Run a check suite. Example:
*
* Suite *foo_suite(void);
*
* conch_check_runsuite(foo_suite());
*
* Returns 1 on suite failures, 0 otherwise.
*/
int conch_check_runsuite(Suite *s) {
int number_failed;
SRunner *sr;
sr = srunner_create(s);
srunner_set_log(sr, "/dev/stdout");
srunner_run_all(sr, CK_SILENT);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}
void add_test_case(Suite *s, char *name, void (*test_case)(int)) {
TCase *tc = tcase_create(name);
tcase_add_test(tc, test_case);
suite_add_tcase(s, tc);
}
#define ADD_TEST_CASE(s, tc) add_test_case(s, #tc, tc)
#define CONCH_CHECK_MAIN(suite) \
int main(void) { \
return conch_check_runsuite(suite()); \
}
#endif /* _CHECKRUNNER_H */