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
11 /* Used to store the return value of check_int(). */
14 /* Used to store the return value of TEST(). */
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)
31 test_skip("missing prerequisite");
35 static int do_skip(void)
37 test_skip("missing prerequisite");
41 static void t_skip_todo(void)
43 check_res
= TEST_TODO(do_skip());
46 static void t_todo_after_fail(void)
52 static void t_fail_after_todo(void)
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)
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");