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