Skip to content

Commit 4fdf71b

Browse files
Gary V. Vaughangitster
authored andcommitted
tests: use "test_cmp", not "diff", when verifying the result
In tests, call test_cmp rather than raw diff where possible (i.e. if the output does not go to a pipe), to allow the use of, say, 'cmp' when the default 'diff -u' is not compatible with a vendor diff. When that is not possible, use $DIFF, as set in GIT-BUILD-OPTIONS. Signed-off-by: Gary V. Vaughan <gary@thewrittenword.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d1b1a91 commit 4fdf71b

19 files changed

+59
-55
lines changed

t/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
-include ../config.mak
77

88
#GIT_TEST_OPTS=--verbose --debug
9+
GIT_TEST_CMP ?= $(DIFF)
910
SHELL_PATH ?= $(SHELL)
1011
TAR ?= $(TAR)
1112
RM ?= rm -f
1213

14+
# Make sure test-lib.sh uses make's value of GIT_TEST_CMP
15+
export GIT_TEST_CMP
16+
1317
# Shell quote;
1418
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
1519

t/t0000-basic.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ $expectfilter >expected <<\EOF
280280
EOF
281281
test_expect_success \
282282
'validate git diff-files output for a know cache/work tree state.' \
283-
'git diff-files >current && diff >/dev/null -b current expected'
283+
'git diff-files >current && test_cmp current expected >/dev/null'
284284

285285
test_expect_success \
286286
'git update-index --refresh should succeed.' \

t/t3200-branch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test_expect_success \
4343
git branch -l d/e/f &&
4444
test -f .git/refs/heads/d/e/f &&
4545
test -f .git/logs/refs/heads/d/e/f &&
46-
diff expect .git/logs/refs/heads/d/e/f'
46+
test_cmp expect .git/logs/refs/heads/d/e/f'
4747

4848
test_expect_success \
4949
'git branch -d d/e/f should delete a branch and a log' \
@@ -222,7 +222,7 @@ test_expect_success \
222222
git checkout -b g/h/i -l master &&
223223
test -f .git/refs/heads/g/h/i &&
224224
test -f .git/logs/refs/heads/g/h/i &&
225-
diff expect .git/logs/refs/heads/g/h/i'
225+
test_cmp expect .git/logs/refs/heads/g/h/i'
226226

227227
test_expect_success 'avoid ambiguous track' '
228228
git config branch.autosetupmerge true &&

t/t3210-pack-refs.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test_expect_success \
2828
SHA1=`cat .git/refs/heads/a` &&
2929
echo "$SHA1 refs/heads/a" >expect &&
3030
git show-ref a >result &&
31-
diff expect result'
31+
test_cmp expect result'
3232

3333
test_expect_success \
3434
'see if a branch still exists when packed' \
@@ -37,7 +37,7 @@ test_expect_success \
3737
rm -f .git/refs/heads/b &&
3838
echo "$SHA1 refs/heads/b" >expect &&
3939
git show-ref b >result &&
40-
diff expect result'
40+
test_cmp expect result'
4141

4242
test_expect_success 'git branch c/d should barf if branch c exists' '
4343
git branch c &&
@@ -52,7 +52,7 @@ test_expect_success \
5252
git pack-refs --all --prune &&
5353
echo "$SHA1 refs/heads/e" >expect &&
5454
git show-ref e >result &&
55-
diff expect result'
55+
test_cmp expect result'
5656

5757
test_expect_success 'see if git pack-refs --prune remove ref files' '
5858
git branch f &&
@@ -109,7 +109,7 @@ test_expect_success 'pack, prune and repack' '
109109
git show-ref >all-of-them &&
110110
git pack-refs &&
111111
git show-ref >again &&
112-
diff all-of-them again
112+
test_cmp all-of-them again
113113
'
114114

115115
test_done

t/t3903-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test_expect_success 'drop top stash' '
8181
git stash &&
8282
git stash drop &&
8383
git stash list > stashlist2 &&
84-
diff stashlist1 stashlist2 &&
84+
test_cmp stashlist1 stashlist2 &&
8585
git stash apply &&
8686
test 3 = $(cat file) &&
8787
test 1 = $(git show :file) &&

t/t4002-diff-basic.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ cmp_diff_files_output () {
135135
# filesystem.
136136
sed <"$2" >.test-tmp \
137137
-e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\) /'$z40'\1 /' &&
138-
diff "$1" .test-tmp
138+
test_cmp "$1" .test-tmp
139139
}
140140

141141
test_expect_success \

t/t4124-apply-ws-rule.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test_fix () {
4444
apply_patch --whitespace=fix || return 1
4545

4646
# find touched lines
47-
diff file target | sed -n -e "s/^> //p" >fixed
47+
$DIFF file target | sed -n -e "s/^> //p" >fixed
4848

4949
# the changed lines are all expeced to change
5050
fixed_cnt=$(wc -l <fixed)
@@ -85,14 +85,14 @@ test_expect_success setup '
8585
test_expect_success 'whitespace=nowarn, default rule' '
8686
8787
apply_patch --whitespace=nowarn &&
88-
diff file target
88+
test_cmp file target
8989
9090
'
9191

9292
test_expect_success 'whitespace=warn, default rule' '
9393
9494
apply_patch --whitespace=warn &&
95-
diff file target
95+
test_cmp file target
9696
9797
'
9898

@@ -108,7 +108,7 @@ test_expect_success 'whitespace=error-all, no rule' '
108108
109109
git config core.whitespace -trailing,-space-before,-indent &&
110110
apply_patch --whitespace=error-all &&
111-
diff file target
111+
test_cmp file target
112112
113113
'
114114

@@ -117,7 +117,7 @@ test_expect_success 'whitespace=error-all, no rule (attribute)' '
117117
git config --unset core.whitespace &&
118118
echo "target -whitespace" >.gitattributes &&
119119
apply_patch --whitespace=error-all &&
120-
diff file target
120+
test_cmp file target
121121
122122
'
123123

t/t4127-apply-same-fn.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_expect_success 'apply same filename with independent changes' '
2727
cp same_fn same_fn2 &&
2828
git reset --hard &&
2929
git apply patch0 &&
30-
diff same_fn same_fn2
30+
test_cmp same_fn same_fn2
3131
'
3232

3333
test_expect_success 'apply same filename with overlapping changes' '
@@ -40,7 +40,7 @@ test_expect_success 'apply same filename with overlapping changes' '
4040
cp same_fn same_fn2 &&
4141
git reset --hard &&
4242
git apply patch0 &&
43-
diff same_fn same_fn2
43+
test_cmp same_fn same_fn2
4444
'
4545

4646
test_expect_success 'apply same new filename after rename' '
@@ -54,7 +54,7 @@ test_expect_success 'apply same new filename after rename' '
5454
cp new_fn new_fn2 &&
5555
git reset --hard &&
5656
git apply --index patch1 &&
57-
diff new_fn new_fn2
57+
test_cmp new_fn new_fn2
5858
'
5959

6060
test_expect_success 'apply same old filename after rename -- should fail.' '

t/t5300-pack-object.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ test_expect_success \
147147
git cat-file $t $object || return 1
148148
done <obj-list
149149
} >current &&
150-
diff expect current'
150+
test_cmp expect current'
151151

152152
test_expect_success \
153153
'use packed deltified (REF_DELTA) objects' \
@@ -162,7 +162,7 @@ test_expect_success \
162162
git cat-file $t $object || return 1
163163
done <obj-list
164164
} >current &&
165-
diff expect current'
165+
test_cmp expect current'
166166

167167
test_expect_success \
168168
'use packed deltified (OFS_DELTA) objects' \
@@ -177,7 +177,7 @@ test_expect_success \
177177
git cat-file $t $object || return 1
178178
done <obj-list
179179
} >current &&
180-
diff expect current'
180+
test_cmp expect current'
181181

182182
unset GIT_OBJECT_DIRECTORY
183183

t/t5510-fetch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test_expect_success "fetch test for-merge" '
7171
echo "$one_in_two "
7272
} >expected &&
7373
cut -f -2 .git/FETCH_HEAD >actual &&
74-
diff expected actual'
74+
test_cmp expected actual'
7575

7676
test_expect_success 'fetch tags when there is no tags' '
7777

0 commit comments

Comments
 (0)