Git fork

add test_cmp function for test scripts

Many scripts compare actual and expected output using
"diff -u". This is nicer than "cmp" because the output shows
how the two differ. However, not all versions of diff
understand -u, leading to unnecessary test failure.

This adds a test_cmp function to the test scripts and
switches all "diff -u" invocations to use it. The function
uses the contents of "$GIT_TEST_CMP" to compare its
arguments; the default is "diff -u".

On systems with a less-capable diff, you can do:

GIT_TEST_CMP=cmp make test

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Jeff King and committed by
Junio C Hamano
82ebb0b6 b4ce54fc

+133 -115
+1 -1
t/t0003-attributes.sh
··· 11 11 12 12 git check-attr test -- "$path" >actual && 13 13 echo "$path: test: $2" >expect && 14 - diff -u expect actual 14 + test_cmp expect actual 15 15 16 16 } 17 17
+1 -1
t/t0022-crlf-rename.sh
··· 26 26 git diff-tree -M -r --name-status HEAD^ HEAD | 27 27 sed -e "s/R[0-9]*/RNUM/" >actual && 28 28 echo "RNUM sample elpmas" >expect && 29 - diff -u expect actual 29 + test_cmp expect actual 30 30 31 31 ' 32 32
+1 -1
t/t1005-read-tree-reset.sh
··· 24 24 test_expect_success 'reset should work' ' 25 25 git read-tree -u --reset HEAD^ && 26 26 git ls-files >actual && 27 - diff -u expect actual 27 + test_cmp expect actual 28 28 ' 29 29 30 30 test_done
+1 -1
t/t2200-add-update.sh
··· 62 62 sed -e "s/ 0 / /" >expect && 63 63 git ls-tree -r $(git write-tree) | 64 64 sed -e "s/ blob / /" >current && 65 - diff -u expect current 65 + test_cmp expect current 66 66 67 67 ' 68 68
+1 -1
t/t3001-ls-files-others-exclude.sh
··· 97 97 EOF 98 98 99 99 test_expect_success 'git-status honours core.excludesfile' \ 100 - 'diff -u expect output' 100 + 'test_cmp expect output' 101 101 102 102 test_expect_success 'trailing slash in exclude allows directory match(1)' ' 103 103
+2 -2
t/t3050-subprojects-fetch.sh
··· 26 26 cd cloned && 27 27 (git rev-parse HEAD; git ls-files -s) >../actual 28 28 ) && 29 - diff -u expected actual 29 + test_cmp expected actual 30 30 ' 31 31 32 32 test_expect_success advance ' ··· 46 46 git pull && 47 47 (git rev-parse HEAD; git ls-files -s) >../actual 48 48 ) && 49 - diff -u expected actual 49 + test_cmp expected actual 50 50 ' 51 51 52 52 test_done
+1 -1
t/t3060-ls-files-with-tree.sh
··· 66 66 cd .. 67 67 test_expect_success \ 68 68 'git -ls-files --with-tree should add entries from named tree.' \ 69 - 'diff -u expected output' 69 + 'test_cmp expected output' 70 70 71 71 test_done
+3 -3
t/t3201-branch-contains.sh
··· 31 31 { 32 32 echo " master" && echo "* side" 33 33 } >expect && 34 - diff -u expect actual 34 + test_cmp expect actual 35 35 36 36 ' 37 37 ··· 41 41 { 42 42 echo " master" && echo "* side" 43 43 } >expect && 44 - diff -u expect actual 44 + test_cmp expect actual 45 45 46 46 ' 47 47 ··· 51 51 { 52 52 echo "* side" 53 53 } >expect && 54 - diff -u expect actual 54 + test_cmp expect actual 55 55 56 56 ' 57 57
+2 -2
t/t3404-rebase-interactive.sh
··· 146 146 test_expect_success 'stop on conflicting pick' ' 147 147 git tag new-branch1 && 148 148 ! git rebase -i master && 149 - diff -u expect .git/.dotest-merge/patch && 150 - diff -u expect2 file1 && 149 + test_cmp expect .git/.dotest-merge/patch && 150 + test_cmp expect2 file1 && 151 151 test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) && 152 152 test 0 = $(grep -c "^[^#]" < .git/.dotest-merge/git-rebase-todo) 153 153 '
+2 -2
t/t3405-rebase-malformed.sh
··· 41 41 git rebase master side && 42 42 git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 && 43 43 44 - diff -u F0 F1 && 45 - diff -u F F0 44 + test_cmp F0 F1 && 45 + test_cmp F F0 46 46 ' 47 47 48 48 test_done
+1 -1
t/t3406-rebase-message.sh
··· 37 37 git rebase -m master >report && 38 38 sed -n -e "/^Already applied: /p" \ 39 39 -e "/^Committed: /p" report >actual && 40 - diff -u expect actual 40 + test_cmp expect actual 41 41 42 42 ' 43 43
+2 -2
t/t3701-add-interactive.sh
··· 24 24 test_expect_success 'diff works (initial)' ' 25 25 (echo d; echo 1) | git add -i >output && 26 26 sed -ne "/new file/,/content/p" <output >diff && 27 - diff -u expected diff 27 + test_cmp expected diff 28 28 ' 29 29 test_expect_success 'revert works (initial)' ' 30 30 git add file && ··· 57 57 test_expect_success 'diff works (commit)' ' 58 58 (echo d; echo 1) | git add -i >output && 59 59 sed -ne "/^index/,/content/p" <output >diff && 60 - diff -u expected diff 60 + test_cmp expected diff 61 61 ' 62 62 test_expect_success 'revert works (commit)' ' 63 63 git add file &&
+8 -8
t/t3902-quoted.sh
··· 78 78 79 79 test_expect_success 'check fully quoted output from ls-files' ' 80 80 81 - git ls-files >current && diff -u expect.quoted current 81 + git ls-files >current && test_cmp expect.quoted current 82 82 83 83 ' 84 84 85 85 test_expect_success 'check fully quoted output from diff-files' ' 86 86 87 87 git diff --name-only >current && 88 - diff -u expect.quoted current 88 + test_cmp expect.quoted current 89 89 90 90 ' 91 91 92 92 test_expect_success 'check fully quoted output from diff-index' ' 93 93 94 94 git diff --name-only HEAD >current && 95 - diff -u expect.quoted current 95 + test_cmp expect.quoted current 96 96 97 97 ' 98 98 99 99 test_expect_success 'check fully quoted output from diff-tree' ' 100 100 101 101 git diff --name-only HEAD^ HEAD >current && 102 - diff -u expect.quoted current 102 + test_cmp expect.quoted current 103 103 104 104 ' 105 105 ··· 111 111 112 112 test_expect_success 'check fully quoted output from ls-files' ' 113 113 114 - git ls-files >current && diff -u expect.raw current 114 + git ls-files >current && test_cmp expect.raw current 115 115 116 116 ' 117 117 118 118 test_expect_success 'check fully quoted output from diff-files' ' 119 119 120 120 git diff --name-only >current && 121 - diff -u expect.raw current 121 + test_cmp expect.raw current 122 122 123 123 ' 124 124 125 125 test_expect_success 'check fully quoted output from diff-index' ' 126 126 127 127 git diff --name-only HEAD >current && 128 - diff -u expect.raw current 128 + test_cmp expect.raw current 129 129 130 130 ' 131 131 132 132 test_expect_success 'check fully quoted output from diff-tree' ' 133 133 134 134 git diff --name-only HEAD^ HEAD >current && 135 - diff -u expect.raw current 135 + test_cmp expect.raw current 136 136 137 137 ' 138 138
+1 -1
t/t3903-stash.sh
··· 34 34 test_expect_success 'parents of stash' ' 35 35 test $(git rev-parse stash^) = $(git rev-parse HEAD) && 36 36 git diff stash^2..stash > output && 37 - diff -u output expect 37 + test_cmp output expect 38 38 ' 39 39 40 40 test_expect_success 'apply needs clean working directory' '
+3 -3
t/t4023-diff-rename-typechange.sh
··· 57 57 echo "R100 foo bar" 58 58 echo "R100 bar foo" 59 59 } | sort >expect && 60 - diff -u expect actual 60 + test_cmp expect actual 61 61 62 62 ' 63 63 ··· 68 68 echo "R100 foo bar" 69 69 echo "R100 bar foo" 70 70 } | sort >expect && 71 - diff -u expect actual 71 + test_cmp expect actual 72 72 73 73 ' 74 74 ··· 79 79 echo "R100 foo bar" 80 80 echo "T100 foo" 81 81 } | sort >expect && 82 - diff -u expect actual 82 + test_cmp expect actual 83 83 84 84 ' 85 85
+1 -1
t/t4024-diff-optimize-common.sh
··· 150 150 do 151 151 git diff -U0 file-?$n 152 152 done | zc >actual && 153 - diff -u expect actual 153 + test_cmp expect actual 154 154 155 155 ' 156 156
+1 -1
t/t4025-hunk-header.sh
··· 37 37 echo " A $N$N$N$N$N$N$N$N$N2" 38 38 echo " L $N$N$N$N$N$N$N$N$N1" 39 39 ) >expected && 40 - diff -u actual expected 40 + test_cmp actual expected 41 41 42 42 ' 43 43
+3 -3
t/t4027-diff-submodule.sh
··· 37 37 38 38 test_expect_success 'git diff --raw HEAD' ' 39 39 git diff --raw --abbrev=40 HEAD >actual && 40 - diff -u expect actual 40 + test_cmp expect actual 41 41 ' 42 42 43 43 test_expect_success 'git diff-index --raw HEAD' ' 44 44 git diff-index --raw HEAD >actual.index && 45 - diff -u expect actual.index 45 + test_cmp expect actual.index 46 46 ' 47 47 48 48 test_expect_success 'git diff-files --raw' ' 49 49 git diff-files --raw >actual.files && 50 - diff -u expect actual.files 50 + test_cmp expect actual.files 51 51 ' 52 52 53 53 test_done
+1 -1
t/t4105-apply-fuzz.sh
··· 9 9 test_expect_success "$name" " 10 10 git checkout-index -f -q -u file && 11 11 git apply $* && 12 - diff -u expect file 12 + test_cmp expect file 13 13 " 14 14 } 15 15
+4 -4
t/t4125-apply-ws-fuzz.sh
··· 56 56 git apply --whitespace=nowarn patch-1 && 57 57 58 58 # The result should obviously match. 59 - diff -u file-1 file 59 + test_cmp file-1 file 60 60 ' 61 61 62 62 test_expect_success 'withfix (forward)' ' ··· 70 70 git apply --whitespace=fix patch-0 && 71 71 git apply --whitespace=fix patch-1 && 72 72 73 - diff -u file-fixed file 73 + test_cmp file-fixed file 74 74 ' 75 75 76 76 test_expect_success 'withfix (backward)' ' ··· 91 91 92 92 sed -e /h/d file-fixed >fixed-head && 93 93 sed -e /h/d file >file-head && 94 - diff -u fixed-head file-head && 94 + test_cmp fixed-head file-head && 95 95 96 96 sed -n -e /h/p file-fixed >fixed-tail && 97 97 sed -n -e /h/p file >file-tail && 98 98 99 - ! diff -u fixed-tail file-tail 99 + ! test_cmp fixed-tail file-tail 100 100 101 101 ' 102 102
+5 -5
t/t4150-am-subdir.sh
··· 22 22 git checkout initial && 23 23 git am <patchfile && 24 24 git diff master >actual && 25 - diff -u expect actual 25 + test_cmp expect actual 26 26 ' 27 27 28 28 test_expect_success 'am regularly from file' ' 29 29 git checkout initial && 30 30 git am patchfile && 31 31 git diff master >actual && 32 - diff -u expect actual 32 + test_cmp expect actual 33 33 ' 34 34 35 35 test_expect_success 'am regularly from stdin in subdirectory' ' ··· 41 41 git am <../patchfile 42 42 ) && 43 43 git diff master>actual && 44 - diff -u expect actual 44 + test_cmp expect actual 45 45 ' 46 46 47 47 test_expect_success 'am regularly from file in subdirectory' ' ··· 53 53 git am ../patchfile 54 54 ) && 55 55 git diff master >actual && 56 - diff -u expect actual 56 + test_cmp expect actual 57 57 ' 58 58 59 59 test_expect_success 'am regularly from file in subdirectory with full path' ' ··· 66 66 git am "$P/patchfile" 67 67 ) && 68 68 git diff master >actual && 69 - diff -u expect actual 69 + test_cmp expect actual 70 70 ' 71 71 72 72 test_done
+1 -1
t/t4201-shortlog.sh
··· 45 45 46 46 EOF 47 47 48 - test_expect_success 'shortlog wrapping' 'diff -u expect out' 48 + test_expect_success 'shortlog wrapping' 'test_cmp expect out' 49 49 50 50 test_done
+3 -3
t/t5505-remote.sh
··· 24 24 tokens_match () { 25 25 echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && 26 26 echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && 27 - diff -u expect actual 27 + test_cmp expect actual 28 28 } 29 29 30 30 check_remote_track () { ··· 73 73 sed -e "/^refs\/remotes\/origin\//d" \ 74 74 -e "/^refs\/remotes\/second\//d" >actual && 75 75 >expect && 76 - diff -u expect actual 76 + test_cmp expect actual 77 77 ) 78 78 ' 79 79 ··· 93 93 git for-each-ref "--format=%(refname)" refs/remotes | 94 94 sed -e "/^refs\/remotes\/origin\//d" >actual && 95 95 >expect && 96 - diff -u expect actual 96 + test_cmp expect actual 97 97 ) 98 98 ' 99 99
+1 -1
t/t5510-fetch.sh
··· 249 249 do 250 250 echo "$(git rev-parse --verify $h) $h" 251 251 done >expect && 252 - diff -u expect actual 252 + test_cmp expect actual 253 253 254 254 ' 255 255
+4 -4
t/t5512-ls-remote.sh
··· 24 24 test_expect_success 'ls-remote --tags .git' ' 25 25 26 26 git ls-remote --tags .git >actual && 27 - diff -u expected.tag actual 27 + test_cmp expected.tag actual 28 28 29 29 ' 30 30 31 31 test_expect_success 'ls-remote .git' ' 32 32 33 33 git ls-remote .git >actual && 34 - diff -u expected.all actual 34 + test_cmp expected.all actual 35 35 36 36 ' 37 37 38 38 test_expect_success 'ls-remote --tags self' ' 39 39 40 40 git ls-remote --tags self >actual && 41 - diff -u expected.tag actual 41 + test_cmp expected.tag actual 42 42 43 43 ' 44 44 45 45 test_expect_success 'ls-remote self' ' 46 46 47 47 git ls-remote self >actual && 48 - diff -u expected.all actual 48 + test_cmp expected.all actual 49 49 50 50 ' 51 51
+1 -1
t/t6004-rev-list-path-optim.sh
··· 45 45 test_expect_success 'path optimization 2' ' 46 46 ( echo "$side"; echo "$initial" ) >expected && 47 47 git rev-list HEAD -- a >actual && 48 - diff -u expected actual 48 + test_cmp expected actual 49 49 ' 50 50 51 51 test_done
+1 -1
t/t6009-rev-list-parent.sh
··· 31 31 32 32 git rev-list one --not four >result && 33 33 >expect && 34 - diff -u expect result 34 + test_cmp expect result 35 35 36 36 ' 37 37
+2 -2
t/t6027-merge-binary.sh
··· 45 45 false 46 46 else 47 47 git ls-files -s >current 48 - diff -u current expect 48 + test_cmp current expect 49 49 fi 50 50 ' 51 51 ··· 60 60 false 61 61 else 62 62 git ls-files -s >current 63 - diff -u current expect 63 + test_cmp current expect 64 64 fi 65 65 ' 66 66
+1 -1
t/t6029-merge-subtree.sh
··· 25 25 26 26 git merge -s subtree side && 27 27 for i in mundo $s world; do echo $i; done >expect && 28 - diff -u expect hello 28 + test_cmp expect hello 29 29 30 30 ' 31 31
+9 -9
t/t7010-setup.sh
··· 18 18 git add "$D/a/b/c/d" && 19 19 git ls-files >current && 20 20 echo a/b/c/d >expect && 21 - diff -u expect current 21 + test_cmp expect current 22 22 23 23 ' 24 24 ··· 32 32 ) && 33 33 git ls-files >current && 34 34 echo a/e/f >expect && 35 - diff -u expect current 35 + test_cmp expect current 36 36 37 37 ' 38 38 ··· 43 43 git rm -f --cached "$D/a/b/c/d" && 44 44 git ls-files >current && 45 45 echo a/e/f >expect && 46 - diff -u expect current 46 + test_cmp expect current 47 47 48 48 ' 49 49 ··· 57 57 ) && 58 58 git ls-files >current && 59 59 echo a/b/c/d >expect && 60 - diff -u expect current 60 + test_cmp expect current 61 61 62 62 ' 63 63 ··· 67 67 git add a && 68 68 git ls-files "$D/a/e/../b" >current && 69 69 echo a/b/c/d >expect && 70 - diff -u expect current 70 + test_cmp expect current 71 71 72 72 ' 73 73 ··· 80 80 git ls-files "../b/c" 81 81 ) >current && 82 82 echo c/d >expect && 83 - diff -u expect current 83 + test_cmp expect current 84 84 85 85 ' 86 86 ··· 93 93 git ls-files --full-name "../e/f" 94 94 ) >current && 95 95 echo a/e/f >expect && 96 - diff -u expect current 96 + test_cmp expect current 97 97 98 98 ' 99 99 ··· 126 126 127 127 git log a/b/c/d >f1.txt && 128 128 git log "$(pwd)/a/b/c/d" >f2.txt && 129 - diff -u f1.txt f2.txt 129 + test_cmp f1.txt f2.txt 130 130 ' 131 131 132 132 test_expect_success 'blame using absolute path names' ' 133 133 git blame a/b/c/d >f1.txt && 134 134 git blame "$(pwd)/a/b/c/d" >f2.txt && 135 - diff -u f1.txt f2.txt 135 + test_cmp f1.txt f2.txt 136 136 ' 137 137 138 138 test_expect_success 'setup deeper work tree' '
+9 -9
t/t7201-co.sh
··· 83 83 fill 0 1 2 3 4 5 6 7 8 >same && 84 84 cp same kept 85 85 git checkout side >messages && 86 - diff -u same kept 86 + test_cmp same kept 87 87 (cat > messages.expect <<EOF 88 88 M same 89 89 EOF 90 90 ) && 91 91 touch messages.expect && 92 - diff -u messages.expect messages 92 + test_cmp messages.expect messages 93 93 ' 94 94 95 95 test_expect_success "checkout -m with dirty tree" ' ··· 106 106 M one 107 107 EOF 108 108 ) && 109 - diff -u expect.messages messages && 109 + test_cmp expect.messages messages && 110 110 111 111 fill "M one" "A three" "D two" >expect.master && 112 112 git diff --name-status master >current.master && 113 - diff -u expect.master current.master && 113 + test_cmp expect.master current.master && 114 114 115 115 fill "M one" >expect.side && 116 116 git diff --name-status side >current.side && 117 - diff -u expect.side current.side && 117 + test_cmp expect.side current.side && 118 118 119 119 : >expect.index && 120 120 git diff --cached >current.index && 121 - diff -u expect.index current.index 121 + test_cmp expect.index current.index 122 122 ' 123 123 124 124 test_expect_success "checkout -m with dirty tree, renamed" ' ··· 136 136 137 137 git checkout -m renamer && 138 138 fill 1 3 4 5 7 8 >expect && 139 - diff -u expect uno && 139 + test_cmp expect uno && 140 140 ! test -f one && 141 141 git diff --cached >current && 142 142 ! test -s current ··· 161 161 git diff master:one :3:uno | 162 162 sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current && 163 163 fill d2 aT d7 aS >expect && 164 - diff -u current expect && 164 + test_cmp current expect && 165 165 git diff --cached two >current && 166 166 ! test -s current 167 167 ' ··· 178 178 HEAD is now at 7329388... Initial A one, A two 179 179 EOF 180 180 ) && 181 - diff -u messages.expect messages && 181 + test_cmp messages.expect messages && 182 182 H=$(git rev-parse --verify HEAD) && 183 183 M=$(git show-ref -s --verify refs/heads/master) && 184 184 test "z$H" = "z$M" &&
+7 -7
t/t7501-commit.sh
··· 203 203 git var GIT_COMMITTER_IDENT | 204 204 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" 205 205 ) >expected && 206 - diff -u expected actual 206 + test_cmp expected actual 207 207 208 208 ' 209 209 ··· 223 223 git var GIT_COMMITTER_IDENT | 224 224 sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" 225 225 ) >expected && 226 - diff -u expected actual 226 + test_cmp expected actual 227 227 228 228 ' 229 229 ··· 240 240 echo 241 241 echo three 242 242 ) >expected && 243 - diff -u expected actual 243 + test_cmp expected actual 244 244 245 245 ' 246 246 ··· 301 301 git merge -s ours side -m "empty ok" && 302 302 git diff HEAD^ HEAD >actual && 303 303 : >expected && 304 - diff -u expected actual && 304 + test_cmp expected actual && 305 305 306 306 git commit --amend -m "empty really ok" && 307 307 git diff HEAD^ HEAD >actual && 308 308 : >expected && 309 - diff -u expected actual 309 + test_cmp expected actual 310 310 311 311 ' 312 312 ··· 323 323 git commit --allow-empty --amend -C "$old" && 324 324 git show --pretty="format:%ad %s" "$old" >expected && 325 325 git show --pretty="format:%ad %s" HEAD >actual && 326 - diff -u expected actual 326 + test_cmp expected actual 327 327 328 328 ' 329 329 ··· 341 341 git commit --allow-empty --amend -C tagged-old && 342 342 git show --pretty="format:%ad %s" "$old" >expected && 343 343 git show --pretty="format:%ad %s" HEAD >actual && 344 - diff -u expected actual 344 + test_cmp expected actual 345 345 346 346 ' 347 347
+7 -7
t/t7502-commit.sh
··· 85 85 git add negative && 86 86 git status -v | sed -ne "/^diff --git /p" >actual && 87 87 echo "diff --git a/negative b/negative" >expect && 88 - diff -u expect actual 88 + test_cmp expect actual 89 89 90 90 ' 91 91 ··· 95 95 { echo;echo "# text";echo; } >expect && 96 96 git commit --cleanup=verbatim -t expect -a && 97 97 git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual && 98 - diff -u expect actual 98 + test_cmp expect actual 99 99 100 100 ' 101 101 ··· 104 104 echo >>negative && 105 105 git commit --cleanup=verbatim -F expect -a && 106 106 git cat-file -p HEAD |sed -e "1,/^\$/d">actual && 107 - diff -u expect actual 107 + test_cmp expect actual 108 108 109 109 ' 110 110 ··· 113 113 echo >>negative && 114 114 git commit --cleanup=verbatim -m "$(cat expect)" -a && 115 115 git cat-file -p HEAD |sed -e "1,/^\$/d">actual && 116 - diff -u expect actual 116 + test_cmp expect actual 117 117 118 118 ' 119 119 ··· 124 124 echo "# text" >expect && 125 125 git commit --cleanup=whitespace -F text -a && 126 126 git cat-file -p HEAD |sed -e "1,/^\$/d">actual && 127 - diff -u expect actual 127 + test_cmp expect actual 128 128 129 129 ' 130 130 ··· 135 135 echo sample >expect && 136 136 git commit --cleanup=strip -F text -a && 137 137 git cat-file -p HEAD |sed -e "1,/^\$/d">actual && 138 - diff -u expect actual 138 + test_cmp expect actual 139 139 140 140 ' 141 141 ··· 150 150 { echo;echo sample;echo; } >text && 151 151 git commit -e -F text -a && 152 152 head -n 4 .git/COMMIT_EDITMSG >actual && 153 - diff -u expect actual 153 + test_cmp expect actual 154 154 155 155 ' 156 156
+1 -1
t/t7502-status.sh
··· 146 146 EOF 147 147 test_expect_success 'status of partial commit excluding new file in index' ' 148 148 git status dir1/modified >output && 149 - diff -u expect output 149 + test_cmp expect output 150 150 ' 151 151 152 152 test_done
+1 -1
t/t7600-merge.sh
··· 108 108 } 109 109 110 110 verify_diff() { 111 - if ! diff -u "$1" "$2" 111 + if ! test_cmp "$1" "$2" 112 112 then 113 113 echo "$3" 114 114 false
+2 -2
t/t8003-blame.sh
··· 112 112 echo mouse-Second 113 113 echo mouse-Third 114 114 } >expected && 115 - diff -u expected current 115 + test_cmp expected current 116 116 117 117 ' 118 118 ··· 125 125 echo cow-Fifth 126 126 echo mouse-Third 127 127 } >expected && 128 - diff -u expected current 128 + test_cmp expected current 129 129 130 130 ' 131 131
+1 -1
t/t9001-send-email.sh
··· 81 81 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ 82 82 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ 83 83 >actual-show-all-headers && 84 - diff -u expected-show-all-headers actual-show-all-headers 84 + test_cmp expected-show-all-headers actual-show-all-headers 85 85 ' 86 86 87 87 z8=zzzzzzzz
+12 -12
t/t9116-git-svn-log.sh
··· 55 55 56 56 test_expect_success 'test ascending revision range' " 57 57 git reset --hard trunk && 58 - git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2-r4 - 58 + git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 - 59 59 " 60 60 61 61 printf 'r4 \nr2 \nr1 \n' > expected-range-r4-r2-r1 62 62 63 63 test_expect_success 'test descending revision range' " 64 64 git reset --hard trunk && 65 - git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4-r2-r1 - 65 + git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4-r2-r1 - 66 66 " 67 67 68 68 printf 'r1 \nr2 \n' > expected-range-r1-r2 69 69 70 70 test_expect_success 'test ascending revision range with unreachable revision' " 71 71 git reset --hard trunk && 72 - git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2 - 72 + git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2 - 73 73 " 74 74 75 75 printf 'r2 \nr1 \n' > expected-range-r2-r1 76 76 77 77 test_expect_success 'test descending revision range with unreachable revision' " 78 78 git reset --hard trunk && 79 - git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2-r1 - 79 + git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2-r1 - 80 80 " 81 81 82 82 printf 'r2 \n' > expected-range-r2 83 83 84 84 test_expect_success 'test ascending revision range with unreachable upper boundary revision and 1 commit' " 85 85 git reset --hard trunk && 86 - git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 - 86 + git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 - 87 87 " 88 88 89 89 test_expect_success 'test descending revision range with unreachable upper boundary revision and 1 commit' " 90 90 git reset --hard trunk && 91 - git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 - 91 + git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 - 92 92 " 93 93 94 94 printf 'r4 \n' > expected-range-r4 95 95 96 96 test_expect_success 'test ascending revision range with unreachable lower boundary revision and 1 commit' " 97 97 git reset --hard trunk && 98 - git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - 98 + git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - 99 99 " 100 100 101 101 test_expect_success 'test descending revision range with unreachable lower boundary revision and 1 commit' " 102 102 git reset --hard trunk && 103 - git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - 103 + git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - 104 104 " 105 105 106 106 printf -- '------------------------------------------------------------------------\n' > expected-separator 107 107 108 108 test_expect_success 'test ascending revision range with unreachable boundary revisions and no commits' " 109 109 git reset --hard trunk && 110 - git svn log -r 5:6 | diff -u expected-separator - 110 + git svn log -r 5:6 | test_cmp expected-separator - 111 111 " 112 112 113 113 test_expect_success 'test descending revision range with unreachable boundary revisions and no commits' " 114 114 git reset --hard trunk && 115 - git svn log -r 6:5 | diff -u expected-separator - 115 + git svn log -r 6:5 | test_cmp expected-separator - 116 116 " 117 117 118 118 test_expect_success 'test ascending revision range with unreachable boundary revisions and 1 commit' " 119 119 git reset --hard trunk && 120 - git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - 120 + git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - 121 121 " 122 122 123 123 test_expect_success 'test descending revision range with unreachable boundary revisions and 1 commit' " 124 124 git reset --hard trunk && 125 - git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - 125 + git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - 126 126 " 127 127 128 128 test_done
+7 -7
t/t9200-git-cvsexportcommit.sh
··· 37 37 else 38 38 printf '%s\n' "$2" | tr '|' '\012' >expected 39 39 fi 40 - diff -u expected actual 40 + test_cmp expected actual 41 41 } 42 42 43 43 test_expect_success \ ··· 257 257 (cd "$GIT_DIR" && 258 258 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id && 259 259 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" && 260 - diff -u "$CVSWORK/W/file1.txt" ../W/file1.txt && 261 - diff -u "$CVSWORK/W/file2.txt" ../W/file2.txt 260 + test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt && 261 + test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt 262 262 ) 263 263 ' 264 264 ··· 279 279 git cvsexportcommit -w "$CVSWORK" -c $id && 280 280 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" && 281 281 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" && 282 - diff -u "$CVSWORK/DS" DS && 283 - diff -u "$CVSWORK/E/DS" E/DS && 284 - diff -u "$CVSWORK/release-notes" release-notes 282 + test_cmp "$CVSWORK/DS" DS && 283 + test_cmp "$CVSWORK/E/DS" E/DS && 284 + test_cmp "$CVSWORK/release-notes" release-notes 285 285 286 286 ' 287 287 ··· 293 293 id=$(git rev-parse HEAD) && 294 294 git cvsexportcommit -w "$CVSWORK" -c $id && 295 295 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" && 296 - diff -u "$CVSWORK/ space" " space" 296 + test_cmp "$CVSWORK/ space" " space" 297 297 298 298 ' 299 299
+18
t/test-lib.sh
··· 42 42 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME 43 43 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME 44 44 export EDITOR VISUAL 45 + GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} 45 46 46 47 # Protect ourselves from common misconfiguration to export 47 48 # CDPATH into the environment ··· 300 301 test_must_fail () { 301 302 "$@" 302 303 test $? -gt 0 -a $? -le 128 304 + } 305 + 306 + # test_cmp is a helper function to compare actual and expected output. 307 + # You can use it like: 308 + # 309 + # test_expect_success 'foo works' ' 310 + # echo expected >expected && 311 + # foo >actual && 312 + # test_cmp expected actual 313 + # ' 314 + # 315 + # This could be written as either "cmp" or "diff -u", but: 316 + # - cmp's output is not nearly as easy to read as diff -u 317 + # - not all diff versions understand "-u" 318 + 319 + test_cmp() { 320 + $GIT_TEST_CMP "$@" 303 321 } 304 322 305 323 # Most tests can use the created repository, but some may need to create more.