Skip to content

Commit ed870d3

Browse files
committed
t3701: avoid depending on the TTY prerequisite
The TTY prerequisite is a rather heavy one: it not only requires Perl to work, but also the IO/Pty.pm module (with native support, and it requires pseudo terminals, too). In particular, test cases marked with the TTY prerequisite would be skipped in Git for Windows' SDK. In the case of `git add -p`, we do not actually need that big a hammer, as we do not want to test any functionality that requires a pseudo terminal; all we want is for the interactive add command to use color, even when being called from within the test suite. And we found exactly such a trick earlier already: when we added a test case to verify that the main loop of `git add -i` is colored appropriately. Let's use that trick instead of the TTY prerequisite. While at it, we avoid the pipes, as we do not want a SIGPIPE to break the regression test cases (which will be much more likely when we do not run everything through Perl because that is inherently slower). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent acfa161 commit ed870d3

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

t/t3701-add-interactive.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ diff_cmp () {
2323
test_cmp "$1.filtered" "$2.filtered"
2424
}
2525

26+
# This function uses a trick to manipulate the interactive add to use color:
27+
# the `want_color()` function special-cases the situation where a pager was
28+
# spawned and Git now wants to output colored text: to detect that situation,
29+
# the environment variable `GIT_PAGER_IN_USE` is set. However, color is
30+
# suppressed despite that environment variable if the `TERM` variable
31+
# indicates a dumb terminal, so we set that variable, too.
32+
33+
force_color () {
34+
env GIT_PAGER_IN_USE=true TERM=vt100 "$@"
35+
}
36+
2637
test_expect_success 'setup (initial)' '
2738
echo content >file &&
2839
git add file &&
@@ -451,35 +462,38 @@ test_expect_success 'patch mode ignores unmerged entries' '
451462
diff_cmp expected diff
452463
'
453464

454-
test_expect_success TTY 'diffs can be colorized' '
465+
test_expect_success 'diffs can be colorized' '
455466
git reset --hard &&
456467
457468
echo content >test &&
458-
printf y | test_terminal git add -p >output 2>&1 &&
469+
printf y >y &&
470+
force_color git add -p >output 2>&1 <y &&
459471
460472
# We do not want to depend on the exact coloring scheme
461473
# git uses for diffs, so just check that we saw some kind of color.
462474
grep "$(printf "\\033")" output
463475
'
464476

465-
test_expect_success TTY 'diffFilter filters diff' '
477+
test_expect_success 'diffFilter filters diff' '
466478
git reset --hard &&
467479
468480
echo content >test &&
469481
test_config interactive.diffFilter "sed s/^/foo:/" &&
470-
printf y | test_terminal git add -p >output 2>&1 &&
482+
printf y >y &&
483+
force_color git add -p >output 2>&1 <y &&
471484
472485
# avoid depending on the exact coloring or content of the prompts,
473486
# and just make sure we saw our diff prefixed
474487
grep foo:.*content output
475488
'
476489

477-
test_expect_success TTY 'detect bogus diffFilter output' '
490+
test_expect_success 'detect bogus diffFilter output' '
478491
git reset --hard &&
479492
480493
echo content >test &&
481494
test_config interactive.diffFilter "echo too-short" &&
482-
printf y | test_must_fail test_terminal git add -p
495+
printf y >y &&
496+
test_must_fail force_color git add -p <y
483497
'
484498

485499
test_expect_success 'patch-mode via -i prompts for files' '
@@ -689,7 +703,7 @@ test_expect_success 'show help from add--helper' '
689703
<BOLD;BLUE>What now<RESET>>$SP
690704
Bye.
691705
EOF
692-
test_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored &&
706+
test_write_lines h | force_color git add -i >actual.colored &&
693707
test_decode_color <actual.colored >actual &&
694708
test_i18ncmp expect actual
695709
'

0 commit comments

Comments
 (0)