git-p4: fix typos
[git/gitster.git] / t / helper / test-example-tap.c
blobd072ad559f64f71823f25462832eb7bc53864828
1 #include "test-tool.h"
2 #include "t/unit-tests/test-lib.h"
4 /*
5 * The purpose of this "unit test" is to verify a few invariants of the unit
6 * test framework itself, as well as to provide examples of output from actually
7 * failing tests. As such, it is intended that this test fails, and thus it
8 * should not be run as part of `make unit-tests`. Instead, we verify it behaves
9 * as expected in the integration test t0080-unit-test-output.sh
12 /* Used to store the return value of check_int(). */
13 static int check_res;
15 /* Used to store the return value of TEST(). */
16 static int test_res;
18 static void t_res(int expect)
20 check_int(check_res, ==, expect);
21 check_int(test_res, ==, expect);
24 static void t_todo(int x)
26 check_res = TEST_TODO(check(x));
29 static void t_skip(void)
31 check(0);
32 test_skip("missing prerequisite");
33 check(1);
36 static int do_skip(void)
38 test_skip("missing prerequisite");
39 return 1;
42 static void t_skip_todo(void)
44 check_res = TEST_TODO(do_skip());
47 static void t_todo_after_fail(void)
49 check(0);
50 TEST_TODO(check(0));
53 static void t_fail_after_todo(void)
55 check(1);
56 TEST_TODO(check(0));
57 check(0);
60 static void t_messages(void)
62 check_str("\thello\\", "there\"\n");
63 check_str("NULL", NULL);
64 check_char('a', ==, '\n');
65 check_char('\\', ==, '\'');
68 static void t_empty(void)
70 ; /* empty */
73 int cmd__example_tap(int argc, const char **argv)
75 test_res = TEST(check_res = check_int(1, ==, 1), "passing test");
76 TEST(t_res(1), "passing test and assertion return 1");
77 test_res = TEST(check_res = check_int(1, ==, 2), "failing test");
78 TEST(t_res(0), "failing test and assertion return 0");
79 test_res = TEST(t_todo(0), "passing TEST_TODO()");
80 TEST(t_res(1), "passing TEST_TODO() returns 1");
81 test_res = TEST(t_todo(1), "failing TEST_TODO()");
82 TEST(t_res(0), "failing TEST_TODO() returns 0");
83 test_res = TEST(t_skip(), "test_skip()");
84 TEST(check_int(test_res, ==, 1), "skipped test returns 1");
85 test_res = TEST(t_skip_todo(), "test_skip() inside TEST_TODO()");
86 TEST(t_res(1), "test_skip() inside TEST_TODO() returns 1");
87 test_res = TEST(t_todo_after_fail(), "TEST_TODO() after failing check");
88 TEST(check_int(test_res, ==, 0), "TEST_TODO() after failing check returns 0");
89 test_res = TEST(t_fail_after_todo(), "failing check after TEST_TODO()");
90 TEST(check_int(test_res, ==, 0), "failing check after TEST_TODO() returns 0");
91 TEST(t_messages(), "messages from failing string and char comparison");
92 test_res = TEST(t_empty(), "test with no checks");
93 TEST(check_int(test_res, ==, 0), "test with no checks returns 0");
95 return test_done();