@matheusbsbs / matheus-bagliano / commits / 4fdf71be1c
Fork 0

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>

Gary V. Vaughan committed May 14, 2010 at 09:31 UTC 4fdf71be1ca3a817851a14f91b75e7d30f885a48
19 files changed +59 -55
t/Makefile
+4
@@ -6,10 +6,14 @@
6 -include ../config.mak
7
8 #GIT_TEST_OPTS=--verbose --debug
9 +GIT_TEST_CMP ?= $(DIFF)
10 SHELL_PATH ?= $(SHELL)
11 TAR ?= $(TAR)
12 RM ?= rm -f
13
14 +# Make sure test-lib.sh uses make's value of GIT_TEST_CMP
15 +export GIT_TEST_CMP
16 +
17 # Shell quote;
18 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
19
t/t0000-basic.sh
+1 -1
@@ -280,7 +280,7 @@ $expectfilter >expected <<\EOF
280 EOF
281 test_expect_success \
282 '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'
284
285 test_expect_success \
286 'git update-index --refresh should succeed.' \
t/t3200-branch.sh
+2 -2
@@ -43,7 +43,7 @@ test_expect_success \
43 git branch -l d/e/f &&
44 test -f .git/refs/heads/d/e/f &&
45 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'
47
48 test_expect_success \
49 'git branch -d d/e/f should delete a branch and a log' \
@@ -222,7 +222,7 @@ test_expect_success \
222 git checkout -b g/h/i -l master &&
223 test -f .git/refs/heads/g/h/i &&
224 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'
226
227 test_expect_success 'avoid ambiguous track' '
228 git config branch.autosetupmerge true &&
t/t3210-pack-refs.sh
+4 -4
@@ -28,7 +28,7 @@ test_expect_success \
28 SHA1=`cat .git/refs/heads/a` &&
29 echo "$SHA1 refs/heads/a" >expect &&
30 git show-ref a >result &&
31 - diff expect result'
31 + test_cmp expect result'
32
33 test_expect_success \
34 'see if a branch still exists when packed' \
@@ -37,7 +37,7 @@ test_expect_success \
37 rm -f .git/refs/heads/b &&
38 echo "$SHA1 refs/heads/b" >expect &&
39 git show-ref b >result &&
40 - diff expect result'
40 + test_cmp expect result'
41
42 test_expect_success 'git branch c/d should barf if branch c exists' '
43 git branch c &&
@@ -52,7 +52,7 @@ test_expect_success \
52 git pack-refs --all --prune &&
53 echo "$SHA1 refs/heads/e" >expect &&
54 git show-ref e >result &&
55 - diff expect result'
55 + test_cmp expect result'
56
57 test_expect_success 'see if git pack-refs --prune remove ref files' '
58 git branch f &&
@@ -109,7 +109,7 @@ test_expect_success 'pack, prune and repack' '
109 git show-ref >all-of-them &&
110 git pack-refs &&
111 git show-ref >again &&
112 - diff all-of-them again
112 + test_cmp all-of-them again
113 '
114
115 test_done
t/t3903-stash.sh
+1 -1
@@ -81,7 +81,7 @@ test_expect_success 'drop top stash' '
81 git stash &&
82 git stash drop &&
83 git stash list > stashlist2 &&
84 - diff stashlist1 stashlist2 &&
84 + test_cmp stashlist1 stashlist2 &&
85 git stash apply &&
86 test 3 = $(cat file) &&
87 test 1 = $(git show :file) &&
t/t4002-diff-basic.sh
+1 -1
@@ -135,7 +135,7 @@ cmp_diff_files_output () {
135 # filesystem.
136 sed <"$2" >.test-tmp \
137 -e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\) /'$z40'\1 /' &&
138 - diff "$1" .test-tmp
138 + test_cmp "$1" .test-tmp
139 }
140
141 test_expect_success \
t/t4124-apply-ws-rule.sh
+5 -5
@@ -44,7 +44,7 @@ test_fix () {
44 apply_patch --whitespace=fix || return 1
45
46 # find touched lines
47 - diff file target | sed -n -e "s/^> //p" >fixed
47 + $DIFF file target | sed -n -e "s/^> //p" >fixed
48
49 # the changed lines are all expeced to change
50 fixed_cnt=$(wc -l <fixed)
@@ -85,14 +85,14 @@ test_expect_success setup '
85 test_expect_success 'whitespace=nowarn, default rule' '
86
87 apply_patch --whitespace=nowarn &&
88 - diff file target
88 + test_cmp file target
89
90 '
91
92 test_expect_success 'whitespace=warn, default rule' '
93
94 apply_patch --whitespace=warn &&
95 - diff file target
95 + test_cmp file target
96
97 '
98
@@ -108,7 +108,7 @@ test_expect_success 'whitespace=error-all, no rule' '
108
109 git config core.whitespace -trailing,-space-before,-indent &&
110 apply_patch --whitespace=error-all &&
111 - diff file target
111 + test_cmp file target
112
113 '
114
@@ -117,7 +117,7 @@ test_expect_success 'whitespace=error-all, no rule (attribute)' '
117 git config --unset core.whitespace &&
118 echo "target -whitespace" >.gitattributes &&
119 apply_patch --whitespace=error-all &&
120 - diff file target
120 + test_cmp file target
121
122 '
123
t/t4127-apply-same-fn.sh
+3 -3
@@ -27,7 +27,7 @@ test_expect_success 'apply same filename with independent changes' '
27 cp same_fn same_fn2 &&
28 git reset --hard &&
29 git apply patch0 &&
30 - diff same_fn same_fn2
30 + test_cmp same_fn same_fn2
31 '
32
33 test_expect_success 'apply same filename with overlapping changes' '
@@ -40,7 +40,7 @@ test_expect_success 'apply same filename with overlapping changes' '
40 cp same_fn same_fn2 &&
41 git reset --hard &&
42 git apply patch0 &&
43 - diff same_fn same_fn2
43 + test_cmp same_fn same_fn2
44 '
45
46 test_expect_success 'apply same new filename after rename' '
@@ -54,7 +54,7 @@ test_expect_success 'apply same new filename after rename' '
54 cp new_fn new_fn2 &&
55 git reset --hard &&
56 git apply --index patch1 &&
57 - diff new_fn new_fn2
57 + test_cmp new_fn new_fn2
58 '
59
60 test_expect_success 'apply same old filename after rename -- should fail.' '
t/t5300-pack-object.sh
+3 -3
@@ -147,7 +147,7 @@ test_expect_success \
147 git cat-file $t $object || return 1
148 done <obj-list
149 } >current &&
150 - diff expect current'
150 + test_cmp expect current'
151
152 test_expect_success \
153 'use packed deltified (REF_DELTA) objects' \
@@ -162,7 +162,7 @@ test_expect_success \
162 git cat-file $t $object || return 1
163 done <obj-list
164 } >current &&
165 - diff expect current'
165 + test_cmp expect current'
166
167 test_expect_success \
168 'use packed deltified (OFS_DELTA) objects' \
@@ -177,7 +177,7 @@ test_expect_success \
177 git cat-file $t $object || return 1
178 done <obj-list
179 } >current &&
180 - diff expect current'
180 + test_cmp expect current'
181
182 unset GIT_OBJECT_DIRECTORY
183
t/t5510-fetch.sh
+1 -1
@@ -71,7 +71,7 @@ test_expect_success "fetch test for-merge" '
71 echo "$one_in_two "
72 } >expected &&
73 cut -f -2 .git/FETCH_HEAD >actual &&
74 - diff expected actual'
74 + test_cmp expected actual'
75
76 test_expect_success 'fetch tags when there is no tags' '
77
t/t5520-pull.sh
+1 -1
@@ -26,7 +26,7 @@ cd "$D"
26 test_expect_success 'checking the results' '
27 test -f file &&
28 test -f cloned/file &&
29 - diff file cloned/file
29 + test_cmp file cloned/file
30 '
31
32 test_expect_success 'pulling into void using master:master' '
t/t5700-clone-reference.sh
+4 -4
@@ -48,7 +48,7 @@ test_expect_success 'that reference gets used' \
48 'cd C &&
49 echo "0 objects, 0 kilobytes" > expected &&
50 git count-objects > current &&
51 -diff expected current'
51 +test_cmp expected current'
52
53 cd "$base_dir"
54
@@ -75,7 +75,7 @@ cd "$base_dir"
75 test_expect_success 'that reference gets used' \
76 'cd D && echo "0 objects, 0 kilobytes" > expected &&
77 git count-objects > current &&
78 -diff expected current'
78 +test_cmp expected current'
79
80 cd "$base_dir"
81
@@ -100,7 +100,7 @@ test_expect_success 'that alternate to origin gets used' \
100 'cd C &&
101 echo "2 objects" > expected &&
102 git count-objects | cut -d, -f1 > current &&
103 -diff expected current'
103 +test_cmp expected current'
104
105 cd "$base_dir"
106
@@ -116,7 +116,7 @@ test_expect_success 'check objects expected to exist locally' \
116 'cd D &&
117 echo "5 objects" > expected &&
118 git count-objects | cut -d, -f1 > current &&
119 -diff expected current'
119 +test_cmp expected current'
120
121 cd "$base_dir"
122
t/t6000lib.sh
+1 -1
@@ -91,7 +91,7 @@ check_output()
91 shift 1
92 if eval "$*" | entag > $_name.actual
93 then
94 - diff $_name.expected $_name.actual
94 + test_cmp $_name.expected $_name.actual
95 else
96 return 1;
97 fi
t/t6001-rev-list-graft.sh
+1 -1
@@ -84,7 +84,7 @@ check () {
84 git rev-list --parents --pretty=raw $arg |
85 sed -n -e 's/^commit //p' >test.actual
86 fi
87 - diff test.expect test.actual
87 + test_cmp test.expect test.actual
88 }
89
90 for type in basic parents parents-raw
t/t6022-merge-rename.sh
+2 -2
@@ -280,7 +280,7 @@ test_expect_success 'updated working tree file should prevent the merge' '
280 echo "BAD: should have complained"
281 return 1
282 }
283 - diff M M.saved || {
283 + test_cmp M M.saved || {
284 echo "BAD: should have left M intact"
285 return 1
286 }
@@ -301,7 +301,7 @@ test_expect_success 'updated working tree file should prevent the merge' '
301 echo "BAD: should have complained"
302 return 1
303 }
304 - diff M M.saved || {
304 + test_cmp M M.saved || {
305 echo "BAD: should have left M intact"
306 return 1
307 }
t/t7002-grep.sh
+8 -8
@@ -60,7 +60,7 @@ do
60 echo ${HC}file:5:foo_mmap bar mmap baz
61 } >expected &&
62 git grep -n -w -e mmap $H >actual &&
63 - diff expected actual
63 + test_cmp expected actual
64 '
65
66 test_expect_success "grep -w $L (w)" '
@@ -74,7 +74,7 @@ do
74 echo ${HC}x:1:x x xx x
75 } >expected &&
76 git grep -n -w -e "x xx* x" $H >actual &&
77 - diff expected actual
77 + test_cmp expected actual
78 '
79
80 test_expect_success "grep -w $L (y-1)" '
@@ -82,7 +82,7 @@ do
82 echo ${HC}y:1:y yy
83 } >expected &&
84 git grep -n -w -e "^y" $H >actual &&
85 - diff expected actual
85 + test_cmp expected actual
86 '
87
88 test_expect_success "grep -w $L (y-2)" '
@@ -93,7 +93,7 @@ do
93 cat actual
94 false
95 else
96 - diff expected actual
96 + test_cmp expected actual
97 fi
98 '
99
@@ -105,14 +105,14 @@ do
105 cat actual
106 false
107 else
108 - diff expected actual
108 + test_cmp expected actual
109 fi
110 '
111
112 test_expect_success "grep $L (t-1)" '
113 echo "${HC}t/t:1:test" >expected &&
114 git grep -n -e test $H >actual &&
115 - diff expected actual
115 + test_cmp expected actual
116 '
117
118 test_expect_success "grep $L (t-2)" '
@@ -121,7 +121,7 @@ do
121 cd t &&
122 git grep -n -e test $H
123 ) >actual &&
124 - diff expected actual
124 + test_cmp expected actual
125 '
126
127 test_expect_success "grep $L (t-3)" '
@@ -130,7 +130,7 @@ do
130 cd t &&
131 git grep --full-name -n -e test $H
132 ) >actual &&
133 - diff expected actual
133 + test_cmp expected actual
134 '
135
136 test_expect_success "grep -c $L (no /dev/null)" '
t/t7005-editor.sh
+3 -3
@@ -38,7 +38,7 @@ test_expect_success setup '
38 test_commit "$msg" &&
39 echo "$msg" >expect &&
40 git show -s --format=%s > actual &&
41 - diff actual expect
41 + test_cmp actual expect
42
43 '
44
@@ -85,7 +85,7 @@ do
85 git --exec-path=. commit --amend &&
86 git show -s --pretty=oneline |
87 sed -e "s/^[0-9a-f]* //" >actual &&
88 - diff actual expect
88 + test_cmp actual expect
89 '
90 done
91
@@ -107,7 +107,7 @@ do
107 git --exec-path=. commit --amend &&
108 git show -s --pretty=oneline |
109 sed -e "s/^[0-9a-f]* //" >actual &&
110 - diff actual expect
110 + test_cmp actual expect
111 '
112 done
113
t/t9200-git-cvsexportcommit.sh
+13 -13
@@ -63,10 +63,10 @@ test_expect_success \
63 check_entries B "newfile2.txt/1.1/" &&
64 check_entries C "newfile3.png/1.1/-kb" &&
65 check_entries D "newfile4.png/1.1/-kb" &&
66 - diff A/newfile1.txt ../A/newfile1.txt &&
67 - diff B/newfile2.txt ../B/newfile2.txt &&
68 - diff C/newfile3.png ../C/newfile3.png &&
69 - diff D/newfile4.png ../D/newfile4.png
66 + test_cmp A/newfile1.txt ../A/newfile1.txt &&
67 + test_cmp B/newfile2.txt ../B/newfile2.txt &&
68 + test_cmp C/newfile3.png ../C/newfile3.png &&
69 + test_cmp D/newfile4.png ../D/newfile4.png
70 )'
71
72 test_expect_success \
@@ -89,10 +89,10 @@ test_expect_success \
89 check_entries D "newfile4.png/1.2/-kb" &&
90 check_entries E "newfile5.txt/1.1/" &&
91 check_entries F "newfile6.png/1.1/-kb" &&
92 - diff A/newfile1.txt ../A/newfile1.txt &&
93 - diff D/newfile4.png ../D/newfile4.png &&
94 - diff E/newfile5.txt ../E/newfile5.txt &&
95 - diff F/newfile6.png ../F/newfile6.png
92 + test_cmp A/newfile1.txt ../A/newfile1.txt &&
93 + test_cmp D/newfile4.png ../D/newfile4.png &&
94 + test_cmp E/newfile5.txt ../E/newfile5.txt &&
95 + test_cmp F/newfile6.png ../F/newfile6.png
96 )'
97
98 # Should fail (but only on the git cvsexportcommit stage)
@@ -137,9 +137,9 @@ test_expect_success \
137 check_entries D "" &&
138 check_entries E "newfile5.txt/1.1/" &&
139 check_entries F "newfile6.png/1.1/-kb" &&
140 - diff A/newfile1.txt ../A/newfile1.txt &&
141 - diff E/newfile5.txt ../E/newfile5.txt &&
142 - diff F/newfile6.png ../F/newfile6.png
140 + test_cmp A/newfile1.txt ../A/newfile1.txt &&
141 + test_cmp E/newfile5.txt ../E/newfile5.txt &&
142 + test_cmp F/newfile6.png ../F/newfile6.png
143 )'
144
145 test_expect_success \
@@ -155,8 +155,8 @@ test_expect_success \
155 check_entries D "" &&
156 check_entries E "newfile5.txt/1.1/" &&
157 check_entries F "newfile6.png/1.1/-kb" &&
158 - diff E/newfile5.txt ../E/newfile5.txt &&
159 - diff F/newfile6.png ../F/newfile6.png
158 + test_cmp E/newfile5.txt ../E/newfile5.txt &&
159 + test_cmp F/newfile6.png ../F/newfile6.png
160 )'
161
162 test_expect_success \
t/t9400-git-cvsserver-server.sh
+1 -1
@@ -435,7 +435,7 @@ test_expect_success 'cvs update (-p)' '
435 rm -f failures &&
436 for i in merge no-lf empty really-empty; do
437 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
438 - diff $i.out ../$i >>failures 2>&1
438 + test_cmp $i.out ../$i >>failures 2>&1
439 done &&
440 test -z "$(cat failures)"
441 '