[PATCH 5/5] test-lib: add support for GIT_TODO_TESTS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As noted in the updated t/README documentation being added here
setting this new GIT_TODO_TESTS variable is usually better than
GIT_SKIP_TESTS.

My use-case for this is to get feedback from the CI infrastructure[1]
about which tests are passing due to fixes that have trickled into
git.git.

With the GIT_SKIP_TESTS variable this use-case is painful, you need to
do an occasional manual run without GIT_SKIP_TESTS set. It's much
better to use GIT_TODO_TESTS and get a report of passing TODO tests
from prove(1) at the bottom of the test output. Once those passing
TODO tests have trickled down to 'master' the relevant glob (set for
all of master/next/pu) can be removed.

As seen in the "GIT_TODO_TESTS mixed failure" test the lack of
interaction with existing tests marked as TODO by the test suite
itself is intentional. There's no need to print out something saying
they matched GIT_TODO_TESTS if they're already TODO tests.

1. https://public-inbox.org/git/875zwm15k2.fsf@xxxxxxxxxxxxxxxxxxx/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
---
 ci/lib-travisci.sh |  2 +-
 t/README           | 18 +++++++++--
 t/t0000-basic.sh   | 81 +++++++++++++++++++++++++++++++++++++++-------
 t/test-lib.sh      | 31 +++++++++++++++---
 4 files changed, 112 insertions(+), 20 deletions(-)

diff --git a/ci/lib-travisci.sh b/ci/lib-travisci.sh
index 69dff4d1ec..ad8290bfdb 100755
--- a/ci/lib-travisci.sh
+++ b/ci/lib-travisci.sh
@@ -121,7 +121,7 @@ osx-clang|osx-gcc)
 	# t9810 occasionally fails on Travis CI OS X
 	# t9816 occasionally fails with "TAP out of sequence errors" on
 	# Travis CI OS X
-	export GIT_SKIP_TESTS="t9810 t9816"
+	export GIT_TODO_TESTS="t9810 t9816"
 	;;
 GIT_TEST_GETTEXT_POISON)
 	export GIT_TEST_GETTEXT_POISON=YesPlease
diff --git a/t/README b/t/README
index c03b268813..922b4fb3bf 100644
--- a/t/README
+++ b/t/README
@@ -207,8 +207,19 @@ ideally be reported as bugs and fixed, or guarded by a prerequisite
 (see "Using test prerequisites" below). But until then they can be
 skipped.
 
-To skip tests, set the GIT_SKIP_TESTS variable. Individual tests can
-be skipped:
+To skip tests, set either the GIT_SKIP_TESTS or GIT_TODO_TESTS
+variables. The difference is that with SKIP the tests won't be run at
+all, whereas they will be run with TODO, but in success or failure
+annotated as a TODO test.
+
+It's usually preferrable to use TODO, since the test suite will report
+those tests that unexpectedly succeed, which may indicate that
+whatever bug broke the test in the past has been fixed, and the test
+should be un-TODO'd. There's no such feedback loop with
+GIT_SKIP_TESTS.
+
+The GIT_SKIP_TESTS and GIT_TODO_TESTS take the same values. Individual
+tests can be skipped:
 
     $ GIT_SKIP_TESTS=t9200.8 sh ./t9200-git-cvsexport-commit.sh
 
@@ -223,7 +234,8 @@ patterns that tells which tests to skip, and either can match the
 
 For an individual test suite --run could be used to specify that
 only some tests should be run or that some tests should be
-excluded from a run.
+excluded from a run. The --run option is a shorthand for setting
+a GIT_SKIP_TESTS pattern.
 
 The argument for --run is a list of individual test numbers or
 ranges with an optional negation prefix that define what tests in
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index b87a8f18c2..34c9c5c2a3 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -324,9 +324,10 @@ test_expect_success 'test --verbose-only' '
 	EOF
 '
 
-test_expect_success 'GIT_SKIP_TESTS' "
+test_expect_success 'GIT_{SKIP,TODO}_TESTS' "
 	(
 		GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS &&
+		GIT_TODO_TESTS='git.3' && export GIT_TODO_TESTS &&
 		run_sub_test_lib_test git-skip-tests-basic \
 			'GIT_SKIP_TESTS' <<-\\EOF &&
 		for i in 1 2 3
@@ -338,16 +339,17 @@ test_expect_success 'GIT_SKIP_TESTS' "
 		check_sub_test_lib_test git-skip-tests-basic <<-\\EOF
 		> ok 1 - passing test #1
 		> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
-		> ok 3 - passing test #3
-		> # passed all 3 test(s)
+		> ok 3 - passing test #3 # TODO (GIT_TODO_TESTS)
+		> # passed all 3 test(s) (including 1/0 ok/failing TODO test(s))
 		> 1..3
 		EOF
 	)
 "
 
-test_expect_success 'GIT_SKIP_TESTS several tests' "
+test_expect_success 'GIT_{SKIP,TODO}_TESTS several tests' "
 	(
 		GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS &&
+		GIT_TODO_TESTS='git.3 git.6' && export GIT_TODO_TESTS &&
 		run_sub_test_lib_test git-skip-tests-several \
 			'GIT_SKIP_TESTS several tests' <<-\\EOF &&
 		for i in 1 2 3 4 5 6
@@ -359,22 +361,25 @@ test_expect_success 'GIT_SKIP_TESTS several tests' "
 		check_sub_test_lib_test git-skip-tests-several <<-\\EOF
 		> ok 1 - passing test #1
 		> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
-		> ok 3 - passing test #3
+		> ok 3 - passing test #3 # TODO (GIT_TODO_TESTS)
 		> ok 4 - passing test #4
 		> ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
-		> ok 6 - passing test #6
-		> # passed all 6 test(s)
+		> ok 6 - passing test #6 # TODO (GIT_TODO_TESTS)
+		> # passed all 6 test(s) (including 2/0 ok/failing TODO test(s))
 		> 1..6
 		EOF
 	)
 "
 
-test_expect_success 'GIT_SKIP_TESTS sh pattern' "
+test_expect_success 'GIT_{SKIP,TODO}_TESTS sh pattern' "
 	(
 		GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS &&
+		# Overlap between SKIP and TODO. No attempt is made to
+		# be smart about it.
+		GIT_TODO_TESTS='git.[4-8]' && export GIT_TODO_TESTS &&
 		run_sub_test_lib_test git-skip-tests-sh-pattern \
 			'GIT_SKIP_TESTS sh pattern' <<-\\EOF &&
-		for i in 1 2 3 4 5 6
+		for i in 1 2 3 4 5 6 7 8 9
 		do
 			test_expect_success \"passing test #\$i\" 'true'
 		done
@@ -386,9 +391,12 @@ test_expect_success 'GIT_SKIP_TESTS sh pattern' "
 		> ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
 		> ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
 		> ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
-		> ok 6 - passing test #6
-		> # passed all 6 test(s)
-		> 1..6
+		> ok 6 - passing test #6 # TODO (GIT_TODO_TESTS)
+		> ok 7 - passing test #7 # TODO (GIT_TODO_TESTS)
+		> ok 8 - passing test #8 # TODO (GIT_TODO_TESTS)
+		> ok 9 - passing test #9
+		> # passed all 9 test(s) (including 3/0 ok/failing TODO test(s))
+		> 1..9
 		EOF
 	)
 "
@@ -410,6 +418,55 @@ test_expect_success 'GIT_SKIP_TESTS entire file' "
 	)
 "
 
+test_expect_success 'GIT_TODO_TESTS entire file' "
+	(
+		GIT_TODO_TESTS='git' && export GIT_TODO_TESTS &&
+		run_sub_test_lib_test git-todo-tests-entire-file \
+			'GIT_TODO_TESTS' <<-\\EOF &&
+		for i in 1 2 3
+		do
+			test_expect_success \"failing test #\$i\" 'fail'
+		done
+		test_done
+		EOF
+		check_sub_test_lib_test git-todo-tests-entire-file <<-\\EOF
+		not ok 1 - failing test #1 # TODO (GIT_TODO_TESTS)
+		#	fail
+		not ok 2 - failing test #2 # TODO (GIT_TODO_TESTS)
+		#	fail
+		not ok 3 - failing test #3 # TODO (GIT_TODO_TESTS)
+		#	fail
+		# passed all 3 test(s) (including 0/3 ok/failing TODO test(s))
+		1..3
+		EOF
+	)
+"
+
+test_expect_success 'GIT_TODO_TESTS mixed failure' "
+	(
+		GIT_TODO_TESTS='git' && export GIT_TODO_TESTS &&
+		run_sub_test_lib_test git-todo-tests-mixed \
+			'GIT_TODO_TESTS' <<-\\EOF &&
+		test_expect_success \"success\" 'true'
+		test_expect_success \"success\" 'false'
+		test_expect_failure \"success\" 'true'
+		test_expect_failure \"success\" 'false'
+		test_done
+		EOF
+		check_sub_test_lib_test git-todo-tests-mixed <<-\\EOF
+		ok 1 - success # TODO (GIT_TODO_TESTS)
+		not ok 2 - success # TODO (GIT_TODO_TESTS)
+		#	false
+		ok 3 - success # TODO known breakage vanished
+		not ok 4 - success # TODO known breakage
+		# 1 known breakage(s) vanished; please update test(s)
+		# still have 1 known breakage(s)
+		# passed all remaining 2 test(s) (including 1/1 ok/failing TODO test(s))
+		1..4
+		EOF
+	)
+"
+
 test_expect_success '--run basic' "
 	run_sub_test_lib_test run-basic \
 		'--run basic' --run='1 3 5' <<-\\EOF &&
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 6c6c0af7a1..ccd316e7bd 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -456,6 +456,8 @@ test_count=0
 test_fixed=0
 test_broken=0
 test_success=0
+test_todo_success=0
+test_todo_failure=0
 
 test_external_has_tap=0
 
@@ -482,13 +484,29 @@ trap 'exit $?' INT
 # the test_expect_* functions instead.
 
 test_ok_ () {
+	todo_blurb=
+	if match_pattern_list $this_test.$test_count $GIT_TODO_TESTS ||
+		    match_pattern_list $this_test $GIT_TODO_TESTS
+	then
+		todo_blurb=' # TODO (GIT_TODO_TESTS)'
+		test_todo_success=$(($test_todo_success + 1))
+	fi
 	test_success=$(($test_success + 1))
-	say_color "" "ok $test_count - $@"
+	say_color "" "ok $test_count - $@$todo_blurb"
 }
 
 test_failure_ () {
-	test_failure=$(($test_failure + 1))
-	say_color error "not ok $test_count - $1"
+	todo_blurb=
+	if match_pattern_list $this_test.$test_count $GIT_TODO_TESTS ||
+		    match_pattern_list $this_test $GIT_TODO_TESTS
+	then
+		test_success=$(($test_success + 1))
+		test_todo_failure=$(($test_todo_failure + 1))
+		todo_blurb=' # TODO (GIT_TODO_TESTS)'
+	else
+		test_failure=$(($test_failure + 1))
+	fi
+	say_color error "not ok $test_count - $1$todo_blurb"
 	shift
 	printf '%s\n' "$*" | sed -e 's/^/#	/'
 	test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
@@ -845,13 +863,18 @@ test_done () {
 		test_remaining=$test_count
 		msg="$test_count test(s)"
 	fi
+	msg_todo=
+	if test "$test_todo_success" != 0 || test "$test_todo_failure" != 0
+	then
+		msg_todo=" (including $test_todo_success/$test_todo_failure ok/failing TODO test(s))"
+	fi
 	case "$test_failure" in
 	0)
 		if test $test_external_has_tap -eq 0
 		then
 			if test $test_remaining -gt 0
 			then
-				say_color pass "# passed all $msg"
+				say_color pass "# passed all $msg$msg_todo"
 			fi
 
 			# Maybe print SKIP message
-- 
2.20.0.rc1.379.g1dd7ef354c




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux