]> git.ipfire.org Git - thirdparty/git.git/blob - t/unit-tests/t-basic.c
Merge branch 'jc/unleak-core-excludesfile'
[thirdparty/git.git] / t / unit-tests / t-basic.c
1 #include "test-lib.h"
2
3 /*
4 * The purpose of this "unit test" is to verify a few invariants of the unit
5 * test framework itself, as well as to provide examples of output from actually
6 * failing tests. As such, it is intended that this test fails, and thus it
7 * should not be run as part of `make unit-tests`. Instead, we verify it behaves
8 * as expected in the integration test t0080-unit-test-output.sh
9 */
10
11 /* Used to store the return value of check_int(). */
12 static int check_res;
13
14 /* Used to store the return value of TEST(). */
15 static int test_res;
16
17 static void t_res(int expect)
18 {
19 check_int(check_res, ==, expect);
20 check_int(test_res, ==, expect);
21 }
22
23 static void t_todo(int x)
24 {
25 check_res = TEST_TODO(check(x));
26 }
27
28 static void t_skip(void)
29 {
30 check(0);
31 test_skip("missing prerequisite");
32 check(1);
33 }
34
35 static int do_skip(void)
36 {
37 test_skip("missing prerequisite");
38 return 1;
39 }
40
41 static void t_skip_todo(void)
42 {
43 check_res = TEST_TODO(do_skip());
44 }
45
46 static void t_todo_after_fail(void)
47 {
48 check(0);
49 TEST_TODO(check(0));
50 }
51
52 static void t_fail_after_todo(void)
53 {
54 check(1);
55 TEST_TODO(check(0));
56 check(0);
57 }
58
59 static void t_messages(void)
60 {
61 check_str("\thello\\", "there\"\n");
62 check_str("NULL", NULL);
63 check_char('a', ==, '\n');
64 check_char('\\', ==, '\'');
65 }
66
67 static void t_empty(void)
68 {
69 ; /* empty */
70 }
71
72 int cmd_main(int argc, const char **argv)
73 {
74 test_res = TEST(check_res = check_int(1, ==, 1), "passing test");
75 TEST(t_res(1), "passing test and assertion return 1");
76 test_res = TEST(check_res = check_int(1, ==, 2), "failing test");
77 TEST(t_res(0), "failing test and assertion return 0");
78 test_res = TEST(t_todo(0), "passing TEST_TODO()");
79 TEST(t_res(1), "passing TEST_TODO() returns 1");
80 test_res = TEST(t_todo(1), "failing TEST_TODO()");
81 TEST(t_res(0), "failing TEST_TODO() returns 0");
82 test_res = TEST(t_skip(), "test_skip()");
83 TEST(check_int(test_res, ==, 1), "skipped test returns 1");
84 test_res = TEST(t_skip_todo(), "test_skip() inside TEST_TODO()");
85 TEST(t_res(1), "test_skip() inside TEST_TODO() returns 1");
86 test_res = TEST(t_todo_after_fail(), "TEST_TODO() after failing check");
87 TEST(check_int(test_res, ==, 0), "TEST_TODO() after failing check returns 0");
88 test_res = TEST(t_fail_after_todo(), "failing check after TEST_TODO()");
89 TEST(check_int(test_res, ==, 0), "failing check after TEST_TODO() returns 0");
90 TEST(t_messages(), "messages from failing string and char comparison");
91 test_res = TEST(t_empty(), "test with no checks");
92 TEST(check_int(test_res, ==, 0), "test with no checks returns 0");
93
94 return test_done();
95 }