Skip to contentSkip to conversation

Make test output coloring more intuitive

PATCH Superseded Adam Spiers 5 participants 37 messages Jun 15, 2016

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make test output coloring more intuitive

1. Change the color of individual known breakages from bold green to bold yellow. This seems more appropriate when considering the universal traffic lights coloring scheme, where green conveys the impression that everything's OK, and amber that something's not quite right.

2. Likewise, change the color of the summarized total number of known breakages from bold red to bold yellow to be less alarmist and more consistent with the above.

3. Change color of unexpectedly fixed known breakages to bold red. An unexpectedly passing test indicates that the test is wrong or the semantics of the code being tested have changed. Either way this is an error which is arguably as bad as a failing test, and as such is now counted in the totals too.

The end result of these changes is that:

- red is _only_ used for things which have gone unexpectedly wrong:
test failures, unexpected test passes, and failures with the framework,

- yellow is _only_ used for known breakages, and

- green is _only_ used for things which have gone to plan and require no further work to be done.

---
 t/t0000-basic.sh |  7 ++++---
 t/test-lib.sh    | 13 ++++++++-----
 2 files changed, 12 insertions(+), 8 deletions(-)
 mode change 100644 => 100755 t/test-lib.sh
t/t0000-basic.sh +4 -3
index ae6a3f0..4e111b4 100755
@@ -81,9 +81,10 @@ test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib
 	./passing-todo.sh >out 2>err &&
 	! test -s err &&
 	sed -e 's/^> //' >expect <<-\\EOF &&
-	> ok 1 - pretend we have fixed a known breakage # TODO known breakage
-	> # fixed 1 known breakage(s)
-	> # passed all 1 test(s)
+	> ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
+	> # fixed 1 known breakage(s); please update test(s)
+	> # still have 1 known breakage(s)
+	> # passed all remaining 0 test(s)
 	> 1..1
 	EOF
 	test_cmp expect out)
t/test-lib.sh +8 -5
old mode 100644
new mode 100755
index f8e3733..9907035
@@ -183,10 +183,12 @@ then
 			tput bold; tput setaf 1;; # bold red
 		skip)
 			tput bold; tput setaf 2;; # bold green
+		warn)
+			tput bold; tput setaf 3;; # bold yellow
 		pass)
 			tput setaf 2;;            # green
 		info)
-			tput setaf 3;;            # brown
+			tput setaf 3;;            # yellow/brown
 		*)
 			test -n "$quiet" && return;;
 		esac
@@ -276,12 +278,13 @@ test_failure_ () {
 
 test_known_broken_ok_ () {
 	test_fixed=$(($test_fixed+1))
-	say_color "" "ok $test_count - $@ # TODO known breakage"
+	test_broken=$(($test_broken+1))
+	say_color error "ok $test_count - $@ # TODO known breakage vanished"
 }
 
 test_known_broken_failure_ () {
 	test_broken=$(($test_broken+1))
-	say_color skip "not ok $test_count - $@ # TODO known breakage"
+	say_color warn "not ok $test_count - $@ # TODO known breakage"
 }
 
 test_debug () {
@@ -371,11 +374,11 @@ test_done () {
 
 	if test "$test_fixed" != 0
 	then
-		say_color pass "# fixed $test_fixed known breakage(s)"
+		say_color error "# fixed $test_fixed known breakage(s); please update test(s)"
 	fi
 	if test "$test_broken" != 0
 	then
-		say_color error "# still have $test_broken known breakage(s)"
+		say_color warn "# still have $test_broken known breakage(s)"
 		msg="remaining $(($test_count-$test_broken)) test(s)"
 	else
 		msg="$test_count test(s)"
Signature · 1 line
1.7.12.147.g6d168f4
#1 lore raw
Quoted 10 lines · Adam Spiers

The end result of these changes is that:

- red is _only_ used for things which have gone unexpectedly wrong:
test failures, unexpected test passes, and failures with the framework,

- yellow is _only_ used for known breakages, and

- green is _only_ used for things which have gone to plan and require no further work to be done.

Sounds reasonable, and I think the new output looks nice. I notice that skipped tests are still in green. I wonder if they should be in yellow, too. They may or may not be a problem, but you are failing to run some portion of the test suite.

Quoted 8 lines
t/t0000-basic.sh +0 -0
index ae6a3f0..4e111b4 100755
@@ -81,9 +81,10 @@ test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib
 	./passing-todo.sh >out 2>err &&
 	! test -s err &&
 	sed -e 's/^> //' >expect <<-\\EOF &&

t/t0000-basic.sh test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib · line 90

Quoted 10 lines
t/t0000-basic.sh +4 -3
-	> ok 1 - pretend we have fixed a known breakage # TODO known breakage
-	> # fixed 1 known breakage(s)
-	> # passed all 1 test(s)
+	> ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
+	> # fixed 1 known breakage(s); please update test(s)
+	> # still have 1 known breakage(s)
+	> # passed all remaining 0 test(s)
 	> 1..1
 	EOF
 	test_cmp expect out)

This hunk is surprising after reading the commit message. It looks like you are also breaking down expect_fail tests by fixed and not fixed.

I think that is probably an OK thing to do (although it might make more sense in a separate patch), but are your numbers right? It looks from that count as if there are 2 tests expecting failure (one fixed and one still broken).

-Peff

#14 lore raw
In reply to Adam Spiers
Quoted 10 lines · Adam Spiers

1. Change the color of individual known breakages from bold green to bold yellow. This seems more appropriate when considering the universal traffic lights coloring scheme, where green conveys the impression that everything's OK, and amber that something's not quite right.

2. Likewise, change the color of the summarized total number of known breakages from bold red to bold yellow to be less alarmist and more consistent with the above.

Quoted 5 lines

3. Change color of unexpectedly fixed known breakages to bold red. An unexpectedly passing test indicates that the test is wrong or the semantics of the code being tested have changed. Either way this is an error which is arguably as bad as a failing test, and as such is now counted in the totals too.

I agree with Peff's comments.

The point #3 above wants to be a separate patch; we may even want to consider a follow-up change to add an option to make a "test that is expected to fail did not fail" case a failure.

t/test-lib.sh test_failure_ () { · line 283

Quoted 6 lines

test_known_broken_ok_ () {

t/test-lib.sh +2 -1
 	test_fixed=$(($test_fixed+1))
-	say_color "" "ok $test_count - $@ # TODO known breakage"
+	test_broken=$(($test_broken+1))
+	say_color error "ok $test_count - $@ # TODO known breakage vanished"
 }

Also I wonder if this is still a "TODO". "# TODO fixed known breakage", meaning that it is something that must be looked at by whoever happened to have fixed the known breakage by accident, might be a better wording.

#2 lore raw
In reply to Jeff King
Quoted 10 lines · Jeff King
Quoted 8 lines · Adam Spiers

The end result of these changes is that:

- red is _only_ used for things which have gone unexpectedly wrong:
test failures, unexpected test passes, and failures with the framework,

- yellow is _only_ used for known breakages, and

Quoted 7 lines
Quoted 2 lines

- green is _only_ used for things which have gone to plan and require no further work to be done.

Sounds reasonable, and I think the new output looks nice. I notice that skipped tests are still in green. I wonder if they should be in yellow, too. They may or may not be a problem, but you are failing to run some portion of the test suite.

Fair point, I'll reroll the series and change skipped tests to yellow (non-bold, to distinguish from known breakages which are bold yellow).

Quoted 13 lines
Quoted 13 lines
t/t0000-basic.sh +2 -3
index ae6a3f0..4e111b4 100755
@@ -81,9 +81,10 @@ test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib
 	./passing-todo.sh >out 2>err &&
 	! test -s err &&
 	sed -e 's/^> //' >expect <<-\\EOF &&
-	> ok 1 - pretend we have fixed a known breakage # TODO known breakage
-	> # fixed 1 known breakage(s)
-	> # passed all 1 test(s)
+	> ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
+	> # fixed 1 known breakage(s); please update test(s)
Quoted 8 lines

t/t0000-basic.sh test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib · line 90

Quoted 5 lines
t/t0000-basic.sh +2 -0
+	> # still have 1 known breakage(s)
+	> # passed all remaining 0 test(s)
 	> 1..1
 	EOF
 	test_cmp expect out)

This hunk is surprising after reading the commit message. It looks like you are also breaking down expect_fail tests by fixed and not fixed.

Correct.

Quoted 2 lines

I think that is probably an OK thing to do (although it might make more sense in a separate patch), but are your numbers right?

They are right (at least as I intended), but I agree it's a bit confusing.

Quoted 2 lines

It looks from that count as if there are 2 tests expecting failure (one fixed and one still broken).

It's actually one test which is both fixed *and* in some sense broken. The confusion arises from the ambiguity of the word "broken", which could mean either "failed as expected" or "expected to fail but didn't". Previously it was just the former, but my patch changed it to encompass both cases. The motivation behind this was to avoid the

    # passed all $count test(s)

summary message which is overly comforting when one or more tests were expected to fail but didn't. However perhaps it's cleaner to keep the counter buckets separated. I'll try to come up with a better solution.

#15 lore raw
In reply to Junio C Hamano
Quoted 18 lines · Junio C Hamano
Quoted 10 lines · Adam Spiers

1. Change the color of individual known breakages from bold green to bold yellow. This seems more appropriate when considering the universal traffic lights coloring scheme, where green conveys the impression that everything's OK, and amber that something's not quite right.

2. Likewise, change the color of the summarized total number of known breakages from bold red to bold yellow to be less alarmist and more consistent with the above.

Quoted 5 lines

3. Change color of unexpectedly fixed known breakages to bold red. An unexpectedly passing test indicates that the test is wrong or the semantics of the code being tested have changed. Either way this is an error which is arguably as bad as a failing test, and as such is now counted in the totals too.

Quoted 3 lines

I agree with Peff's comments.

The point #3 above wants to be a separate patch;

OK, re-rolling this.

Quoted 2 lines

we may even want to consider a follow-up change to add an option to make a "test that is expected to fail did not fail" case a failure.

Sounds like a nice idea.

Quoted 8 lines

t/test-lib.sh test_failure_ () { · line 283

Quoted 6 lines

test_known_broken_ok_ () {

t/test-lib.sh +2 -1
 	test_fixed=$(($test_fixed+1))
-	say_color "" "ok $test_count - $@ # TODO known breakage"
+	test_broken=$(($test_broken+1))
+	say_color error "ok $test_count - $@ # TODO known breakage vanished"
 }

Also I wonder if this is still a "TODO".

Hah, I should trust my first instincts more; my first version of the patch dropped the "TODO", but then I put it back in because I thought people would object :-)

Quoted 3 lines

"# TODO fixed known breakage", meaning that it is something that must be looked at by whoever happened to have fixed the known breakage by accident, might be a better wording.

I would challenge the assumption that the test passed because someone deliberately fixed the code it was testing. Whilst this is a probable scenario (e.g. if they forgot to adjust the test to expect success rather than failure), it's not the only one. Tests can be brittle and depend on external factors which can change unexpectedly. For example, I noticed that the final 'general options plus command' test in t9902-completion.sh is currently dependent on the contents of the current $PATH. This is because I have a shell-script called git-check-email' on mine, so check-email' becomes an extra subcommand completion possibility for the prefix `check'. Almost every other developer running this test would not encounter the same failure. It's not a huge stretch to imagine a similar corner case which could unexpectedly cause a test to pass when failure was expected.

Therefore I would suggest a wording which avoids implying that something was deliberately fixed. That was my reasoning behind introducing the word "vanished" to the output.

#16 lore raw

v2 cover make test output coloring more intuitive

This series of commits attempts to make test output coloring more intuitive, so that:

- red is _only_ used for things which have gone unexpectedly wrong:
test failures, unexpected test passes, and failures with the framework,

- yellow is _only_ used for known breakages and skipped tests, and

- green is _only_ used for things which have gone to plan and require no further work to be done.

Adam Spiers (6):
Change the color of individual known breakages Make 'not ok $count - $message' consistent with 'ok $count -
$message'
Color skipped tests the same as informational messages Refactor mechanics of testing in a sub test-lib Test the test framework more thoroughly
Treat unexpectedly fixed known breakages more seriously

 t/t0000-basic.sh | 179 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 t/test-lib.sh    |  25 +++++---
 2 files changed, 174 insertions(+), 30 deletions(-)
 mode change 100644 => 100755 t/test-lib.sh
Signature · 1 line
1.7.12.147.g6d168f4
#17 lore raw

PATCH v2 1/6 Change the color of individual known breakages

Bold yellow seems a more appropriate color than bold green when considering the universal traffic lights coloring scheme, where green conveys the impression that everything's OK, and amber that something's not quite right.

Likewise, change the color of the summarized total number of known breakages from bold red to bold yellow to be less alarmist and more consistent with the above.

---
 t/test-lib.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
t/test-lib.sh +4 -2
index f8e3733..426820e 100644
@@ -183,6 +183,8 @@ then
 			tput bold; tput setaf 1;; # bold red
 		skip)
 			tput bold; tput setaf 2;; # bold green
+		warn)
+			tput bold; tput setaf 3;; # bold yellow
 		pass)
 			tput setaf 2;;            # green
 		info)
@@ -281,7 +283,7 @@ test_known_broken_ok_ () {
 
 test_known_broken_failure_ () {
 	test_broken=$(($test_broken+1))
-	say_color skip "not ok $test_count - $@ # TODO known breakage"
+	say_color warn "not ok $test_count - $@ # TODO known breakage"
 }
 
 test_debug () {
@@ -375,7 +377,7 @@ test_done () {
 	fi
 	if test "$test_broken" != 0
 	then
-		say_color error "# still have $test_broken known breakage(s)"
+		say_color warn "# still have $test_broken known breakage(s)"
 		msg="remaining $(($test_count-$test_broken)) test(s)"
 	else
 		msg="$test_count test(s)"
Signature · 1 line
1.7.12.147.g6d168f4
#18 lore raw

PATCH v2 2/6 Make 'not ok $count - $message' consistent with 'ok $count - $message'

In reply to Adam Spiers
---
 t/t0000-basic.sh | 4 ++--
 t/test-lib.sh    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 t/test-lib.sh
t/t0000-basic.sh +2 -2
index ae6a3f0..c6b42de 100755
@@ -167,13 +167,13 @@ test_expect_success 'tests clean up even on failures' "
 	! test -s err &&
 	! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
 	sed -e 's/Z$//' -e 's/^> //' >expect <<-\\EOF &&
-	> not ok - 1 tests clean up even after a failure
+	> not ok 1 - tests clean up even after a failure
 	> #	Z
 	> #	touch clean-after-failure &&
 	> #	test_when_finished rm clean-after-failure &&
 	> #	(exit 1)
 	> #	Z
-	> not ok - 2 failure to clean up causes the test to fail
+	> not ok 2 - failure to clean up causes the test to fail
 	> #	Z
 	> #	test_when_finished \"(exit 2)\"
 	> #	Z
t/test-lib.sh +1 -1
old mode 100644
new mode 100755
index 426820e..5293830
@@ -270,7 +270,7 @@ test_ok_ () {
 
 test_failure_ () {
 	test_failure=$(($test_failure + 1))
-	say_color error "not ok - $test_count $1"
+	say_color error "not ok $test_count - $1"
 	shift
 	echo "$@" | sed -e 's/^/#	/'
 	test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
Signature · 1 line
1.7.12.147.g6d168f4
#19 lore raw

Re: [PATCH v2 2/6] Make 'not ok $count - $message' consistent with 'ok $count - $message'

t/test-lib.sh test_ok_ () { · line 273

Quoted 4 lines · Adam Spiers

test_failure_ () {

t/test-lib.sh +1 -1
 	test_failure=$(($test_failure + 1))
-	say_color error "not ok - $test_count $1"
+	say_color error "not ok $test_count - $1"

Interesting. I wondered what TAP had to say about this, and in fact we were doing it wrong before. However, since the test numbers are optional in TAP, a harness is supposed to keep its own counter when we fail to provide a number.

So it happened to work, but this change in fact makes us more TAP-compliant. Good.

-Peff

#22 lore raw

PATCH v2 3/6 Color skipped tests the same as informational messages

In reply to Adam Spiers

Skipped tests indicate incomplete test coverage. Whilst this is not a test failure or other error, it's still not complete success, so according to the universal traffic lights coloring scheme, yellow/brown seems more suitable than green. However, it's more informational than cautionary, so we leave it non-bold in order to contrast with warnings.

---
 t/test-lib.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/test-lib.sh +2 -2
index 5293830..7028ba8 100755
@@ -182,13 +182,13 @@ then
 		error)
 			tput bold; tput setaf 1;; # bold red
 		skip)
-			tput bold; tput setaf 2;; # bold green
+			tput setaf 3;;            # yellow/brown
 		warn)
 			tput bold; tput setaf 3;; # bold yellow
 		pass)
 			tput setaf 2;;            # green
 		info)
-			tput setaf 3;;            # brown
+			tput setaf 3;;            # yellow/brown
 		*)
 			test -n "$quiet" && return;;
 		esac
Signature · 1 line
1.7.12.147.g6d168f4
#23 lore raw

PATCH v2 4/6 Refactor mechanics of testing in a sub test-lib

In reply to Adam Spiers

This will allow us to test the test framework more thoroughly without disrupting the top-level test metrics.

---
 t/t0000-basic.sh | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)
t/t0000-basic.sh +27 -17
index c6b42de..662cd2f 100755
@@ -55,39 +55,49 @@ test_expect_failure 'pretend we have a known breakage' '
 	false
 '
 
-test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib)' "
-	mkdir passing-todo &&
-	(cd passing-todo &&
-	cat >passing-todo.sh <<-EOF &&
+run_sub_test_lib_test () {
+	name="$1" descr="$2" # stdin is body of test code
+	mkdir $name &&
+	(cd $name &&
+	cat >$name.sh <<-EOF &&
 	#!$SHELL_PATH
 
-	test_description='A passing TODO test
+	test_description='$descr (run in sub test-lib)
 
 	This is run in a sub test-lib so that we do not get incorrect
 	passing metrics
 	'
 
 	# Point to the t/test-lib.sh, which isn't in ../ as usual
-	TEST_DIRECTORY=\"$TEST_DIRECTORY\"
-	. \"\$TEST_DIRECTORY\"/test-lib.sh
-
-	test_expect_failure 'pretend we have fixed a known breakage' '
-		:
-	'
+	TEST_DIRECTORY="$TEST_DIRECTORY"
+	. "\$TEST_DIRECTORY"/test-lib.sh
+	EOF
+	cat >>$name.sh &&
+	chmod +x $name.sh &&
+	./$name.sh >out 2>err)
+}
+
+check_sub_test_lib_test () {
+	name="$1" # stdin is test's expected stdout
+	(cd $name &&
+	! test -s err &&
+	sed -e 's/^> //' >expect &&
+	test_cmp expect out)
+}
 
+test_expect_success 'pretend we have fixed a known breakage' "
+	run_sub_test_lib_test passing-todo 'A passing TODO test' <<-EOF &&
+	test_expect_failure 'pretend we have fixed a known breakage' 'true'
 	test_done
 	EOF
-	chmod +x passing-todo.sh &&
-	./passing-todo.sh >out 2>err &&
-	! test -s err &&
-	sed -e 's/^> //' >expect <<-\\EOF &&
+	check_sub_test_lib_test passing-todo <<-EOF
 	> ok 1 - pretend we have fixed a known breakage # TODO known breakage
 	> # fixed 1 known breakage(s)
 	> # passed all 1 test(s)
 	> 1..1
 	EOF
-	test_cmp expect out)
 "
+
 test_set_prereq HAVEIT
 haveit=no
 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
@@ -166,7 +176,7 @@ test_expect_success 'tests clean up even on failures' "
 	test_must_fail ./failing-cleanup.sh >out 2>err &&
 	! test -s err &&
 	! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
-	sed -e 's/Z$//' -e 's/^> //' >expect <<-\\EOF &&
+	sed -e 's/Z$//' -e 's/^> //' >expect <<-EOF &&
 	> not ok 1 - tests clean up even after a failure
 	> #	Z
 	> #	touch clean-after-failure &&
Signature · 1 line
1.7.12.147.g6d168f4
#24 lore raw

Re: [PATCH v2 4/6] Refactor mechanics of testing in a sub test-lib

Quoted 2 lines · Adam Spiers

This will allow us to test the test framework more thoroughly without disrupting the top-level test metrics.

I see this is prep for the next patch, and the parts pulling out the test-runs into functions make sense. But this hunk confuses me:

t/t0000-basic.sh test_expect_success 'tests clean up even on failures' " · line 182

Quoted 9 lines
t/t0000-basic.sh +1 -1
@@ -166,7 +176,7 @@ test_expect_success 'tests clean up even on failures' "
 	test_must_fail ./failing-cleanup.sh >out 2>err &&
 	! test -s err &&
 	! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
-	sed -e 's/Z$//' -e 's/^> //' >expect <<-\\EOF &&
+	sed -e 's/Z$//' -e 's/^> //' >expect <<-EOF &&
 	> not ok 1 - tests clean up even after a failure
 	> #	Z
 	> #	touch clean-after-failure &&

Is it just that you are dropping the '\' in all of the here-docs because they are not needed? I think our usual style is not to interpolate, and to do so only when we explicitly want it, which can prevent accidental errors due to missing quoting.

Also, why is this one not converted into a check_sub... invocation?

-Peff

#32 lore raw

PATCH v2 5/6 Test the test framework more thoroughly

In reply to Adam Spiers

Add 5 new full test suite runs each with a different number of passing/failing/broken/fixed tests, in order to ensure that the correct exit code and output are generated in each case. As before, these are run in a subdirectory in order to disrupt the metrics for the parent tests.

---
 t/t0000-basic.sh | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
t/t0000-basic.sh +110 -0
index 662cd2f..644cc2c 100755
@@ -77,6 +77,15 @@ run_sub_test_lib_test () {
 	./$name.sh >out 2>err)
 }
 
+run_sub_test_lib_test_expecting_failures () {
+	if run_sub_test_lib_test "$@"; then
+		echo 'sub test-lib run should have failed'
+		return 1
+	else
+		return 0
+	fi
+}
+
 check_sub_test_lib_test () {
 	name="$1" # stdin is test's expected stdout
 	(cd $name &&
@@ -85,6 +94,54 @@ check_sub_test_lib_test () {
 	test_cmp expect out)
 }
 
+test_expect_success 'pretend we have a fully passing test suite' "
+	run_sub_test_lib_test full-pass '3 passing tests' <<-EOF &&
+	for i in 1 2 3; do
+		test_expect_success \"passing test #\\\$i\" 'true'
+	done
+	test_done
+	EOF
+	check_sub_test_lib_test full-pass <<-EOF
+	> ok 1 - passing test #1
+	> ok 2 - passing test #2
+	> ok 3 - passing test #3
+	> # passed all 3 test(s)
+	> 1..3
+	EOF
+"
+
+test_expect_success 'pretend we have a partially passing test suite' "
+	run_sub_test_lib_test_expecting_failures partial-pass '2/3 tests passing' <<-EOF &&
+	test_expect_success 'passing test #1' 'true'
+	test_expect_success 'failing test #2' 'false'
+	test_expect_success 'passing test #3' 'true'
+	test_done
+	EOF
+	check_sub_test_lib_test partial-pass <<-EOF
+	> ok 1 - passing test #1
+	> not ok 2 - failing test #2
+	#	false
+	> ok 3 - passing test #3
+	> # failed 1 among 3 test(s)
+	> 1..3
+	EOF
+"
+
+test_expect_success 'pretend we have a known breakage' "
+	run_sub_test_lib_test failing-todo 'A failing TODO test' <<-EOF &&
+	test_expect_success 'passing test' 'true'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_done
+	EOF
+	check_sub_test_lib_test failing-todo <<-EOF
+	> ok 1 - passing test
+	> not ok 2 - pretend we have a known breakage # TODO known breakage
+	> # still have 1 known breakage(s)
+	> # passed all remaining 1 test(s)
+	> 1..2
+	EOF
+"
+
 test_expect_success 'pretend we have fixed a known breakage' "
 	run_sub_test_lib_test passing-todo 'A passing TODO test' <<-EOF &&
 	test_expect_failure 'pretend we have fixed a known breakage' 'true'
@@ -98,6 +155,59 @@ test_expect_success 'pretend we have fixed a known breakage' "
 	EOF
 "
 
+test_expect_success 'pretend we have a pass, fail, and known breakage' "
+	run_sub_test_lib_test_expecting_failures mixed-results1 'mixed results #1' <<-EOF &&
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'failing test' 'false'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_done
+	EOF
+	check_sub_test_lib_test mixed-results1 <<-EOF
+	> ok 1 - passing test
+	> not ok 2 - failing test
+	> #	false
+	> not ok 3 - pretend we have a known breakage # TODO known breakage
+	> # still have 1 known breakage(s)
+	> # failed 1 among remaining 2 test(s)
+	> 1..3
+	EOF
+"
+
+test_expect_success 'pretend we have a mix of all possible results' "
+	run_sub_test_lib_test_expecting_failures mixed-results2 'mixed results #2' <<-EOF &&
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'failing test' 'false'
+	test_expect_success 'failing test' 'false'
+	test_expect_success 'failing test' 'false'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_expect_failure 'pretend we have fixed a known breakage' 'true'
+	test_done
+	EOF
+	check_sub_test_lib_test mixed-results2 <<-EOF
+	> ok 1 - passing test
+	> ok 2 - passing test
+	> ok 3 - passing test
+	> ok 4 - passing test
+	> not ok 5 - failing test
+	> #	false
+	> not ok 6 - failing test
+	> #	false
+	> not ok 7 - failing test
+	> #	false
+	> not ok 8 - pretend we have a known breakage # TODO known breakage
+	> not ok 9 - pretend we have a known breakage # TODO known breakage
+	> ok 10 - pretend we have fixed a known breakage # TODO known breakage
+	> # fixed 1 known breakage(s)
+	> # still have 2 known breakage(s)
+	> # failed 3 among remaining 8 test(s)
+	> 1..10
+	EOF
+"
+
 test_set_prereq HAVEIT
 haveit=no
 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
Signature · 1 line
1.7.12.147.g6d168f4
#33 lore raw

PATCH v2 6/6 Treat unexpectedly fixed known breakages more seriously

In reply to Adam Spiers

Change color of unexpectedly fixed known breakages to bold red. An unexpectedly passing test indicates that the test code is somehow broken or out of sync with the code it is testing. Either way this is an error which is potentially as bad as a failing test, and as such is no longer portrayed as a pass in the output.

---
 t/t0000-basic.sh | 29 +++++++++++++++++++++++------
 t/test-lib.sh    | 13 +++++++++----
 2 files changed, 32 insertions(+), 10 deletions(-)
t/t0000-basic.sh +23 -6
index 644cc2c..459d0c7 100755
@@ -148,13 +148,30 @@ test_expect_success 'pretend we have fixed a known breakage' "
 	test_done
 	EOF
 	check_sub_test_lib_test passing-todo <<-EOF
-	> ok 1 - pretend we have fixed a known breakage # TODO known breakage
-	> # fixed 1 known breakage(s)
-	> # passed all 1 test(s)
+	> ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
+	> # 1 known breakage(s) vanished; please update test(s)
 	> 1..1
 	EOF
 "
 
+test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' "
+	run_sub_test_lib_test partially-passing-todos '2 TODO tests, one passing' <<-EOF &&
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_expect_success 'pretend we have a passing test' 'true'
+	test_expect_failure 'pretend we have fixed another known breakage' 'true'
+	test_done
+	EOF
+	check_sub_test_lib_test partially-passing-todos <<-EOF
+	> not ok 1 - pretend we have a known breakage # TODO known breakage
+	> ok 2 - pretend we have a passing test
+	> ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
+	> # 1 known breakage(s) vanished; please update test(s)
+	> # still have 1 known breakage(s)
+	> # passed all remaining 1 test(s)
+	> 1..3
+	EOF
+"
+
 test_expect_success 'pretend we have a pass, fail, and known breakage' "
 	run_sub_test_lib_test_expecting_failures mixed-results1 'mixed results #1' <<-EOF &&
 	test_expect_success 'passing test' 'true'
@@ -200,10 +217,10 @@ test_expect_success 'pretend we have a mix of all possible results' "
 	> #	false
 	> not ok 8 - pretend we have a known breakage # TODO known breakage
 	> not ok 9 - pretend we have a known breakage # TODO known breakage
-	> ok 10 - pretend we have fixed a known breakage # TODO known breakage
-	> # fixed 1 known breakage(s)
+	> ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
+	> # 1 known breakage(s) vanished; please update test(s)
 	> # still have 2 known breakage(s)
-	> # failed 3 among remaining 8 test(s)
+	> # failed 3 among remaining 7 test(s)
 	> 1..10
 	EOF
 "
t/test-lib.sh +9 -4
index 7028ba8..b403e85 100755
@@ -278,7 +278,7 @@ test_failure_ () {
 
 test_known_broken_ok_ () {
 	test_fixed=$(($test_fixed+1))
-	say_color "" "ok $test_count - $@ # TODO known breakage"
+	say_color error "ok $test_count - $@ # TODO known breakage vanished"
 }
 
 test_known_broken_failure_ () {
@@ -373,13 +373,18 @@ test_done () {
 
 	if test "$test_fixed" != 0
 	then
-		say_color pass "# fixed $test_fixed known breakage(s)"
+		say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
 	fi
 	if test "$test_broken" != 0
 	then
 		say_color warn "# still have $test_broken known breakage(s)"
-		msg="remaining $(($test_count-$test_broken)) test(s)"
+	fi
+	if test "$test_broken" != 0 || test "$test_fixed" != 0
+	then
+		test_remaining=$(( $test_count - $test_broken - $test_fixed ))
+		msg="remaining $test_remaining test(s)"
 	else
+		test_remaining=$test_count
 		msg="$test_count test(s)"
 	fi
 	case "$test_failure" in
@@ -393,7 +398,7 @@ test_done () {
 
 		if test $test_external_has_tap -eq 0
 		then
-			if test $test_count -gt 0
+			if test $test_remaining -gt 0
 			then
 				say_color pass "# passed all $msg"
 			fi
Signature · 1 line
1.7.12.147.g6d168f4
#35 lore raw
In reply to Adam Spiers
Quoted 8 lines · Adam Spiers
Quoted 4 lines

t/test-lib.sh test_failure_ () { · line 283

Quoted 2 lines
t/test-lib.sh +1 -0
+	say_color error "ok $test_count - $@ # TODO known breakage vanished"
 }

Also I wonder if this is still a "TODO".

Hah, I should trust my first instincts more; my first version of the patch dropped the "TODO", but then I put it back in because I thought people would object :-)

TODO is a special token[1] respected by TAP harnesses like "prove". I'm not sure what practical impact it has, but it should probably remain.

-Peff

[1] http://testanything.org/wiki/index.php/TAP_specification#TODO_tests

#36 lore raw
Quoted 6 lines · Jeff King

TODO is a special token[1] respected by TAP harnesses like "prove". I'm not sure what practical impact it has, but it should probably remain.

-Peff

[1] http://testanything.org/wiki/index.php/TAP_specification#TODO_tests

Thanks, I didn't know that. For reasons I just stated elsewhere in this thread, I don't _completely_ agree with the specification where it says:

"Should a todo test point begin succeeding, the harness should report it as a bonus. This indicates that whatever you were supposed to do has been done and you should promote this to a normal test point."

However those semantics are well-defined enough to warrant keeping the "TODO" as you suggest.

#3 lore raw
In reply to Jeff King
Quoted 8 lines · Jeff King
Quoted 6 lines · Adam Spiers

The end result of these changes is that:

- red is _only_ used for things which have gone unexpectedly wrong:
test failures, unexpected test passes, and failures with the framework,

Quoted 9 lines
Quoted 4 lines

- yellow is _only_ used for known breakages, and

- green is _only_ used for things which have gone to plan and require no further work to be done.

Sounds reasonable, and I think the new output looks nice. I notice that skipped tests are still in green. I wonder if they should be in yellow, too.

What about blue instead? This would keep the colouring scheme more
consistent with the one used by prove:
<http://search.cpan.org/~ovid/Test-Harness/bin/prove>
by autotest:
<http://www.gnu.org/software/autoconf/manual/autoconf.html#Using-Autotest>
and by the Automake-generated test harness:
<http://www.gnu.org/software/automake/manual/automake.html#Scripts_002dbased-Testsuites>

Just my 2 cents,
Stefano

#4 lore raw
Quoted 18 lines · Stefano Lattarini
Quoted 8 lines · Jeff King
Quoted 6 lines · Adam Spiers

The end result of these changes is that:

- red is _only_ used for things which have gone unexpectedly wrong:
test failures, unexpected test passes, and failures with the framework,

Quoted 9 lines
Quoted 4 lines

- yellow is _only_ used for known breakages, and

- green is _only_ used for things which have gone to plan and require no further work to be done.

Sounds reasonable, and I think the new output looks nice. I notice that skipped tests are still in green. I wonder if they should be in yellow, too.

Quoted 7 lines

What about blue instead? This would keep the colouring scheme more
consistent with the one used by prove:
<http://search.cpan.org/~ovid/Test-Harness/bin/prove>
by autotest:
<http://www.gnu.org/software/autoconf/manual/autoconf.html#Using-Autotest>
and by the Automake-generated test harness:
<http://www.gnu.org/software/automake/manual/automake.html#Scripts_002dbased-Testsuites>

Sounds good to me! Blue is the conventional color for informational signs, so seems like a natural fit for skipped tests. Not sure whether it should be bold or not though? I'll wait for a more solid group consensus before re-rolling yet another patch :-)

#5 lore raw
Quoted 12 lines · Adam Spiers
Quoted 11 lines
Quoted 4 lines

Sounds reasonable, and I think the new output looks nice. I notice that skipped tests are still in green. I wonder if they should be in yellow, too.

What about blue instead? This would keep the colouring scheme more
consistent with the one used by prove:
<http://search.cpan.org/~ovid/Test-Harness/bin/prove>
by autotest:
<http://www.gnu.org/software/autoconf/manual/autoconf.html#Using-Autotest>
and by the Automake-generated test harness:
<http://www.gnu.org/software/automake/manual/automake.html#Scripts_002dbased-Testsuites>

Quoted 4 lines

Sounds good to me! Blue is the conventional color for informational signs, so seems like a natural fit for skipped tests. Not sure whether it should be bold or not though? I'll wait for a more solid group consensus before re-rolling yet another patch :-)

Blue would be fine with me. No strong opinion on bold or not (my gut is that most things should not be bold unless there is a good reason, but that is just a feeling).

-Peff

#6 lore raw

PATCH v4 3/6 Color skipped tests blue

Skipped tests indicate incomplete test coverage. Whilst this is not a test failure or other error, it's still not complete success, so according to the universal traffic lights coloring scheme, yellow/brown seems more suitable than green. However, it's more informational than cautionary, so instead we use blue which is a universal color for information signs.

---
 t/test-lib.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/test-lib.sh +2 -2
index 5293830..78c88c2 100755
@@ -182,13 +182,13 @@ then
 		error)
 			tput bold; tput setaf 1;; # bold red
 		skip)
-			tput bold; tput setaf 2;; # bold green
+			tput setaf 4;;            # blue
 		warn)
 			tput bold; tput setaf 3;; # bold yellow
 		pass)
 			tput setaf 2;;            # green
 		info)
-			tput setaf 3;;            # brown
+			tput setaf 3;;            # yellow/brown
 		*)
 			test -n "$quiet" && return;;
 		esac
Signature · 1 line
1.7.12.147.g6d168f4
#7 lore raw

Re: [PATCH v4 3/6] Color skipped tests blue

Am 9/19/2012 22:24, schrieb Adam Spiers:

t/test-lib.sh then · line 185

Quoted 3 lines
t/test-lib.sh +1 -1
 		skip)
-			tput bold; tput setaf 2;; # bold green
+			tput setaf 4;;            # blue

It's unreadable on black background. Keep it bold; that works on both black and white background.

-- Hannes

#8 lore raw

PATCH v5 3/3 Color skipped tests bold blue

Skipped tests indicate incomplete test coverage. Whilst this is not a test failure or other error, it's still not complete success, so according to the universal traffic lights coloring scheme, yellow/brown seems more suitable than green. However, it's more informational than cautionary, so instead we use blue which is a universal color for information signs. Bold blue should work better on both black and white backgrounds than normal blue.

---
 t/test-lib.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/test-lib.sh +2 -2
index 5293830..5ef87d4 100755
@@ -182,13 +182,13 @@ then
 		error)
 			tput bold; tput setaf 1;; # bold red
 		skip)
-			tput bold; tput setaf 2;; # bold green
+			tput bold; tput setaf 4;; # bold blue
 		warn)
 			tput bold; tput setaf 3;; # bold yellow
 		pass)
 			tput setaf 2;;            # green
 		info)
-			tput setaf 3;;            # brown
+			tput setaf 3;;            # yellow/brown
 		*)
 			test -n "$quiet" && return;;
 		esac
Signature · 1 line
1.7.12.147.g6d168f4
#9 lore raw

Re: [PATCH v5 3/3] Color skipped tests bold blue

Hi Adam.

Quoted 9 lines · Adam Spiers

Skipped tests indicate incomplete test coverage. Whilst this is not a test failure or other error, it's still not complete success, so according to the universal traffic lights coloring scheme, yellow/brown seems more suitable than green. However, it's more informational than cautionary, so instead we use blue which is a universal color for information signs. Bold blue should work better on both black and white backgrounds than normal blue.

A very minor nit (feel free to ignore it): IMHO, it should be nice to state explicitly in the commit message that blue is already used by other testsuite-related software to highlight skipped tests; you can report the examples of at least Automake, Autotest and prove -- and extra kudos if you find further examples ;-)

Thanks,
Stefano

#10 lore raw

Re: [PATCH v5 3/3] Color skipped tests bold blue

Quoted 12 lines · Stefano Lattarini

Hi Adam.

Quoted 9 lines · Adam Spiers

Skipped tests indicate incomplete test coverage. Whilst this is not a test failure or other error, it's still not complete success, so according to the universal traffic lights coloring scheme, yellow/brown seems more suitable than green. However, it's more informational than cautionary, so instead we use blue which is a universal color for information signs. Bold blue should work better on both black and white backgrounds than normal blue.

Quoted 5 lines

A very minor nit (feel free to ignore it): IMHO, it should be nice to state explicitly in the commit message that blue is already used by other testsuite-related software to highlight skipped tests; you can report the examples of at least Automake, Autotest and prove -- and extra kudos if you find further examples ;-)

Thanks. Will tweak the proposed log message to include the above when queuing the updated patch.

#11 lore raw

Re: [PATCH v4 3/6] Color skipped tests blue

In reply to Johannes Sixt
Quoted 7 lines · Johannes Sixt

Am 9/19/2012 22:24, schrieb Adam Spiers:

t/test-lib.sh then · line 185

Quoted 3 lines

skip)

t/test-lib.sh +1 -1
-                     tput bold; tput setaf 2;; # bold green
+                     tput setaf 4;;            # blue

It's unreadable on black background. Keep it bold; that works on both black and white background.

Whilst my preference aligns with yours in this particular case, we are now on a slippery slope, since these days terminal colors are infinitely configurable, and some heretics even choose backgrounds which are neither black nor white ;-) I don't want to trigger a long discussion or end up spamming the list with lots of different color scheme patches in an attempt to please everyone. So bold blue will be my last version of this patch.

#20 lore raw

Re: [PATCH v2 2/6] Make 'not ok $count - $message' consistent with 'ok $count - $message'

In reply to Adam Spiers
Quoted 7 lines · Adam Spiers
---
 t/t0000-basic.sh | 4 ++--
 t/test-lib.sh    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 t/test-lib.sh

Peff might have already pointed out, but this is wrong. Will queue with an obvious tweak.

Thanks.

#21 lore raw

Re: [PATCH v2 2/6] Make 'not ok $count - $message' consistent with 'ok $count - $message'

Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Adam Spiers
---
 t/t0000-basic.sh | 4 ++--
 t/test-lib.sh    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
Quoted 4 lines
Quoted 1 line
 mode change 100644 => 100755 t/test-lib.sh

Peff might have already pointed out, but this is wrong. Will queue with an obvious tweak.

Oops, good catch. That's a bug in my emacs config, I suspect. Thanks for the tweak. You guys have eagle eyes!

#25 lore raw

Re: [PATCH v2 4/6] Refactor mechanics of testing in a sub test-lib

In reply to Jeff King
Quoted 8 lines · Jeff King
Quoted 2 lines · Adam Spiers

This will allow us to test the test framework more thoroughly without disrupting the top-level test metrics.

I see this is prep for the next patch, and the parts pulling out the test-runs into functions make sense. But this hunk confuses me:

Quoted 12 lines

t/t0000-basic.sh test_expect_success 'tests clean up even on failures' " · line 182

Quoted 9 lines
t/t0000-basic.sh +1 -1
@@ -166,7 +176,7 @@ test_expect_success 'tests clean up even on failures' "
 	test_must_fail ./failing-cleanup.sh >out 2>err &&
 	! test -s err &&
 	! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
-	sed -e 's/Z$//' -e 's/^> //' >expect <<-\\EOF &&
+	sed -e 's/Z$//' -e 's/^> //' >expect <<-EOF &&
 	> not ok 1 - tests clean up even after a failure
 	> #	Z
 	> #	touch clean-after-failure &&

Is it just that you are dropping the '\' in all of the here-docs because they are not needed?

Hmm, I think I previously misunderstood the point of the \\ due to never seeing that syntax before (since my Perl background taught me to write <<'EOF' instead). I noticed that the tests all passed without it, and mistakenly assumed it had become unnecessary due to the refactoring.

Quoted 3 lines

I think our usual style is not to interpolate, and
to do so only when we explicitly want it, which can prevent accidental errors due to missing quoting.

Right, that makes sense. I'd vote to put it back in then.

Quoted 1 line

Also, why is this one not converted into a check_sub... invocation?

Because it was much further down in that file so I didn't notice it during the refactoring ;-) I've also noticed I can use test_must_fail instead of introducing run_sub_test_lib_test_expecting_failures.

So I'll have to re-roll 4--6 again. Presumably I can just reply to [PATCH v2 4/6] with modified v3 versions without having to resend the first three in the series, which haven't changed.

#26 lore raw

PATCH v3 4/6 Refactor mechanics of testing in a sub test-lib

This will allow us to test the test framework more thoroughly without disrupting the top-level test metrics.

---
 t/t0000-basic.sh | 67 ++++++++++++++++++++++++--------------------------------
 1 file changed, 29 insertions(+), 38 deletions(-)
t/t0000-basic.sh +29 -38
index c6b42de..029e3bd 100755
@@ -55,39 +55,49 @@ test_expect_failure 'pretend we have a known breakage' '
 	false
 '
 
-test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib)' "
-	mkdir passing-todo &&
-	(cd passing-todo &&
-	cat >passing-todo.sh <<-EOF &&
+run_sub_test_lib_test () {
+	name="$1" descr="$2" # stdin is body of test code
+	mkdir $name &&
+	(cd $name &&
+	cat >$name.sh <<-EOF &&
 	#!$SHELL_PATH
 
-	test_description='A passing TODO test
+	test_description='$descr (run in sub test-lib)
 
 	This is run in a sub test-lib so that we do not get incorrect
 	passing metrics
 	'
 
 	# Point to the t/test-lib.sh, which isn't in ../ as usual
-	TEST_DIRECTORY=\"$TEST_DIRECTORY\"
-	. \"\$TEST_DIRECTORY\"/test-lib.sh
-
-	test_expect_failure 'pretend we have fixed a known breakage' '
-		:
-	'
+	TEST_DIRECTORY="$TEST_DIRECTORY"
+	. "\$TEST_DIRECTORY"/test-lib.sh
+	EOF
+	cat >>$name.sh &&
+	chmod +x $name.sh &&
+	./$name.sh >out 2>err)
+}
+
+check_sub_test_lib_test () {
+	name="$1" # stdin is test's expected stdout
+	(cd $name &&
+	! test -s err &&
+	sed -e 's/^> //' -e 's/Z$//' >expect &&
+	test_cmp expect out)
+}
 
+test_expect_success 'pretend we have fixed a known breakage' "
+	run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
+	test_expect_failure 'pretend we have fixed a known breakage' 'true'
 	test_done
 	EOF
-	chmod +x passing-todo.sh &&
-	./passing-todo.sh >out 2>err &&
-	! test -s err &&
-	sed -e 's/^> //' >expect <<-\\EOF &&
+	check_sub_test_lib_test passing-todo <<-\\EOF
 	> ok 1 - pretend we have fixed a known breakage # TODO known breakage
 	> # fixed 1 known breakage(s)
 	> # passed all 1 test(s)
 	> 1..1
 	EOF
-	test_cmp expect out)
 "
+
 test_set_prereq HAVEIT
 haveit=no
 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
@@ -137,19 +147,8 @@ then
 fi
 
 test_expect_success 'tests clean up even on failures' "
-	mkdir failing-cleanup &&
-	(
-	cd failing-cleanup &&
-
-	cat >failing-cleanup.sh <<-EOF &&
-	#!$SHELL_PATH
-
-	test_description='Failing tests with cleanup commands'
-
-	# Point to the t/test-lib.sh, which isn't in ../ as usual
-	TEST_DIRECTORY=\"$TEST_DIRECTORY\"
-	. \"\$TEST_DIRECTORY\"/test-lib.sh
-
+	test_must_fail run_sub_test_lib_test \
+		failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
 	test_expect_success 'tests clean up even after a failure' '
 		touch clean-after-failure &&
 		test_when_finished rm clean-after-failure &&
@@ -159,14 +158,8 @@ test_expect_success 'tests clean up even on failures' "
 		test_when_finished \"(exit 2)\"
 	'
 	test_done
-
 	EOF
-
-	chmod +x failing-cleanup.sh &&
-	test_must_fail ./failing-cleanup.sh >out 2>err &&
-	! test -s err &&
-	! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
-	sed -e 's/Z$//' -e 's/^> //' >expect <<-\\EOF &&
+	check_sub_test_lib_test failing-cleanup <<-\\EOF
 	> not ok 1 - tests clean up even after a failure
 	> #	Z
 	> #	touch clean-after-failure &&
@@ -180,8 +173,6 @@ test_expect_success 'tests clean up even on failures' "
 	> # failed 2 among 2 test(s)
 	> 1..2
 	EOF
-	test_cmp expect out
-	)
 "
 
 ################################################################
Signature · 1 line
1.7.12.147.g6d168f4
#27 lore raw

PATCH v3 5/6 Test the test framework more thoroughly

Add 5 new full test suite runs each with a different number of passing/failing/broken/fixed tests, in order to ensure that the correct exit code and output are generated in each case. As before, these are run in a subdirectory in order to disrupt the metrics for the parent tests.

---
 t/t0000-basic.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
t/t0000-basic.sh +104 -0
index 029e3bd..65f578f 100755
@@ -85,6 +85,55 @@ check_sub_test_lib_test () {
 	test_cmp expect out)
 }
 
+test_expect_success 'pretend we have a fully passing test suite' "
+	run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
+	for i in 1 2 3; do
+		test_expect_success \"passing test #\$i\" 'true'
+	done
+	test_done
+	EOF
+	check_sub_test_lib_test full-pass <<-\\EOF
+	> ok 1 - passing test #1
+	> ok 2 - passing test #2
+	> ok 3 - passing test #3
+	> # passed all 3 test(s)
+	> 1..3
+	EOF
+"
+
+test_expect_success 'pretend we have a partially passing test suite' "
+	test_must_fail run_sub_test_lib_test \
+		partial-pass '2/3 tests passing' <<-\\EOF &&
+	test_expect_success 'passing test #1' 'true'
+	test_expect_success 'failing test #2' 'false'
+	test_expect_success 'passing test #3' 'true'
+	test_done
+	EOF
+	check_sub_test_lib_test partial-pass <<-\\EOF
+	> ok 1 - passing test #1
+	> not ok 2 - failing test #2
+	#	false
+	> ok 3 - passing test #3
+	> # failed 1 among 3 test(s)
+	> 1..3
+	EOF
+"
+
+test_expect_success 'pretend we have a known breakage' "
+	run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
+	test_expect_success 'passing test' 'true'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_done
+	EOF
+	check_sub_test_lib_test failing-todo <<-\\EOF
+	> ok 1 - passing test
+	> not ok 2 - pretend we have a known breakage # TODO known breakage
+	> # still have 1 known breakage(s)
+	> # passed all remaining 1 test(s)
+	> 1..2
+	EOF
+"
+
 test_expect_success 'pretend we have fixed a known breakage' "
 	run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
 	test_expect_failure 'pretend we have fixed a known breakage' 'true'
@@ -98,6 +147,61 @@ test_expect_success 'pretend we have fixed a known breakage' "
 	EOF
 "
 
+test_expect_success 'pretend we have a pass, fail, and known breakage' "
+	test_must_fail run_sub_test_lib_test \
+		mixed-results1 'mixed results #1' <<-\\EOF &&
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'failing test' 'false'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_done
+	EOF
+	check_sub_test_lib_test mixed-results1 <<-\\EOF
+	> ok 1 - passing test
+	> not ok 2 - failing test
+	> #	false
+	> not ok 3 - pretend we have a known breakage # TODO known breakage
+	> # still have 1 known breakage(s)
+	> # failed 1 among remaining 2 test(s)
+	> 1..3
+	EOF
+"
+
+test_expect_success 'pretend we have a mix of all possible results' "
+	test_must_fail run_sub_test_lib_test \
+		mixed-results2 'mixed results #2' <<-\\EOF &&
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'passing test' 'true'
+	test_expect_success 'failing test' 'false'
+	test_expect_success 'failing test' 'false'
+	test_expect_success 'failing test' 'false'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_expect_failure 'pretend we have fixed a known breakage' 'true'
+	test_done
+	EOF
+	check_sub_test_lib_test mixed-results2 <<-\\EOF
+	> ok 1 - passing test
+	> ok 2 - passing test
+	> ok 3 - passing test
+	> ok 4 - passing test
+	> not ok 5 - failing test
+	> #	false
+	> not ok 6 - failing test
+	> #	false
+	> not ok 7 - failing test
+	> #	false
+	> not ok 8 - pretend we have a known breakage # TODO known breakage
+	> not ok 9 - pretend we have a known breakage # TODO known breakage
+	> ok 10 - pretend we have fixed a known breakage # TODO known breakage
+	> # fixed 1 known breakage(s)
+	> # still have 2 known breakage(s)
+	> # failed 3 among remaining 8 test(s)
+	> 1..10
+	EOF
+"
+
 test_set_prereq HAVEIT
 haveit=no
 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
Signature · 1 line
1.7.12.147.g6d168f4
#28 lore raw

PATCH v3 6/6 Treat unexpectedly fixed known breakages more seriously

In reply to Adam Spiers

Change color of unexpectedly fixed known breakages to bold red. An unexpectedly passing test indicates that the test code is somehow broken or out of sync with the code it is testing. Either way this is an error which is potentially as bad as a failing test, and as such is no longer portrayed as a pass in the output.

---
 t/t0000-basic.sh | 30 ++++++++++++++++++++++++------
 t/test-lib.sh    | 13 +++++++++----
 2 files changed, 33 insertions(+), 10 deletions(-)
t/t0000-basic.sh +24 -6
index 65f578f..ed44f7d 100755
@@ -140,13 +140,31 @@ test_expect_success 'pretend we have fixed a known breakage' "
 	test_done
 	EOF
 	check_sub_test_lib_test passing-todo <<-\\EOF
-	> ok 1 - pretend we have fixed a known breakage # TODO known breakage
-	> # fixed 1 known breakage(s)
-	> # passed all 1 test(s)
+	> ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
+	> # 1 known breakage(s) vanished; please update test(s)
 	> 1..1
 	EOF
 "
 
+test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' "
+	run_sub_test_lib_test partially-passing-todos \
+		'2 TODO tests, one passing' <<-\\EOF &&
+	test_expect_failure 'pretend we have a known breakage' 'false'
+	test_expect_success 'pretend we have a passing test' 'true'
+	test_expect_failure 'pretend we have fixed another known breakage' 'true'
+	test_done
+	EOF
+	check_sub_test_lib_test partially-passing-todos <<-\\EOF
+	> not ok 1 - pretend we have a known breakage # TODO known breakage
+	> ok 2 - pretend we have a passing test
+	> ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
+	> # 1 known breakage(s) vanished; please update test(s)
+	> # still have 1 known breakage(s)
+	> # passed all remaining 1 test(s)
+	> 1..3
+	EOF
+"
+
 test_expect_success 'pretend we have a pass, fail, and known breakage' "
 	test_must_fail run_sub_test_lib_test \
 		mixed-results1 'mixed results #1' <<-\\EOF &&
@@ -194,10 +212,10 @@ test_expect_success 'pretend we have a mix of all possible results' "
 	> #	false
 	> not ok 8 - pretend we have a known breakage # TODO known breakage
 	> not ok 9 - pretend we have a known breakage # TODO known breakage
-	> ok 10 - pretend we have fixed a known breakage # TODO known breakage
-	> # fixed 1 known breakage(s)
+	> ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
+	> # 1 known breakage(s) vanished; please update test(s)
 	> # still have 2 known breakage(s)
-	> # failed 3 among remaining 8 test(s)
+	> # failed 3 among remaining 7 test(s)
 	> 1..10
 	EOF
 "
t/test-lib.sh +9 -4
index 7028ba8..b403e85 100755
@@ -278,7 +278,7 @@ test_failure_ () {
 
 test_known_broken_ok_ () {
 	test_fixed=$(($test_fixed+1))
-	say_color "" "ok $test_count - $@ # TODO known breakage"
+	say_color error "ok $test_count - $@ # TODO known breakage vanished"
 }
 
 test_known_broken_failure_ () {
@@ -373,13 +373,18 @@ test_done () {
 
 	if test "$test_fixed" != 0
 	then
-		say_color pass "# fixed $test_fixed known breakage(s)"
+		say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
 	fi
 	if test "$test_broken" != 0
 	then
 		say_color warn "# still have $test_broken known breakage(s)"
-		msg="remaining $(($test_count-$test_broken)) test(s)"
+	fi
+	if test "$test_broken" != 0 || test "$test_fixed" != 0
+	then
+		test_remaining=$(( $test_count - $test_broken - $test_fixed ))
+		msg="remaining $test_remaining test(s)"
 	else
+		test_remaining=$test_count
 		msg="$test_count test(s)"
 	fi
 	case "$test_failure" in
@@ -393,7 +398,7 @@ test_done () {
 
 		if test $test_external_has_tap -eq 0
 		then
-			if test $test_count -gt 0
+			if test $test_remaining -gt 0
 			then
 				say_color pass "# passed all $msg"
 			fi
Signature · 1 line
1.7.12.147.g6d168f4
#29 lore raw

Re: [PATCH v3 4/6] Refactor mechanics of testing in a sub test-lib

In reply to Adam Spiers
Quoted 34 lines · Adam Spiers

This will allow us to test the test framework more thoroughly without disrupting the top-level test metrics.

---
 t/t0000-basic.sh | 67 ++++++++++++++++++++++++--------------------------------
 1 file changed, 29 insertions(+), 38 deletions(-)
t/t0000-basic.sh +6 -5
index c6b42de..029e3bd 100755
@@ -55,39 +55,49 @@ test_expect_failure 'pretend we have a known breakage' '
 	false
 '
 
-test_expect_success 'pretend we have fixed a known breakage (run in sub test-lib)' "
-	mkdir passing-todo &&
-	(cd passing-todo &&
-	cat >passing-todo.sh <<-EOF &&
+run_sub_test_lib_test () {
+	name="$1" descr="$2" # stdin is body of test code
+	mkdir $name &&
+	(cd $name &&
+	cat >$name.sh <<-EOF &&
 	#!$SHELL_PATH
 
-	test_description='A passing TODO test
+	test_description='$descr (run in sub test-lib)
 
 	This is run in a sub test-lib so that we do not get incorrect
 	passing metrics
 	'
 

t/t0000-basic.sh test_expect_failure 'pretend we have a known breakage' ' · line 74

Quoted 10 lines
t/t0000-basic.sh +3 -6
 	# Point to the t/test-lib.sh, which isn't in ../ as usual
-	TEST_DIRECTORY=\"$TEST_DIRECTORY\"
-	. \"\$TEST_DIRECTORY\"/test-lib.sh
-
-	test_expect_failure 'pretend we have fixed a known breakage' '
-		:
-	'
+	TEST_DIRECTORY="$TEST_DIRECTORY"
+	. "\$TEST_DIRECTORY"/test-lib.sh
+	EOF

The quoting of $TEST_DIRECTORY in the assignment does not look correct (imagine a path with a double quote in it).

Removing the assignment and instead exporting TEST_DIRECTORY before calling name.sh may be a reasonable fix, than trying to quotemeta the value of $TEST_DIRECTORY here.

I'll re-queue this series in 'pu' with fixes and retitles; please eyeball them before submitting a reroll.

b465316 tests: paint unexpectedly fixed known breakages in bold red 7214717 tests: test the test framework more thoroughly
03c772a [SQUASH] t/t0000-basic.sh: quoting of TEST_DIRECTORY is screwed up 99fe0af tests: refactor mechanics of testing in a sub test-lib 6af90bf tests: paint skipped tests in bold blue
0b87581 tests: test number comes first in 'not ok $count - $message' 1c55079 tests: paint known breakages in bold yellow

The third one from the tip looks like the following, to re-indent to make it readable and then minimally fix the quoting.

Thanks.

 t/t0000-basic.sh | 50 +++++++++++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 23 deletions(-)
t/t0000-basic.sh +27 -23
index ee78e68..c3345a9 100755
@@ -56,33 +56,37 @@ test_expect_failure 'pretend we have a known breakage' '
 '
 
 run_sub_test_lib_test () {
-	name="$1" descr="$2" # stdin is body of test code
+	name="$1" descr="$2" # stdin is the body of the test code
 	mkdir $name &&
-	(cd $name &&
-	cat >$name.sh <<-EOF &&
-	#!$SHELL_PATH
-
-	test_description='$descr (run in sub test-lib)
-
-	This is run in a sub test-lib so that we do not get incorrect
-	passing metrics
-	'
-
-	# Point to the t/test-lib.sh, which isn't in ../ as usual
-	TEST_DIRECTORY="$TEST_DIRECTORY"
-	. "\$TEST_DIRECTORY"/test-lib.sh
-	EOF
-	cat >>$name.sh &&
-	chmod +x $name.sh &&
-	./$name.sh >out 2>err)
+	(
+		cd $name &&
+		cat >$name.sh <<-EOF &&
+		#!$SHELL_PATH
+
+		test_description='$descr (run in sub test-lib)
+
+		This is run in a sub test-lib so that we do not get incorrect
+		passing metrics
+		'
+
+		# Point to the t/test-lib.sh, which isn't in ../ as usual
+		. "\$TEST_DIRECTORY"/test-lib.sh
+		EOF
+		cat >>$name.sh &&
+		chmod +x $name.sh &&
+		export TEST_DIRECTORY &&
+		./$name.sh >out 2>err
+	)
 }
 
 check_sub_test_lib_test () {
-	name="$1" # stdin is expected output from the test
-	(cd $name &&
-	! test -s err &&
-	sed -e 's/^> //' -e 's/Z$//' >expect &&
-	test_cmp expect out)
+	name="$1" # stdin is the expected output from the test
+	(
+		cd $name &&
+		! test -s err &&
+		sed -e 's/^> //' -e 's/Z$//' >expect &&
+		test_cmp expect out
+	)
 }
 
 test_expect_success 'pretend we have fixed a known breakage' "
Signature · 1 line
1.7.12.1.389.g3dff30b
#30 lore raw

Re: [PATCH v2 4/6] Refactor mechanics of testing in a sub test-lib

In reply to Adam Spiers
Quoted 8 lines · Adam Spiers
Quoted 2 lines

Is it just that you are dropping the '\' in all of the here-docs because they are not needed?

Hmm, I think I previously misunderstood the point of the \\ due to never seeing that syntax before (since my Perl background taught me to write <<'EOF' instead). I noticed that the tests all passed without it, and mistakenly assumed it had become unnecessary due to the refactoring.

OK. You can write 'EOF' in the shell, too, but we tend not to in this project (and you can write \EOF in perl, but I agree that it is much less common in perl code I have seen).

Looking at it again, it is actually quite subtle what is going on. We wrap the outer test_expect_* calls in double-quotes so that the inner ones can use single-quotes easily. But that means that technically the contents of the here-doc _are_ interpolated. But not at test run-time, but rather at the call to test_expect_*. And that is why we nee to use "\\" instead of "\". So I think anybody trying to tweak these tests using shell metacharacters is in for a surprise either way. I'm not sure it is worth worrying about, though, as handling it would probably make the existing tests less readable.

Quoted 4 lines
Quoted 1 line

Also, why is this one not converted into a check_sub... invocation?

Because it was much further down in that file so I didn't notice it during the refactoring ;-)

OK. :)

Quoted 2 lines

I've also noticed I can use test_must_fail instead of introducing run_sub_test_lib_test_expecting_failures.

Good catch. I didn't notice that, but it definitely makes sense to reuse it.

Quoted 4 lines

So I'll have to re-roll 4--6 again. Presumably I can just reply to [PATCH v2 4/6] with modified v3 versions without having to resend the first three in the series, which haven't changed.

It all looks sane to me. Thanks again.

-Peff

#31 lore raw

Re: [PATCH v2 4/6] Refactor mechanics of testing in a sub test-lib

Quoted 7 lines · Jeff King

Looking at it again, it is actually quite subtle what is going on. We wrap the outer test_expect_* calls in double-quotes so that the inner ones can use single-quotes easily. But that means that technically the contents of the here-doc _are_ interpolated. But not at test run-time, but rather at the call to test_expect_*. And that is why we nee to use "\\" instead of "\". So I think anybody trying to tweak these tests using shell metacharacters is in for a surprise either way.

Actually I already did that in one place:

test_expect_success 'pretend we have a fully passing test suite' "
run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF && for i in 1 2 3; do
test_expect_success \"passing test #\$i\" 'true'
done
test_done
EOF
[...]
"

Without the \\ preceeding the EOF, it needed to be:

                    test_expect_success \"passing test #\\\$i\" 'true'
Quoted 2 lines

I'm not sure it is worth worrying about, though, as handling it would probably make the existing tests less readable.

Yeah, the for loop is perhaps slightly overkill :-)

Quoted 1 line

It all looks sane to me. Thanks again.

Thanks for your (unnervingly) thorough reviews ;-)

#34 lore raw

Re: [PATCH v2 0/6] make test output coloring more intuitive

In reply to Adam Spiers
Quoted 11 lines · Adam Spiers

This series of commits attempts to make test output coloring more intuitive, so that:

- red is _only_ used for things which have gone unexpectedly wrong:
test failures, unexpected test passes, and failures with the framework,

- yellow is _only_ used for known breakages and skipped tests, and

- green is _only_ used for things which have gone to plan and require no further work to be done.

Thanks, I like this much better than the original (and it's much easier to review broken apart like this).

I raised a few minor questions in the refactoring patch, but other than that (and assuming your answers are what I expect, I do not care enough about them to block the series), it looks very good.

The new "a passing expect_failure is a breakage" is a good thing. When it's unexpected, it will help call attention to it and let us figure out early what changed. And when it is expected (because you are fixing the breakage), it is an easy way to remind you to update the tests. :)

Thanks for working on it.

-Peff

#12 lore raw

Re: [PATCH v4 3/6] Color skipped tests blue

In reply to Adam Spiers
Quoted 10 lines · Adam Spiers
 t/test-lib.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/test-lib.sh +0 -0
index 5293830..78c88c2 100755
@@ -182,13 +182,13 @@ then
 		error)
 			tput bold; tput setaf 1;; # bold red

t/test-lib.sh then · line 191

Quoted 10 lines
t/test-lib.sh +2 -2
 		skip)
-			tput bold; tput setaf 2;; # bold green
+			tput setaf 4;;            # blue
 		warn)
 			tput bold; tput setaf 3;; # bold yellow
 		pass)
 			tput setaf 2;;            # green
 		info)
-			tput setaf 3;;            # brown
+			tput setaf 3;;            # yellow/brown

I happened to be running a test script with "-v" earlier today, and I noticed that the "expecting success..." dump of the test contents is also yellow. By your new rules, shouldn't it be blue?

I think it is matching the "info" type, which from the discussion should be blue, no?

Maybe it is just my terminal. I see it is labeled as "brown" here, but it looks very yellow (and I am using the stock xterm colors. According to:

https://en.wikipedia.org/wiki/ANSI_colors

It looks it really is brown on some platforms. I'm not sure if it is worth worrying about. I don't really want to get into configurable colors just for the test-suite output.

-Peff

#13 lore raw

Re: [PATCH v4 3/6] Color skipped tests blue

Quoted 27 lines · Jeff King
Quoted 10 lines · Adam Spiers
 t/test-lib.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
t/test-lib.sh +0 -0
index 5293830..78c88c2 100755
@@ -182,13 +182,13 @@ then
 		error)
 			tput bold; tput setaf 1;; # bold red

t/test-lib.sh then · line 191

Quoted 10 lines
t/test-lib.sh +2 -2
 		skip)
-			tput bold; tput setaf 2;; # bold green
+			tput setaf 4;;            # blue
 		warn)
 			tput bold; tput setaf 3;; # bold yellow
 		pass)
 			tput setaf 2;;            # green
 		info)
-			tput setaf 3;;            # brown
+			tput setaf 3;;            # yellow/brown

I happened to be running a test script with "-v" earlier today, and I noticed that the "expecting success..." dump of the test contents is also yellow. By your new rules, shouldn't it be blue?

Quoted 2 lines

I think it is matching the "info" type, which from the discussion should be blue, no?

It uses the "default" colour:

    say >&3 "expecting success: $2"

where say is defined:

    say () {
            say_color info "$*"
    }

Many other messages are output in this default colour too, and I never proposed to change it. The only time in the discussion where blue was associated with "info" was in this sentence I wrote in the commit message for the patch altering the colour of "skip" messages:

"However, it's more informational than cautionary, so instead we
use blue which is a universal color for information signs."

Whilst it could also be applied to "info", I don't think it would be a good idea to have the "skip" and "info" colours *both* as bold blue. It seems to me more important that the "skip" messages should visually stand out more than "info", since they are rarer and a more notable level of information than the latter (especially if --verbose is used). Additionally, yellow is already somewhat overloaded (yellow for "info" and bold yellow for "warn"). Therefore I would suggest changing "info" to perhaps bold white or bold cyan. Or "skip" could be magenta and "info" blue. But now we are heading down a slippery slope; it'll be near impossible to please everyone. Any final thoughts?

Quoted 7 lines

Maybe it is just my terminal. I see it is labeled as "brown" here, but it looks very yellow (and I am using the stock xterm colors. According to:

https://en.wikipedia.org/wiki/ANSI_colors

It looks it really is brown on some platforms.

Yes, it can be.

Quoted 3 lines

I'm not sure if it is
worth worrying about. I don't really want to get into configurable colors just for the test-suite output.

Agreed. There is no indisputably correct combination. However, I think that, modulo a tweak for the above, we are definitely in the right ball park. The main thing is that the traffic light colour scheme is adhered to, and that different types of message are clearly visually separated, with more important ones standing out more than less important ones.