Skip to content

Commit 5476bdf

Browse files
avargitster
authored andcommitted
diff tests: don't ignore "git diff" exit code in "read" loop
Fix a test pattern that originated in f1af60b (Support 'diff=pgm' attribute, 2007-04-22) so that we'll stop using "git diff" on the left-hand-side of a pipe, and thus ignoring its exit code. Rather than use intermediate files let's rewrite these tests to a much simpler but more exhaustive "test_tmp" where we'll ignore certain fields in the output. Note that this is not a faithful conversion of the previous "read/test" in some cases, as we were ignoring more fields there than we strictly needed to. Now we'll "test_cmp" everything we can, and only ignore the likes of paths to $TEMPDIR etc. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d239ef1 commit 5476bdf

File tree

1 file changed

+53
-51
lines changed

1 file changed

+53
-51
lines changed

t/t4020-diff-external.sh

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ test_expect_success setup '
2424
'
2525

2626
test_expect_success 'GIT_EXTERNAL_DIFF environment' '
27-
28-
GIT_EXTERNAL_DIFF=echo git diff | {
29-
read path oldfile oldhex oldmode newfile newhex newmode &&
30-
test "z$path" = zfile &&
31-
test "z$oldmode" = z100644 &&
32-
test "z$newhex" = "z$ZERO_OID" &&
33-
test "z$newmode" = z100644 &&
34-
oh=$(git rev-parse --verify HEAD:file) &&
35-
test "z$oh" = "z$oldhex"
36-
}
27+
cat >expect <<-EOF &&
28+
file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
29+
EOF
30+
GIT_EXTERNAL_DIFF=echo git diff >out &&
31+
cut -d" " -f1,3- <out >actual &&
32+
test_cmp expect actual
3733
3834
'
3935

@@ -52,15 +48,14 @@ test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
5248
test_expect_success SYMLINKS 'typechange diff' '
5349
rm -f file &&
5450
ln -s elif file &&
55-
GIT_EXTERNAL_DIFF=echo git diff | {
56-
read path oldfile oldhex oldmode newfile newhex newmode &&
57-
test "z$path" = zfile &&
58-
test "z$oldmode" = z100644 &&
59-
test "z$newhex" = "z$ZERO_OID" &&
60-
test "z$newmode" = z120000 &&
61-
oh=$(git rev-parse --verify HEAD:file) &&
62-
test "z$oh" = "z$oldhex"
63-
} &&
51+
52+
cat >expect <<-EOF &&
53+
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 120000
54+
EOF
55+
GIT_EXTERNAL_DIFF=echo git diff >out &&
56+
cut -d" " -f1,3-4,6- <out >actual &&
57+
test_cmp expect actual &&
58+
6459
GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
6560
git diff >expect &&
6661
test_cmp expect actual
@@ -70,15 +65,13 @@ test_expect_success 'diff.external' '
7065
git reset --hard &&
7166
echo third >file &&
7267
test_config diff.external echo &&
73-
git diff | {
74-
read path oldfile oldhex oldmode newfile newhex newmode &&
75-
test "z$path" = zfile &&
76-
test "z$oldmode" = z100644 &&
77-
test "z$newhex" = "z$ZERO_OID" &&
78-
test "z$newmode" = z100644 &&
79-
oh=$(git rev-parse --verify HEAD:file) &&
80-
test "z$oh" = "z$oldhex"
81-
}
68+
69+
cat >expect <<-EOF &&
70+
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
71+
EOF
72+
git diff >out &&
73+
cut -d" " -f1,3-4,6- <out >actual &&
74+
test_cmp expect actual
8275
'
8376

8477
test_expect_success !SANITIZE_LEAK 'diff.external should apply only to diff' '
@@ -101,16 +94,12 @@ test_expect_success 'diff attribute' '
10194
10295
echo >.gitattributes "file diff=parrot" &&
10396
104-
git diff | {
105-
read path oldfile oldhex oldmode newfile newhex newmode &&
106-
test "z$path" = zfile &&
107-
test "z$oldmode" = z100644 &&
108-
test "z$newhex" = "z$ZERO_OID" &&
109-
test "z$newmode" = z100644 &&
110-
oh=$(git rev-parse --verify HEAD:file) &&
111-
test "z$oh" = "z$oldhex"
112-
}
113-
97+
cat >expect <<-EOF &&
98+
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
99+
EOF
100+
git diff >out &&
101+
cut -d" " -f1,3-4,6- <out >actual &&
102+
test_cmp expect actual
114103
'
115104

116105
test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
@@ -132,16 +121,12 @@ test_expect_success 'diff attribute' '
132121
133122
echo >.gitattributes "file diff=color" &&
134123
135-
git diff | {
136-
read path oldfile oldhex oldmode newfile newhex newmode &&
137-
test "z$path" = zfile &&
138-
test "z$oldmode" = z100644 &&
139-
test "z$newhex" = "z$ZERO_OID" &&
140-
test "z$newmode" = z100644 &&
141-
oh=$(git rev-parse --verify HEAD:file) &&
142-
test "z$oh" = "z$oldhex"
143-
}
144-
124+
cat >expect <<-EOF &&
125+
file $(git rev-parse --verify HEAD:file) 100644 $(test_oid zero) 100644
126+
EOF
127+
git diff >out &&
128+
cut -d" " -f1,3-4,6- <out >actual &&
129+
test_cmp expect actual
145130
'
146131

147132
test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
@@ -159,14 +144,26 @@ test_expect_success 'diff attribute and --no-ext-diff' '
159144
test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
160145
>.gitattributes &&
161146
test_config diff.external "echo ext-global" &&
162-
GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-env
147+
148+
cat >expect <<-EOF &&
149+
ext-env file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
150+
EOF
151+
GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
152+
cut -d" " -f1-2,4- <out >actual &&
153+
test_cmp expect actual
163154
'
164155

165156
test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
166157
test_config diff.foo.command "echo ext-attribute" &&
167158
test_config diff.external "echo ext-global" &&
168159
echo "file diff=foo" >.gitattributes &&
169-
GIT_EXTERNAL_DIFF="echo ext-env" git diff | grep ext-attribute
160+
161+
cat >expect <<-EOF &&
162+
ext-attribute file $(git rev-parse --verify HEAD:file) 100644 file $(test_oid zero) 100644
163+
EOF
164+
GIT_EXTERNAL_DIFF="echo ext-env" git diff >out &&
165+
cut -d" " -f1-2,4- <out >actual &&
166+
test_cmp expect actual
170167
'
171168

172169
test_expect_success 'no diff with -diff' '
@@ -212,7 +209,12 @@ test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
212209
touch file.ext &&
213210
git add file.ext &&
214211
echo with extension > file.ext &&
215-
GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext &&
212+
213+
cat >expect <<-EOF &&
214+
file.ext file $(git rev-parse --verify HEAD:file) 100644 file.ext $(test_oid zero) 100644
215+
EOF
216+
GIT_EXTERNAL_DIFF=echo git diff file.ext >out &&
217+
cut -d" " -f1,3- <out >actual &&
216218
git update-index --force-remove file.ext &&
217219
rm file.ext
218220
'

0 commit comments

Comments
 (0)