On Wed, Dec 14, 2011 at 07:25:30PM -0500, Jeff King wrote: > [1] Actually, you could abandon the idea of feeding garbage altogether, > and instead open the descriptor outside the test, then check that its > offset is still 0 after the test. You'd have to use a helper program to > do the ftell(), but it should work as the descriptor position will be > shared. And here's what that patch would look like. You still want to feed a garbage file, because you want to make sure that there is something for it to actually read. And then either it can choke on the garbage and fail, or if not, you can detect afterwards that it was read. This correctly detects the bug in t7006. I can't decide if it's clever or ugly. --- t/stdin-garbage | 1 + t/test-lib.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) create mode 100644 t/stdin-garbage diff --git a/t/stdin-garbage b/t/stdin-garbage new file mode 100644 index 0000000..3a2ebc2 --- /dev/null +++ b/t/stdin-garbage @@ -0,0 +1 @@ +This is a garbage file that will be connected to the stdin of each test. diff --git a/t/test-lib.sh b/t/test-lib.sh index bdd9513..9b4692b 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -466,6 +466,10 @@ test_debug () { test "$debug" = "" || eval "$1" } +test_stdin_unread_ () { + test "`perl -e 'print tell(STDIN)'`" = 0 +} + test_eval_ () { # This is a separate function because some tests use # "return" to end a test_expect_success block early. @@ -475,9 +479,21 @@ test_eval_ () { test_run_ () { test_cleanup=: expecting_failure=$2 + # feed the test a bogus stdin, but keep a spare descriptor open in case + # the test redirects stdin, which affects us since it is an eval + exec 6<&0 + exec 7<"$TEST_DIRECTORY/stdin-garbage" + exec 0<&7 test_eval_ "$1" eval_ret=$? + # check that nobody read from our bogus descriptor + if test $eval_ret = 0 && ! test_stdin_unread_ <&7; then + echo >&4 "bug in the test script: somebody read from stdin" + eval_ret=1 + fi + exec 0<&6 + if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure" then test_eval_ "$test_cleanup" -- 1.7.8.rc2.30.g803b1a -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html