Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 7e27173

Browse files
peffgitster
authored andcommitted
t/lib-terminal: make TTY a lazy prerequisite
When lib-terminal.sh is sourced by a test script, we immediately set up the TTY prerequisite. We do so inside a test_expect_success, because that nicely isolates any generated output. However, this early test can interfere with a script that later wants to skip all tests (e.g., t5541 then goes on to set up the httpd server, and wants to skip_all if that fails). TAP output doesn't let us skip everything after we have already run at least one test. We could fix this by reordering the inclusion of lib-terminal.sh in t5541 to go after the httpd setup. That solves this case, but we might eventually hit a case with circular dependencies, where either lib-*.sh include might want to skip_all after the other has run a test. So instead, let's just remove the ordering constraint entirely by doing the setup inside a test_lazy_prereq construct, rather than in a regular test. We never cared about the test outcome anyway (it was written to always succeed). Note that in addition to setting up the prerequisite, the current test also defines test_terminal. Since we can't affect the environment from a lazy_prereq, we have to hoist that out. We previously depended on it _not_ being defined when the TTY prereq isn't set as a way to ensure that tests properly declare their dependency on TTY. However, we still cover the case (see the in-code comment for details). Reported-by: Jens Lehmann <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bbc4e8 commit 7e27173

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

t/lib-terminal.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
#!/bin/sh
22

3-
test_expect_success PERL 'set up terminal for tests' '
3+
# Catch tests which should depend on TTY but forgot to. There's no need
4+
# to aditionally check that the TTY prereq is set here. If the test declared
5+
# it and we are running the test, then it must have been set.
6+
test_terminal () {
7+
if ! test_declared_prereq TTY
8+
then
9+
echo >&4 "test_terminal: need to declare TTY prerequisite"
10+
return 127
11+
fi
12+
perl "$TEST_DIRECTORY"/test-terminal.perl "$@"
13+
}
14+
15+
test_lazy_prereq TTY '
16+
test_have_prereq PERL &&
17+
418
# Reading from the pty master seems to get stuck _sometimes_
519
# on Mac OS X 10.5.0, using Perl 5.10.0 or 5.8.9.
620
#
@@ -15,21 +29,8 @@ test_expect_success PERL 'set up terminal for tests' '
1529
# After 2000 iterations or so it hangs.
1630
# https://rt.cpan.org/Ticket/Display.html?id=65692
1731
#
18-
if test "$(uname -s)" = Darwin
19-
then
20-
:
21-
elif
22-
perl "$TEST_DIRECTORY"/test-terminal.perl \
23-
sh -c "test -t 1 && test -t 2"
24-
then
25-
test_set_prereq TTY &&
26-
test_terminal () {
27-
if ! test_declared_prereq TTY
28-
then
29-
echo >&4 "test_terminal: need to declare TTY prerequisite"
30-
return 127
31-
fi
32-
perl "$TEST_DIRECTORY"/test-terminal.perl "$@"
33-
}
34-
fi
32+
test "$(uname -s)" != Darwin &&
33+
34+
perl "$TEST_DIRECTORY"/test-terminal.perl \
35+
sh -c "test -t 1 && test -t 2"
3536
'

0 commit comments

Comments
 (0)