t0080: turn t-basic unit test into a helper

While t/unit-tests/t-basic.c uses the unit-test framework added in e137fe3b29 (unit tests: add TAP unit test framework, 2023-11-09), it is not a true unit test in that it intentionally fails in order to exercise various codepaths in the unit-test framework. Thus, we intentionally exclude it when running unit tests through the various t/Makefile targets. Instead, it is executed by t0080-unit-test-output.sh, which verifies its output follows the TAP format expected for the various pass, skip, or fail cases. As such, it makes more sense for t-basic to be a helper item for t0080-unit-test-output.sh, so let's move it to t/helper/test-example-tap.c and adjust Makefiles as necessary. Signed-off-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Josh Steadmon committed May 6, 2024 at 12:57 UTC 80bb227e41f462bb04f07991cb2bb531453820a5
6 files changed +20 -17
Makefile
+2 -2
@@ -806,6 +806,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
806 TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
807 TEST_BUILTINS_OBJS += test-env-helper.o
808 TEST_BUILTINS_OBJS += test-example-decorate.o
809 +TEST_BUILTINS_OBJS += test-example-tap.o
810 TEST_BUILTINS_OBJS += test-find-pack.o
811 TEST_BUILTINS_OBJS += test-fsmonitor-client.o
812 TEST_BUILTINS_OBJS += test-genrandom.o
@@ -1342,7 +1343,6 @@ THIRD_PARTY_SOURCES += compat/regex/%
1343 THIRD_PARTY_SOURCES += sha1collisiondetection/%
1344 THIRD_PARTY_SOURCES += sha1dc/%
1345
1345 -UNIT_TEST_PROGRAMS += t-basic
1346 UNIT_TEST_PROGRAMS += t-mem-pool
1347 UNIT_TEST_PROGRAMS += t-strbuf
1348 UNIT_TEST_PROGRAMS += t-ctype
@@ -3222,7 +3222,7 @@ perf: all
3222
3223 .PRECIOUS: $(TEST_OBJS)
3224
3225 -t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
3225 +t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
3226
3227 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
3228 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
t/Makefile
+1 -1
@@ -48,7 +48,7 @@ CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.tes
48 CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
49 UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c)
50 UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
51 -UNIT_TESTS = $(sort $(filter-out unit-tests/bin/t-basic%,$(UNIT_TEST_PROGRAMS)))
51 +UNIT_TESTS = $(sort $(UNIT_TEST_PROGRAMS))
52
53 # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
54 # checks all tests in all scripts via a single invocation, so tell individual
t/helper/test-example-tap.c renamed
+3 -2
@@ -1,4 +1,5 @@
1 -#include "test-lib.h"
1 +#include "test-tool.h"
2 +#include "t/unit-tests/test-lib.h"
3
4 /*
5 * The purpose of this "unit test" is to verify a few invariants of the unit
@@ -69,7 +70,7 @@ static void t_empty(void)
70 ; /* empty */
71 }
72
72 -int cmd_main(int argc, const char **argv)
73 +int cmd__example_tap(int argc, const char **argv)
74 {
75 test_res = TEST(check_res = check_int(1, ==, 1), "passing test");
76 TEST(t_res(1), "passing test and assertion return 1");
t/helper/test-tool.c
+1
@@ -29,6 +29,7 @@ static struct test_cmd cmds[] = {
29 { "dump-untracked-cache", cmd__dump_untracked_cache },
30 { "env-helper", cmd__env_helper },
31 { "example-decorate", cmd__example_decorate },
32 + { "example-tap", cmd__example_tap },
33 { "find-pack", cmd__find_pack },
34 { "fsmonitor-client", cmd__fsmonitor_client },
35 { "genrandom", cmd__genrandom },
t/helper/test-tool.h
+1
@@ -23,6 +23,7 @@ int cmd__dump_untracked_cache(int argc, const char **argv);
23 int cmd__dump_reftable(int argc, const char **argv);
24 int cmd__env_helper(int argc, const char **argv);
25 int cmd__example_decorate(int argc, const char **argv);
26 +int cmd__example_tap(int argc, const char **argv);
27 int cmd__find_pack(int argc, const char **argv);
28 int cmd__fsmonitor_client(int argc, const char **argv);
29 int cmd__genrandom(int argc, const char **argv);
t/t0080-unit-test-output.sh
+12 -12
@@ -8,50 +8,50 @@ test_expect_success 'TAP output from unit tests' '
8 cat >expect <<-EOF &&
9 ok 1 - passing test
10 ok 2 - passing test and assertion return 1
11 - # check "1 == 2" failed at t/unit-tests/t-basic.c:76
11 + # check "1 == 2" failed at t/helper/test-example-tap.c:77
12 # left: 1
13 # right: 2
14 not ok 3 - failing test
15 ok 4 - failing test and assertion return 0
16 not ok 5 - passing TEST_TODO() # TODO
17 ok 6 - passing TEST_TODO() returns 1
18 - # todo check ${SQ}check(x)${SQ} succeeded at t/unit-tests/t-basic.c:25
18 + # todo check ${SQ}check(x)${SQ} succeeded at t/helper/test-example-tap.c:26
19 not ok 7 - failing TEST_TODO()
20 ok 8 - failing TEST_TODO() returns 0
21 - # check "0" failed at t/unit-tests/t-basic.c:30
21 + # check "0" failed at t/helper/test-example-tap.c:31
22 # skipping test - missing prerequisite
23 - # skipping check ${SQ}1${SQ} at t/unit-tests/t-basic.c:32
23 + # skipping check ${SQ}1${SQ} at t/helper/test-example-tap.c:33
24 ok 9 - test_skip() # SKIP
25 ok 10 - skipped test returns 1
26 # skipping test - missing prerequisite
27 ok 11 - test_skip() inside TEST_TODO() # SKIP
28 ok 12 - test_skip() inside TEST_TODO() returns 1
29 - # check "0" failed at t/unit-tests/t-basic.c:48
29 + # check "0" failed at t/helper/test-example-tap.c:49
30 not ok 13 - TEST_TODO() after failing check
31 ok 14 - TEST_TODO() after failing check returns 0
32 - # check "0" failed at t/unit-tests/t-basic.c:56
32 + # check "0" failed at t/helper/test-example-tap.c:57
33 not ok 15 - failing check after TEST_TODO()
34 ok 16 - failing check after TEST_TODO() returns 0
35 - # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/unit-tests/t-basic.c:61
35 + # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:62
36 # left: "\011hello\\\\"
37 # right: "there\"\012"
38 - # check "!strcmp("NULL", NULL)" failed at t/unit-tests/t-basic.c:62
38 + # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:63
39 # left: "NULL"
40 # right: NULL
41 - # check "${SQ}a${SQ} == ${SQ}\n${SQ}" failed at t/unit-tests/t-basic.c:63
41 + # check "${SQ}a${SQ} == ${SQ}\n${SQ}" failed at t/helper/test-example-tap.c:64
42 # left: ${SQ}a${SQ}
43 # right: ${SQ}\012${SQ}
44 - # check "${SQ}\\\\${SQ} == ${SQ}\\${SQ}${SQ}" failed at t/unit-tests/t-basic.c:64
44 + # check "${SQ}\\\\${SQ} == ${SQ}\\${SQ}${SQ}" failed at t/helper/test-example-tap.c:65
45 # left: ${SQ}\\\\${SQ}
46 # right: ${SQ}\\${SQ}${SQ}
47 not ok 17 - messages from failing string and char comparison
48 - # BUG: test has no checks at t/unit-tests/t-basic.c:91
48 + # BUG: test has no checks at t/helper/test-example-tap.c:92
49 not ok 18 - test with no checks
50 ok 19 - test with no checks returns 0
51 1..19
52 EOF
53
54 - ! "$GIT_BUILD_DIR"/t/unit-tests/bin/t-basic >actual &&
54 + ! test-tool example-tap >actual &&
55 test_cmp expect actual
56 '
57