do not use GIT_TRACE_PACKET=3 in tests

Some test scripts use the GIT_TRACE mechanism to dump debugging information to descriptor 3 (and point it to a file using the shell). On Windows, however, bash is unable to set up descriptor 3. We do not write our trace to the file, and worse, we may interfere with other operations happening on descriptor 3, causing tests to fail or even behave inconsistently. Prior to commit 97a83fa (upload-pack: remove packet debugging harness), these tests used GIT_DEBUG_SEND_PACK, which only supported output to a descriptor. The tests in t5503 were always broken on Windows, and were marked to be skipped via the NOT_MINGW prerequisite. In t5700, the tests used to pass prior to 97a83fa, but only because they were not careful enough; because we only grepped the trace file, an empty file looked successful to us. But post-97a83fa, the writing to descriptor 3 causes "git fetch" to hang (presumably because we are throwing random bytes into the middle of the protocol). Now that we are using the GIT_TRACE mechanism, we can improve both scripts by asking git to write directly to a file rather than a descriptor. That fixes the hang in t5700, and should allow t5503 to successfully run on Windows. In both cases we now also use "test -s" to double-check that our trace file actually contains output, which should reduce the possibility of an erroneously passing test. Signed-off-by: Jeff King <peff@peff.net> Tested-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 20, 2013 at 13:43 UTC 2ad23273e71ff708936bd924502186b8789a7289
2 files changed +27 -25
t/t5503-tagfollow.sh
+18 -20
@@ -4,10 +4,6 @@ test_description='test automatic tag following'
4
5 . ./test-lib.sh
6
7 -if ! test_have_prereq NOT_MINGW; then
8 - say "GIT_TRACE_PACKET not supported - skipping tests"
9 -fi
10 -
7 # End state of the repository:
8 #
9 # T - tag1 S - tag2
@@ -17,7 +13,7 @@ fi
13 # \ C - origin/cat \
14 # origin/master master
15
20 -test_expect_success NOT_MINGW setup '
16 +test_expect_success setup '
17 test_tick &&
18 echo ichi >file &&
19 git add file &&
@@ -39,33 +35,35 @@ test_expect_success NOT_MINGW setup '
35 '
36
37 U=UPLOAD_LOG
38 +UPATH="$(pwd)/$U"
39
43 -test_expect_success NOT_MINGW 'setup expect' '
40 +test_expect_success 'setup expect' '
41 cat - <<EOF >expect
42 want $A
43 EOF
44 '
45
46 get_needs () {
47 + test -s "$1" &&
48 perl -alne '
49 next unless $F[1] eq "upload-pack<";
50 last if $F[2] eq "0000";
51 print $F[2], " ", $F[3];
54 - ' "$@"
52 + ' "$1"
53 }
54
57 -test_expect_success NOT_MINGW 'fetch A (new commit : 1 connection)' '
55 +test_expect_success 'fetch A (new commit : 1 connection)' '
56 rm -f $U &&
57 (
58 cd cloned &&
61 - GIT_TRACE_PACKET=3 git fetch 3>../$U &&
59 + GIT_TRACE_PACKET=$UPATH git fetch &&
60 test $A = $(git rev-parse --verify origin/master)
61 ) &&
62 get_needs $U >actual &&
63 test_cmp expect actual
64 '
65
68 -test_expect_success NOT_MINGW "create tag T on A, create C on branch cat" '
66 +test_expect_success "create tag T on A, create C on branch cat" '
67 git tag -a -m tag1 tag1 $A &&
68 T=$(git rev-parse --verify tag1) &&
69
@@ -77,18 +75,18 @@ test_expect_success NOT_MINGW "create tag T on A, create C on branch cat" '
75 git checkout master
76 '
77
80 -test_expect_success NOT_MINGW 'setup expect' '
78 +test_expect_success 'setup expect' '
79 cat - <<EOF >expect
80 want $C
81 want $T
82 EOF
83 '
84
87 -test_expect_success NOT_MINGW 'fetch C, T (new branch, tag : 1 connection)' '
85 +test_expect_success 'fetch C, T (new branch, tag : 1 connection)' '
86 rm -f $U &&
87 (
88 cd cloned &&
91 - GIT_TRACE_PACKET=3 git fetch 3>../$U &&
89 + GIT_TRACE_PACKET=$UPATH git fetch &&
90 test $C = $(git rev-parse --verify origin/cat) &&
91 test $T = $(git rev-parse --verify tag1) &&
92 test $A = $(git rev-parse --verify tag1^0)
@@ -97,7 +95,7 @@ test_expect_success NOT_MINGW 'fetch C, T (new branch, tag : 1 connection)' '
95 test_cmp expect actual
96 '
97
100 -test_expect_success NOT_MINGW "create commits O, B, tag S on B" '
98 +test_expect_success "create commits O, B, tag S on B" '
99 test_tick &&
100 echo O >file &&
101 git add file &&
@@ -113,18 +111,18 @@ test_expect_success NOT_MINGW "create commits O, B, tag S on B" '
111 S=$(git rev-parse --verify tag2)
112 '
113
116 -test_expect_success NOT_MINGW 'setup expect' '
114 +test_expect_success 'setup expect' '
115 cat - <<EOF >expect
116 want $B
117 want $S
118 EOF
119 '
120
123 -test_expect_success NOT_MINGW 'fetch B, S (commit and tag : 1 connection)' '
121 +test_expect_success 'fetch B, S (commit and tag : 1 connection)' '
122 rm -f $U &&
123 (
124 cd cloned &&
127 - GIT_TRACE_PACKET=3 git fetch 3>../$U &&
125 + GIT_TRACE_PACKET=$UPATH git fetch &&
126 test $B = $(git rev-parse --verify origin/master) &&
127 test $B = $(git rev-parse --verify tag2^0) &&
128 test $S = $(git rev-parse --verify tag2)
@@ -133,14 +131,14 @@ test_expect_success NOT_MINGW 'fetch B, S (commit and tag : 1 connection)' '
131 test_cmp expect actual
132 '
133
136 -test_expect_success NOT_MINGW 'setup expect' '
134 +test_expect_success 'setup expect' '
135 cat - <<EOF >expect
136 want $B
137 want $S
138 EOF
139 '
140
143 -test_expect_success NOT_MINGW 'new clone fetch master and tags' '
141 +test_expect_success 'new clone fetch master and tags' '
142 git branch -D cat
143 rm -f $U
144 (
@@ -148,7 +146,7 @@ test_expect_success NOT_MINGW 'new clone fetch master and tags' '
146 cd clone2 &&
147 git init &&
148 git remote add origin .. &&
151 - GIT_TRACE_PACKET=3 git fetch 3>../$U &&
149 + GIT_TRACE_PACKET=$UPATH git fetch &&
150 test $B = $(git rev-parse --verify origin/master) &&
151 test $S = $(git rev-parse --verify tag2) &&
152 test $B = $(git rev-parse --verify tag2^0) &&
t/t5700-clone-reference.sh
+9 -5
@@ -54,11 +54,14 @@ cd "$base_dir"
54
55 rm -f "$U.D"
56
57 -test_expect_success 'cloning with reference (no -l -s)' \
58 -'GIT_TRACE_PACKET=3 git clone --reference B "file://$(pwd)/A" D 3>"$U.D"'
57 +test_expect_success 'cloning with reference (no -l -s)' '
58 + GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
59 +'
60
60 -test_expect_success 'fetched no objects' \
61 -'! grep " want" "$U.D"'
61 +test_expect_success 'fetched no objects' '
62 + test -s "$U.D" &&
63 + ! grep " want" "$U.D"
64 +'
65
66 cd "$base_dir"
67
@@ -173,9 +176,10 @@ test_expect_success 'fetch with incomplete alternates' '
176 (
177 cd K &&
178 git remote add J "file://$base_dir/J" &&
176 - GIT_TRACE_PACKET=3 git fetch J 3>"$U.K"
179 + GIT_TRACE_PACKET=$U.K git fetch J
180 ) &&
181 master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
182 + test -s "$U.K" &&
183 ! grep " want $master_object" "$U.K" &&
184 tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
185 ! grep " want $tag_object" "$U.K"