Skip to content

Commit 571e472

Browse files
committed
Merge branch 'sg/test-x'
Running test scripts under -x option of the shell is often not a useful way to debug them, because the error messages from the commands tests try to capture and inspect are contaminated by the tracing output by the shell. An earlier work done to make it more pleasant to run tests under -x with recent versions of bash is extended to cover posix shells that do not support BASH_XTRACEFD. * sg/test-x: travis-ci: run tests with '-x' tracing t/README: add a note about don't saving stderr of compound commands t1510-repo-setup: mark as untraceable with '-x' t9903-bash-prompt: don't check the stderr of __git_ps1() t5570-git-daemon: don't check the stderr of a subshell t5526: use $TRASH_DIRECTORY to specify the path of GIT_TRACE log file t5500-fetch-pack: don't check the stderr of a subshell t3030-merge-recursive: don't check the stderr of a subshell t1507-rev-parse-upstream: don't check the stderr of a shell function t: add means to disable '-x' tracing for individual test scripts t: prevent '-x' tracing from interfering with test helpers' stderr
2 parents d92a015 + aedffe9 commit 571e472

12 files changed

+94
-62
lines changed

ci/lib-travisci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fi
9797
export DEVELOPER=1
9898
export DEFAULT_TEST_TARGET=prove
9999
export GIT_PROVE_OPTS="--timer --jobs 3 --state=failed,slow,save"
100-
export GIT_TEST_OPTS="--verbose-log"
100+
export GIT_TEST_OPTS="--verbose-log -x"
101101
export GIT_TEST_CLONE_2GB=YesPlease
102102

103103
case "$jobname" in

t/README

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ appropriately before running "make".
8484

8585
-x::
8686
Turn on shell tracing (i.e., `set -x`) during the tests
87-
themselves. Implies `--verbose`. Note that in non-bash shells,
88-
this can cause failures in some tests which redirect and test
89-
the output of shell functions. Use with caution.
87+
themselves. Implies `--verbose`.
88+
Ignored in test scripts that set the variable 'test_untraceable'
89+
to a non-empty value, unless it's run with a Bash version
90+
supporting BASH_XTRACEFD, i.e. v4.1 or later.
9091

9192
-d::
9293
--debug::
@@ -452,6 +453,22 @@ Don't:
452453
causing the next test to start in an unexpected directory. Do so
453454
inside a subshell if necessary.
454455

456+
- save and verify the standard error of compound commands, i.e. group
457+
commands, subshells, and shell functions (except test helper
458+
functions like 'test_must_fail') like this:
459+
460+
( cd dir && git cmd ) 2>error &&
461+
test_cmp expect error
462+
463+
When running the test with '-x' tracing, then the trace of commands
464+
executed in the compound command will be included in standard error
465+
as well, quite possibly throwing off the subsequent checks examining
466+
the output. Instead, save only the relevant git command's standard
467+
error:
468+
469+
( cd dir && git cmd 2>../error ) &&
470+
test_cmp expect error
471+
455472
- Break the TAP output
456473

457474
The raw output from your test may be interpreted by a TAP harness. TAP

t/lib-terminal.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ test_terminal () {
99
echo >&4 "test_terminal: need to declare TTY prerequisite"
1010
return 127
1111
fi
12-
perl "$TEST_DIRECTORY"/test-terminal.perl "$@"
13-
}
12+
perl "$TEST_DIRECTORY"/test-terminal.perl "$@" 2>&7
13+
} 7>&2 2>&4
1414

1515
test_lazy_prereq TTY '
1616
test_have_prereq PERL &&

t/t1507-rev-parse-upstream.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ commit_subject () {
4242

4343
error_message () {
4444
(cd clone &&
45-
test_must_fail git rev-parse --verify "$@")
45+
test_must_fail git rev-parse --verify "$@" 2>../error)
4646
}
4747

4848
test_expect_success '@{upstream} resolves to correct full name' '
@@ -159,8 +159,8 @@ test_expect_success 'branch@{u} error message when no upstream' '
159159
cat >expect <<-EOF &&
160160
fatal: no upstream configured for branch ${sq}non-tracking${sq}
161161
EOF
162-
error_message non-tracking@{u} 2>actual &&
163-
test_i18ncmp expect actual
162+
error_message non-tracking@{u} &&
163+
test_i18ncmp expect error
164164
'
165165

166166
test_expect_success '@{u} error message when no upstream' '
@@ -175,8 +175,8 @@ test_expect_success 'branch@{u} error message with misspelt branch' '
175175
cat >expect <<-EOF &&
176176
fatal: no such branch: ${sq}no-such-branch${sq}
177177
EOF
178-
error_message no-such-branch@{u} 2>actual &&
179-
test_i18ncmp expect actual
178+
error_message no-such-branch@{u} &&
179+
test_i18ncmp expect error
180180
'
181181

182182
test_expect_success '@{u} error message when not on a branch' '
@@ -192,8 +192,8 @@ test_expect_success 'branch@{u} error message if upstream branch not fetched' '
192192
cat >expect <<-EOF &&
193193
fatal: upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
194194
EOF
195-
error_message bad-upstream@{u} 2>actual &&
196-
test_i18ncmp expect actual
195+
error_message bad-upstream@{u} &&
196+
test_i18ncmp expect error
197197
'
198198

199199
test_expect_success 'pull works when tracking a local branch' '

t/t1510-repo-setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ A few rules for repo setup:
3939
11. When user's cwd is outside worktree, cwd remains unchanged,
4040
prefix is NULL.
4141
"
42+
43+
# This test heavily relies on the standard error of nested function calls.
44+
test_untraceable=UnfortunatelyYes
45+
4246
. ./test-lib.sh
4347

4448
here=$(pwd)

t/t3030-merge-recursive.sh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,20 +525,22 @@ test_expect_success 'merge-recursive w/ empty work tree - ours has rename' '
525525
GIT_INDEX_FILE="$PWD/ours-has-rename-index" &&
526526
export GIT_INDEX_FILE &&
527527
mkdir "$GIT_WORK_TREE" &&
528-
git read-tree -i -m $c7 &&
529-
git update-index --ignore-missing --refresh &&
530-
git merge-recursive $c0 -- $c7 $c3 &&
531-
git ls-files -s >actual-files
532-
) 2>actual-err &&
533-
>expected-err &&
528+
git read-tree -i -m $c7 2>actual-err &&
529+
test_must_be_empty actual-err &&
530+
git update-index --ignore-missing --refresh 2>actual-err &&
531+
test_must_be_empty actual-err &&
532+
git merge-recursive $c0 -- $c7 $c3 2>actual-err &&
533+
test_must_be_empty actual-err &&
534+
git ls-files -s >actual-files 2>actual-err &&
535+
test_must_be_empty actual-err
536+
) &&
534537
cat >expected-files <<-EOF &&
535538
100644 $o3 0 b/c
536539
100644 $o0 0 c
537540
100644 $o0 0 d/e
538541
100644 $o0 0 e
539542
EOF
540-
test_cmp expected-files actual-files &&
541-
test_cmp expected-err actual-err
543+
test_cmp expected-files actual-files
542544
'
543545

544546
test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' '
@@ -548,20 +550,22 @@ test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' '
548550
GIT_INDEX_FILE="$PWD/theirs-has-rename-index" &&
549551
export GIT_INDEX_FILE &&
550552
mkdir "$GIT_WORK_TREE" &&
551-
git read-tree -i -m $c3 &&
552-
git update-index --ignore-missing --refresh &&
553-
git merge-recursive $c0 -- $c3 $c7 &&
554-
git ls-files -s >actual-files
555-
) 2>actual-err &&
556-
>expected-err &&
553+
git read-tree -i -m $c3 2>actual-err &&
554+
test_must_be_empty actual-err &&
555+
git update-index --ignore-missing --refresh 2>actual-err &&
556+
test_must_be_empty actual-err &&
557+
git merge-recursive $c0 -- $c3 $c7 2>actual-err &&
558+
test_must_be_empty actual-err &&
559+
git ls-files -s >actual-files 2>actual-err &&
560+
test_must_be_empty actual-err
561+
) &&
557562
cat >expected-files <<-EOF &&
558563
100644 $o3 0 b/c
559564
100644 $o0 0 c
560565
100644 $o0 0 d/e
561566
100644 $o0 0 e
562567
EOF
563-
test_cmp expected-files actual-files &&
564-
test_cmp expected-err actual-err
568+
test_cmp expected-files actual-files
565569
'
566570

567571
test_expect_success 'merge removes empty directories' '

t/t5500-fetch-pack.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,24 +482,24 @@ test_expect_success 'set up tests of missing reference' '
482482
test_expect_success 'test lonely missing ref' '
483483
(
484484
cd client &&
485-
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy
486-
) >/dev/null 2>error-m &&
485+
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy 2>../error-m
486+
) &&
487487
test_i18ncmp expect-error error-m
488488
'
489489

490490
test_expect_success 'test missing ref after existing' '
491491
(
492492
cd client &&
493-
test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy
494-
) >/dev/null 2>error-em &&
493+
test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy 2>../error-em
494+
) &&
495495
test_i18ncmp expect-error error-em
496496
'
497497

498498
test_expect_success 'test missing ref before existing' '
499499
(
500500
cd client &&
501-
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A
502-
) >/dev/null 2>error-me &&
501+
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A 2>../error-me
502+
) &&
503503
test_i18ncmp expect-error error-me
504504
'
505505

t/t5526-fetch-submodules.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test_expect_success "fetch --recurse-submodules -j2 has the same output behaviou
8585
add_upstream_commit &&
8686
(
8787
cd downstream &&
88-
GIT_TRACE=$(pwd)/../trace.out git fetch --recurse-submodules -j2 2>../actual.err
88+
GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
8989
) &&
9090
test_must_be_empty actual.out &&
9191
test_i18ncmp expect.err actual.err &&

t/t5570-git-daemon.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test_expect_success 'no-op fetch -v stderr is as expected' '
5050
'
5151

5252
test_expect_success 'no-op fetch without "-v" is quiet' '
53-
(cd clone && git fetch) 2>stderr &&
53+
(cd clone && git fetch 2>../stderr) &&
5454
! test -s stderr
5555
'
5656

t/t9903-bash-prompt.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -735,22 +735,12 @@ test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, p
735735
test_cmp expected "$actual"
736736
'
737737

738-
test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stdout)' '
738+
test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '
739739
printf " (GIT_DIR!)" >expected &&
740740
(
741741
GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
742742
cd .git &&
743-
__git_ps1 >"$actual" 2>/dev/null
744-
) &&
745-
test_cmp expected "$actual"
746-
'
747-
748-
test_expect_success 'prompt - hide if pwd ignored - inside gitdir (stderr)' '
749-
printf "" >expected &&
750-
(
751-
GIT_PS1_HIDE_IF_PWD_IGNORED=y &&
752-
cd .git &&
753-
__git_ps1 >/dev/null 2>"$actual"
743+
__git_ps1 >"$actual"
754744
) &&
755745
test_cmp expected "$actual"
756746
'

0 commit comments

Comments
 (0)