]> git.scripts.mit.edu Git - git.git/commitdiff
t0080: turn t-basic unit test into a helper
authorJosh Steadmon <steadmon@google.com>
Mon, 6 May 2024 19:57:31 +0000 (12:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 May 2024 21:06:34 +0000 (14:06 -0700)
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>
Makefile
t/Makefile
t/helper/test-example-tap.c [moved from t/unit-tests/t-basic.c with 95% similarity]
t/helper/test-tool.c
t/helper/test-tool.h
t/t0080-unit-test-output.sh

index b5ae34ea7b626caff904c865186c28abc4e399a1..c69c060cfa7dfa9c9cff1da80d77769ee59d455d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -806,6 +806,7 @@ TEST_BUILTINS_OBJS += test-dump-split-index.o
 TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
 TEST_BUILTINS_OBJS += test-env-helper.o
 TEST_BUILTINS_OBJS += test-example-decorate.o
+TEST_BUILTINS_OBJS += test-example-tap.o
 TEST_BUILTINS_OBJS += test-find-pack.o
 TEST_BUILTINS_OBJS += test-fsmonitor-client.o
 TEST_BUILTINS_OBJS += test-genrandom.o
@@ -1342,7 +1343,6 @@ THIRD_PARTY_SOURCES += compat/regex/%
 THIRD_PARTY_SOURCES += sha1collisiondetection/%
 THIRD_PARTY_SOURCES += sha1dc/%
 
-UNIT_TEST_PROGRAMS += t-basic
 UNIT_TEST_PROGRAMS += t-mem-pool
 UNIT_TEST_PROGRAMS += t-strbuf
 UNIT_TEST_PROGRAMS += t-ctype
@@ -3222,7 +3222,7 @@ perf: all
 
 .PRECIOUS: $(TEST_OBJS)
 
-t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
+t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS)) $(UNIT_TEST_DIR)/test-lib.o
 
 t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
index 2d95046f26ec6ebad9d8707e8c002aadc665a282..4861edafe61646370ff577cffa9a3a152d2f22b9 100644 (file)
@@ -48,7 +48,7 @@ CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.tes
 CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
 UNIT_TEST_SOURCES = $(wildcard unit-tests/t-*.c)
 UNIT_TEST_PROGRAMS = $(patsubst unit-tests/%.c,unit-tests/bin/%$(X),$(UNIT_TEST_SOURCES))
-UNIT_TESTS = $(sort $(filter-out unit-tests/bin/t-basic%,$(UNIT_TEST_PROGRAMS)))
+UNIT_TESTS = $(sort $(UNIT_TEST_PROGRAMS))
 
 # `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
 # checks all tests in all scripts via a single invocation, so tell individual
similarity index 95%
rename from t/unit-tests/t-basic.c
rename to t/helper/test-example-tap.c
index fda1ae59a63f2f60f427da634af53ce495319eb0..d072ad559f64f71823f25462832eb7bc53864828 100644 (file)
@@ -1,4 +1,5 @@
-#include "test-lib.h"
+#include "test-tool.h"
+#include "t/unit-tests/test-lib.h"
 
 /*
  * The purpose of this "unit test" is to verify a few invariants of the unit
@@ -69,7 +70,7 @@ static void t_empty(void)
        ; /* empty */
 }
 
-int cmd_main(int argc, const char **argv)
+int cmd__example_tap(int argc, const char **argv)
 {
        test_res = TEST(check_res = check_int(1, ==, 1), "passing test");
        TEST(t_res(1), "passing test and assertion return 1");
index 33b9501c2112a758c1f662890d31fcbce93b854f..bb5c04c9c0bdeb78973b01efd22c315aef14b9ae 100644 (file)
@@ -29,6 +29,7 @@ static struct test_cmd cmds[] = {
        { "dump-untracked-cache", cmd__dump_untracked_cache },
        { "env-helper", cmd__env_helper },
        { "example-decorate", cmd__example_decorate },
+       { "example-tap", cmd__example_tap },
        { "find-pack", cmd__find_pack },
        { "fsmonitor-client", cmd__fsmonitor_client },
        { "genrandom", cmd__genrandom },
index b72f07ded9946b207b0c20da9886d7842cc5ac5c..38001bd1c6f8a52fe352ba95ed7d285e700f7f2c 100644 (file)
@@ -23,6 +23,7 @@ int cmd__dump_untracked_cache(int argc, const char **argv);
 int cmd__dump_reftable(int argc, const char **argv);
 int cmd__env_helper(int argc, const char **argv);
 int cmd__example_decorate(int argc, const char **argv);
+int cmd__example_tap(int argc, const char **argv);
 int cmd__find_pack(int argc, const char **argv);
 int cmd__fsmonitor_client(int argc, const char **argv);
 int cmd__genrandom(int argc, const char **argv);
index 961b54b06cf875f222ff6281a65e84b895c159cb..83b1e3b7f53eb62a04b7869eb2e048c6fff2aa7c 100755 (executable)
@@ -8,50 +8,50 @@ test_expect_success 'TAP output from unit tests' '
        cat >expect <<-EOF &&
        ok 1 - passing test
        ok 2 - passing test and assertion return 1
-       # check "1 == 2" failed at t/unit-tests/t-basic.c:76
+       # check "1 == 2" failed at t/helper/test-example-tap.c:77
        #    left: 1
        #   right: 2
        not ok 3 - failing test
        ok 4 - failing test and assertion return 0
        not ok 5 - passing TEST_TODO() # TODO
        ok 6 - passing TEST_TODO() returns 1
-       # todo check ${SQ}check(x)${SQ} succeeded at t/unit-tests/t-basic.c:25
+       # todo check ${SQ}check(x)${SQ} succeeded at t/helper/test-example-tap.c:26
        not ok 7 - failing TEST_TODO()
        ok 8 - failing TEST_TODO() returns 0
-       # check "0" failed at t/unit-tests/t-basic.c:30
+       # check "0" failed at t/helper/test-example-tap.c:31
        # skipping test - missing prerequisite
-       # skipping check ${SQ}1${SQ} at t/unit-tests/t-basic.c:32
+       # skipping check ${SQ}1${SQ} at t/helper/test-example-tap.c:33
        ok 9 - test_skip() # SKIP
        ok 10 - skipped test returns 1
        # skipping test - missing prerequisite
        ok 11 - test_skip() inside TEST_TODO() # SKIP
        ok 12 - test_skip() inside TEST_TODO() returns 1
-       # check "0" failed at t/unit-tests/t-basic.c:48
+       # check "0" failed at t/helper/test-example-tap.c:49
        not ok 13 - TEST_TODO() after failing check
        ok 14 - TEST_TODO() after failing check returns 0
-       # check "0" failed at t/unit-tests/t-basic.c:56
+       # check "0" failed at t/helper/test-example-tap.c:57
        not ok 15 - failing check after TEST_TODO()
        ok 16 - failing check after TEST_TODO() returns 0
-       # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/unit-tests/t-basic.c:61
+       # check "!strcmp("\thello\\\\", "there\"\n")" failed at t/helper/test-example-tap.c:62
        #    left: "\011hello\\\\"
        #   right: "there\"\012"
-       # check "!strcmp("NULL", NULL)" failed at t/unit-tests/t-basic.c:62
+       # check "!strcmp("NULL", NULL)" failed at t/helper/test-example-tap.c:63
        #    left: "NULL"
        #   right: NULL
-       # check "${SQ}a${SQ} == ${SQ}\n${SQ}" failed at t/unit-tests/t-basic.c:63
+       # check "${SQ}a${SQ} == ${SQ}\n${SQ}" failed at t/helper/test-example-tap.c:64
        #    left: ${SQ}a${SQ}
        #   right: ${SQ}\012${SQ}
-       # check "${SQ}\\\\${SQ} == ${SQ}\\${SQ}${SQ}" failed at t/unit-tests/t-basic.c:64
+       # check "${SQ}\\\\${SQ} == ${SQ}\\${SQ}${SQ}" failed at t/helper/test-example-tap.c:65
        #    left: ${SQ}\\\\${SQ}
        #   right: ${SQ}\\${SQ}${SQ}
        not ok 17 - messages from failing string and char comparison
-       # BUG: test has no checks at t/unit-tests/t-basic.c:91
+       # BUG: test has no checks at t/helper/test-example-tap.c:92
        not ok 18 - test with no checks
        ok 19 - test with no checks returns 0
        1..19
        EOF
 
-       ! "$GIT_BUILD_DIR"/t/unit-tests/bin/t-basic >actual &&
+       ! test-tool example-tap >actual &&
        test_cmp expect actual
 '