Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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>
  • Loading branch information...
commit 82ebb0b6ec7470cab96a013d3d719c109003ef83 1 parent b4ce54f
Jeff King authored March 12, 2008 gitster committed March 13, 2008

Showing 40 changed files with 133 additions and 115 deletions. Show diff stats Hide diff stats

  1. 2  t/t0003-attributes.sh
  2. 2  t/t0022-crlf-rename.sh
  3. 2  t/t1005-read-tree-reset.sh
  4. 2  t/t2200-add-update.sh
  5. 2  t/t3001-ls-files-others-exclude.sh
  6. 4  t/t3050-subprojects-fetch.sh
  7. 2  t/t3060-ls-files-with-tree.sh
  8. 6  t/t3201-branch-contains.sh
  9. 4  t/t3404-rebase-interactive.sh
  10. 4  t/t3405-rebase-malformed.sh
  11. 2  t/t3406-rebase-message.sh
  12. 4  t/t3701-add-interactive.sh
  13. 16  t/t3902-quoted.sh
  14. 2  t/t3903-stash.sh
  15. 6  t/t4023-diff-rename-typechange.sh
  16. 2  t/t4024-diff-optimize-common.sh
  17. 2  t/t4025-hunk-header.sh
  18. 6  t/t4027-diff-submodule.sh
  19. 2  t/t4105-apply-fuzz.sh
  20. 8  t/t4125-apply-ws-fuzz.sh
  21. 10  t/t4150-am-subdir.sh
  22. 2  t/t4201-shortlog.sh
  23. 6  t/t5505-remote.sh
  24. 2  t/t5510-fetch.sh
  25. 8  t/t5512-ls-remote.sh
  26. 2  t/t6004-rev-list-path-optim.sh
  27. 2  t/t6009-rev-list-parent.sh
  28. 4  t/t6027-merge-binary.sh
  29. 2  t/t6029-merge-subtree.sh
  30. 18  t/t7010-setup.sh
  31. 18  t/t7201-co.sh
  32. 14  t/t7501-commit.sh
  33. 14  t/t7502-commit.sh
  34. 2  t/t7502-status.sh
  35. 2  t/t7600-merge.sh
  36. 4  t/t8003-blame.sh
  37. 2  t/t9001-send-email.sh
  38. 24  t/t9116-git-svn-log.sh
  39. 14  t/t9200-git-cvsexportcommit.sh
  40. 18  t/test-lib.sh
2  t/t0003-attributes.sh
@@ -11,7 +11,7 @@ attr_check () {
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
 
2  t/t0022-crlf-rename.sh
@@ -26,7 +26,7 @@ test_expect_success 'diff -M' '
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
 
2  t/t1005-read-tree-reset.sh
@@ -24,7 +24,7 @@ test_expect_success 'setup' '
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
2  t/t2200-add-update.sh
@@ -62,7 +62,7 @@ test_expect_success 'cache tree has not been corrupted' '
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
 
2  t/t3001-ls-files-others-exclude.sh
@@ -97,7 +97,7 @@ cat > expect << EOF
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
 
4  t/t3050-subprojects-fetch.sh
@@ -26,7 +26,7 @@ test_expect_success clone '
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,7 +46,7 @@ test_expect_success fetch '
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
2  t/t3060-ls-files-with-tree.sh
@@ -66,6 +66,6 @@ test_expect_success 'git -ls-files --with-tree should succeed from subdir' '
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
6  t/t3201-branch-contains.sh
@@ -31,7 +31,7 @@ test_expect_success 'branch --contains=master' '
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,7 +41,7 @@ test_expect_success 'branch --contains master' '
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,7 +51,7 @@ test_expect_success 'branch --contains=side' '
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
 
4  t/t3404-rebase-interactive.sh
@@ -146,8 +146,8 @@ EOF
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
 '
4  t/t3405-rebase-malformed.sh
@@ -41,8 +41,8 @@ test_expect_success rebase '
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
2  t/t3406-rebase-message.sh
@@ -37,7 +37,7 @@ test_expect_success 'rebase -m' '
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
 
4  t/t3701-add-interactive.sh
@@ -24,7 +24,7 @@ EOF
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,7 +57,7 @@ EOF
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 &&
16  t/t3902-quoted.sh
@@ -78,28 +78,28 @@ EOF
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,28 +111,28 @@ test_expect_success 'setting core.quotepath' '
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
 
2  t/t3903-stash.sh
@@ -34,7 +34,7 @@ EOF
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' '
6  t/t4023-diff-rename-typechange.sh
@@ -57,7 +57,7 @@ test_expect_success 'cross renames to be detected for regular files' '
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,7 +68,7 @@ test_expect_success 'cross renames to be detected for typechange' '
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,7 +79,7 @@ test_expect_success 'moves and renames' '
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
 
2  t/t4024-diff-optimize-common.sh
@@ -150,7 +150,7 @@ test_expect_success 'diff -U0' '
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
 
2  t/t4025-hunk-header.sh
@@ -37,7 +37,7 @@ test_expect_success 'hunk header truncation with an overly long line' '
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
 
6  t/t4027-diff-submodule.sh
@@ -37,17 +37,17 @@ test_expect_success setup '
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
2  t/t4105-apply-fuzz.sh
@@ -9,7 +9,7 @@ dotest () {
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
 
8  t/t4125-apply-ws-fuzz.sh
@@ -56,7 +56,7 @@ test_expect_success nofix '
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,7 +70,7 @@ 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,12 +91,12 @@ 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
 
10  t/t4150-am-subdir.sh
@@ -22,14 +22,14 @@ test_expect_success 'am regularly from stdin' '
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,7 +41,7 @@ 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,7 +53,7 @@ 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,7 +66,7 @@ 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
2  t/t4201-shortlog.sh
@@ -45,6 +45,6 @@ A U Thor (5):
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
6  t/t5505-remote.sh
@@ -24,7 +24,7 @@ setup_repository () {
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,7 +73,7 @@ test_expect_success 'add another remote' '
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,7 +93,7 @@ test_expect_success 'remove remote' '
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
 
2  t/t5510-fetch.sh
@@ -249,7 +249,7 @@ test_expect_success 'bundle should record HEAD correctly' '
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
 
8  t/t5512-ls-remote.sh
@@ -24,28 +24,28 @@ test_expect_success setup '
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
 
2  t/t6004-rev-list-path-optim.sh
@@ -45,7 +45,7 @@ test_expect_success 'further setup' '
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
2  t/t6009-rev-list-parent.sh
@@ -31,7 +31,7 @@ test_expect_failure 'one is ancestor of others and should not be shown' '
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
 
4  t/t6027-merge-binary.sh
@@ -45,7 +45,7 @@ test_expect_success resolve '
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,7 +60,7 @@ test_expect_success recursive '
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
 
2  t/t6029-merge-subtree.sh
@@ -25,7 +25,7 @@ test_expect_success 'subtree available and works like recursive' '
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
 
18  t/t7010-setup.sh
@@ -18,7 +18,7 @@ test_expect_success 'git add (absolute)' '
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,7 +32,7 @@ test_expect_success 'git add (funny relative)' '
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,7 +43,7 @@ test_expect_success 'git rm (absolute)' '
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,7 +57,7 @@ test_expect_success 'git rm (funny relative)' '
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,7 +67,7 @@ test_expect_success 'git ls-files (absolute)' '
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,7 +80,7 @@ test_expect_success 'git ls-files (relative #1)' '
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,7 +93,7 @@ test_expect_success 'git ls-files (relative #2)' '
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,13 +126,13 @@ test_expect_success 'log using absolute path names' '
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' '
18  t/t7201-co.sh
@@ -83,13 +83,13 @@ test_expect_success "checkout with unrelated dirty tree without -m" '
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,19 +106,19 @@ 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,7 +136,7 @@ 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,7 +161,7 @@ test_expect_success 'checkout -m with merge conflict' '
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,7 +178,7 @@ If you want to create a new branch from this checkout, you may do so
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" &&
14  t/t7501-commit.sh
@@ -203,7 +203,7 @@ test_expect_success 'sign off (1)' '
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,7 +223,7 @@ $existing" &&
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,7 +240,7 @@ test_expect_success 'multiple -m' '
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,12 +301,12 @@ test_expect_success 'same tree (merge and amend merge)' '
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,7 +323,7 @@ test_expect_success 'amend using the message from another commit' '
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,7 +341,7 @@ test_expect_success 'amend using the message from a commit named with tag' '
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
 
14  t/t7502-commit.sh
@@ -85,7 +85,7 @@ test_expect_success 'verbose' '
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,7 +95,7 @@ test_expect_success 'cleanup commit messages (verbatim,-t)' '
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,7 +104,7 @@ test_expect_success 'cleanup commit messages (verbatim,-F)' '
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,7 +113,7 @@ test_expect_success 'cleanup commit messages (verbatim,-m)' '
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,7 +124,7 @@ test_expect_success 'cleanup commit messages (whitespace,-F)' '
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,7 +135,7 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
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,7 +150,7 @@ test_expect_success 'cleanup commit messages (strip,-F,-e)' '
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
 
2  t/t7502-status.sh
@@ -146,7 +146,7 @@ cat <<EOF >expect
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
2  t/t7600-merge.sh
@@ -108,7 +108,7 @@ create_merge_msgs() {
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
4  t/t8003-blame.sh
@@ -112,7 +112,7 @@ test_expect_success 'blame wholesale copy' '
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,7 +125,7 @@ test_expect_success 'blame wholesale copy and more' '
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
 
2  t/t9001-send-email.sh
@@ -81,7 +81,7 @@ test_expect_success 'Show all headers' '
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
24  t/t9116-git-svn-log.sh
@@ -55,74 +55,74 @@ printf 'r1 \nr2 \nr4 \n' > expected-range-r1-r2-r4
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
14  t/t9200-git-cvsexportcommit.sh
@@ -37,7 +37,7 @@ check_entries () {
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,8 +257,8 @@ test_expect_success '-w option should work with relative GIT_DIR' '
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,9 +279,9 @@ test_expect_success 'check files before directories' '
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,7 +293,7 @@ test_expect_success 'commit a file with leading spaces in the name' '
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,6 +42,7 @@ export GIT_MERGE_VERBOSITY
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
@@ -302,6 +303,23 @@ test_must_fail () {
302 303
 	test $? -gt 0 -a $? -le 128
303 304
 }
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
+
305 323
 # Most tests can use the created repository, but some may need to create more.
306 324
 # Usage: test_create_repo <directory>
307 325
 test_create_repo () {

0 notes on commit 82ebb0b

Please sign in to comment.
Something went wrong with that request. Please try again.