diff tests: don't ignore "git diff" exit code in "read" loop
Fix a test pattern that originated in f1af60bdba4 (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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 7, 2022 at 13:48 UTC
5476bdf0e86272c47a93ae5c10486d2de31415bd
1 file changed
+53
-51
t/t4020-diff-external.sh
+53
-51
@@ -24,16 +24,12 @@ test_expect_success setup '
24
'
25
26
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
33
34
'
35
@@ -52,15 +48,14 @@ test_expect_success 'GIT_EXTERNAL_DIFF environment and --no-ext-diff' '
48
test_expect_success SYMLINKS 'typechange diff' '
49
rm -f file &&
50
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
+
59
GIT_EXTERNAL_DIFF=echo git diff --no-ext-diff >actual &&
60
git diff >expect &&
61
test_cmp expect actual
@@ -70,15 +65,13 @@ test_expect_success 'diff.external' '
65
git reset --hard &&
66
echo third >file &&
67
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
75
'
76
77
test_expect_success !SANITIZE_LEAK 'diff.external should apply only to diff' '
@@ -101,16 +94,12 @@ test_expect_success 'diff attribute' '
94
95
echo >.gitattributes "file diff=parrot" &&
96
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
103
'
104
105
test_expect_success !SANITIZE_LEAK 'diff attribute should apply only to diff' '
@@ -132,16 +121,12 @@ test_expect_success 'diff attribute' '
121
122
echo >.gitattributes "file diff=color" &&
123
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
130
'
131
132
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' '
144
test_expect_success 'GIT_EXTERNAL_DIFF trumps diff.external' '
145
>.gitattributes &&
146
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
154
'
155
156
test_expect_success 'attributes trump GIT_EXTERNAL_DIFF and diff.external' '
157
test_config diff.foo.command "echo ext-attribute" &&
158
test_config diff.external "echo ext-global" &&
159
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
167
'
168
169
test_expect_success 'no diff with -diff' '
@@ -212,7 +209,12 @@ test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' '
209
touch file.ext &&
210
git add file.ext &&
211
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 &&
218
git update-index --force-remove file.ext &&
219
rm file.ext
220
'