@matheusbsbs / matheus-bagliano / commits / 8539b46534
Fork 0

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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 6, 2019 at 13:08 UTC 8539b465341cc475f219ed46273a1c157bddafa0
1 file changed +21 -7
t/t3701-add-interactive.sh
+21 -7
@@ -23,6 +23,17 @@ diff_cmp () {
23 test_cmp "$1.filtered" "$2.filtered"
24 }
25
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 +
37 test_expect_success 'setup (initial)' '
38 echo content >file &&
39 git add file &&
@@ -451,35 +462,38 @@ test_expect_success 'patch mode ignores unmerged entries' '
462 diff_cmp expected diff
463 '
464
454 -test_expect_success TTY 'diffs can be colorized' '
465 +test_expect_success 'diffs can be colorized' '
466 git reset --hard &&
467
468 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 &&
471
472 # We do not want to depend on the exact coloring scheme
473 # git uses for diffs, so just check that we saw some kind of color.
474 grep "$(printf "\\033")" output
475 '
476
465 -test_expect_success TTY 'diffFilter filters diff' '
477 +test_expect_success 'diffFilter filters diff' '
478 git reset --hard &&
479
480 echo content >test &&
481 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 &&
484
485 # avoid depending on the exact coloring or content of the prompts,
486 # and just make sure we saw our diff prefixed
487 grep foo:.*content output
488 '
489
477 -test_expect_success TTY 'detect bogus diffFilter output' '
490 +test_expect_success 'detect bogus diffFilter output' '
491 git reset --hard &&
492
493 echo content >test &&
494 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
497 '
498
499 test_expect_success 'patch-mode via -i prompts for files' '
@@ -689,7 +703,7 @@ test_expect_success 'show help from add--helper' '
703 <BOLD;BLUE>What now<RESET>>$SP
704 Bye.
705 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 &&
707 test_decode_color <actual.colored >actual &&
708 test_i18ncmp expect actual
709 '