Merge branch 'ps/reftable-write-optim'
[alt-git.git] / t / unit-tests / t-basic.c
blobfda1ae59a63f2f60f427da634af53ce495319eb0
1 #include "test-lib.h"
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 */
11 /* Used to store the return value of check_int(). */
12 static int check_res;
14 /* Used to store the return value of TEST(). */
15 static int test_res;
17 static void t_res(int expect)
19 check_int(check_res, ==, expect);
20 check_int(test_res, ==, expect);
23 static void t_todo(int x)
25 check_res = TEST_TODO(check(x));
28 static void t_skip(void)
30 check(0);
31 test_skip("missing prerequisite");
32 check(1);
35 static int do_skip(void)
37 test_skip("missing prerequisite");
38 return 1;
41 static void t_skip_todo(void)
43 check_res = TEST_TODO(do_skip());
46 static void t_todo_after_fail(void)
48 check(0);
49 TEST_TODO(check(0));
52 static void t_fail_after_todo(void)
54 check(1);
55 TEST_TODO(check(0));
56 check(0);
59 static void t_messages(void)
61 check_str("\thello\\", "there\"\n");
62 check_str("NULL", NULL);
63 check_char('a', ==, '\n');
64 check_char('\\', ==, '\'');
67 static void t_empty(void)
69 ; /* empty */
72 int cmd_main(int argc, const char **argv)
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");
94 return test_done();