Skip to content

Commit 44400f5

Browse files
steadmongitster
authored andcommitted
t0080: turn t-basic unit test into a helper
While t/unit-tests/t-basic.c uses the unit-test framework added in e137fe3 (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. This has the additional benefit that test harnesses seeking to run all unit tests can find them with a simple glob of "t/unit-tests/bin/t-*", with no exceptions needed. This will be important in a later patch where we add support for running the unit tests via a test-tool subcommand. Signed-off-by: Josh Steadmon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 483b759 commit 44400f5

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
806806
TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
807807
TEST_BUILTINS_OBJS += test-env-helper.o
808808
TEST_BUILTINS_OBJS += test-example-decorate.o
809+
TEST_BUILTINS_OBJS += test-example-tap.o
809810
TEST_BUILTINS_OBJS += test-find-pack.o
810811
TEST_BUILTINS_OBJS += test-fsmonitor-client.o
811812
TEST_BUILTINS_OBJS += test-genrandom.o
@@ -1342,7 +1343,6 @@ THIRD_PARTY_SOURCES += compat/regex/%
13421343
THIRD_PARTY_SOURCES += sha1collisiondetection/%
13431344
THIRD_PARTY_SOURCES += sha1dc/%
13441345

1345-
UNIT_TEST_PROGRAMS += t-basic
13461346
UNIT_TEST_PROGRAMS += t-mem-pool
13471347
UNIT_TEST_PROGRAMS += t-strbuf
13481348
UNIT_TEST_PROGRAMS += t-ctype
@@ -3222,7 +3222,7 @@ perf: all
32223222

32233223
.PRECIOUS: $(TEST_OBJS)
32243224

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
32263226

32273227
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
32283228
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)

t/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ TINTEROP = $(sort $(wildcard interop/i[0-9][0-9][0-9][0-9]-*.sh))
4747
CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test)))
4848
CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
4949
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)))
50+
UNIT_TESTS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
5251

5352
# `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
5453
# checks all tests in all scripts via a single invocation, so tell individual

t/unit-tests/t-basic.c renamed to t/helper/test-example-tap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include "test-lib.h"
1+
#include "t/unit-tests/test-lib.h"
2+
#include "test-tool.h"
23

34
/*
45
* The purpose of this "unit test" is to verify a few invariants of the unit
@@ -69,7 +70,7 @@ static void t_empty(void)
6970
; /* empty */
7071
}
7172

72-
int cmd_main(int argc, const char **argv)
73+
int cmd__example_tap(int argc, const char **argv)
7374
{
7475
test_res = TEST(check_res = check_int(1, ==, 1), "passing test");
7576
TEST(t_res(1), "passing test and assertion return 1");

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static struct test_cmd cmds[] = {
2929
{ "dump-untracked-cache", cmd__dump_untracked_cache },
3030
{ "env-helper", cmd__env_helper },
3131
{ "example-decorate", cmd__example_decorate },
32+
{ "example-tap", cmd__example_tap },
3233
{ "find-pack", cmd__find_pack },
3334
{ "fsmonitor-client", cmd__fsmonitor_client },
3435
{ "genrandom", cmd__genrandom },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int cmd__dump_untracked_cache(int argc, const char **argv);
2323
int cmd__dump_reftable(int argc, const char **argv);
2424
int cmd__env_helper(int argc, const char **argv);
2525
int cmd__example_decorate(int argc, const char **argv);
26+
int cmd__example_tap(int argc, const char **argv);
2627
int cmd__find_pack(int argc, const char **argv);
2728
int cmd__fsmonitor_client(int argc, const char **argv);
2829
int cmd__genrandom(int argc, const char **argv);

t/t0080-unit-test-output.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,50 @@ test_expect_success 'TAP output from unit tests' '
88
cat >expect <<-EOF &&
99
ok 1 - passing test
1010
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
1212
# left: 1
1313
# right: 2
1414
not ok 3 - failing test
1515
ok 4 - failing test and assertion return 0
1616
not ok 5 - passing TEST_TODO() # TODO
1717
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
1919
not ok 7 - failing TEST_TODO()
2020
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
2222
# 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
2424
ok 9 - test_skip() # SKIP
2525
ok 10 - skipped test returns 1
2626
# skipping test - missing prerequisite
2727
ok 11 - test_skip() inside TEST_TODO() # SKIP
2828
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
3030
not ok 13 - TEST_TODO() after failing check
3131
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
3333
not ok 15 - failing check after TEST_TODO()
3434
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
3636
# left: "\011hello\\\\"
3737
# 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
3939
# left: "NULL"
4040
# 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
4242
# left: ${SQ}a${SQ}
4343
# 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
4545
# left: ${SQ}\\\\${SQ}
4646
# right: ${SQ}\\${SQ}${SQ}
4747
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
4949
not ok 18 - test with no checks
5050
ok 19 - test with no checks returns 0
5151
1..19
5252
EOF
5353
54-
! "$GIT_BUILD_DIR"/t/unit-tests/bin/t-basic >actual &&
54+
! test-tool example-tap >actual &&
5555
test_cmp expect actual
5656
'
5757

0 commit comments

Comments
 (0)