@@ -20,11 +20,27 @@ test_expect_success setup '
20
20
21
21
blue_grep=' 7;34m' ; # ESC [ 7 ; 3 4 m
22
22
23
+ printf " \033[%s" " $blue_grep " > check-grep
24
+ if (grep " $blue_grep " < check-grep | grep " $blue_grep " ) > /dev/null 2>&1
25
+ then
26
+ grep_a=grep
27
+ elif (grep -a " $blue_grep " < check-grep | grep -a " $blue_grep " ) > /dev/null 2>&1
28
+ then
29
+ grep_a=' grep -a'
30
+ else
31
+ grep_a=grep ; # expected to fail...
32
+ fi
33
+ rm -f check-grep
34
+
35
+ prepare_output () {
36
+ git diff --color > output
37
+ $grep_a " $blue_grep " output > error
38
+ $grep_a -v " $blue_grep " output > normal
39
+ }
40
+
23
41
test_expect_success default '
24
42
25
- git diff --color >output
26
- grep "$blue_grep" output >error
27
- grep -v "$blue_grep" output >normal
43
+ prepare_output
28
44
29
45
grep Eight normal >/dev/null &&
30
46
grep HT error >/dev/null &&
@@ -37,9 +53,7 @@ test_expect_success default '
37
53
test_expect_success ' without -trail' '
38
54
39
55
git config core.whitespace -trail
40
- git diff --color >output
41
- grep "$blue_grep" output >error
42
- grep -v "$blue_grep" output >normal
56
+ prepare_output
43
57
44
58
grep Eight normal >/dev/null &&
45
59
grep HT error >/dev/null &&
@@ -53,9 +67,7 @@ test_expect_success 'without -trail (attribute)' '
53
67
54
68
git config --unset core.whitespace
55
69
echo "F whitespace=-trail" >.gitattributes
56
- git diff --color >output
57
- grep "$blue_grep" output >error
58
- grep -v "$blue_grep" output >normal
70
+ prepare_output
59
71
60
72
grep Eight normal >/dev/null &&
61
73
grep HT error >/dev/null &&
@@ -69,9 +81,7 @@ test_expect_success 'without -space' '
69
81
70
82
rm -f .gitattributes
71
83
git config core.whitespace -space
72
- git diff --color >output
73
- grep "$blue_grep" output >error
74
- grep -v "$blue_grep" output >normal
84
+ prepare_output
75
85
76
86
grep Eight normal >/dev/null &&
77
87
grep HT normal >/dev/null &&
@@ -85,9 +95,7 @@ test_expect_success 'without -space (attribute)' '
85
95
86
96
git config --unset core.whitespace
87
97
echo "F whitespace=-space" >.gitattributes
88
- git diff --color >output
89
- grep "$blue_grep" output >error
90
- grep -v "$blue_grep" output >normal
98
+ prepare_output
91
99
92
100
grep Eight normal >/dev/null &&
93
101
grep HT normal >/dev/null &&
@@ -101,9 +109,7 @@ test_expect_success 'with indent-non-tab only' '
101
109
102
110
rm -f .gitattributes
103
111
git config core.whitespace indent,-trailing,-space
104
- git diff --color >output
105
- grep "$blue_grep" output >error
106
- grep -v "$blue_grep" output >normal
112
+ prepare_output
107
113
108
114
grep Eight error >/dev/null &&
109
115
grep HT normal >/dev/null &&
@@ -117,9 +123,7 @@ test_expect_success 'with indent-non-tab only (attribute)' '
117
123
118
124
git config --unset core.whitespace
119
125
echo "F whitespace=indent,-trailing,-space" >.gitattributes
120
- git diff --color >output
121
- grep "$blue_grep" output >error
122
- grep -v "$blue_grep" output >normal
126
+ prepare_output
123
127
124
128
grep Eight error >/dev/null &&
125
129
grep HT normal >/dev/null &&
@@ -133,9 +137,7 @@ test_expect_success 'with cr-at-eol' '
133
137
134
138
rm -f .gitattributes
135
139
git config core.whitespace cr-at-eol
136
- git diff --color >output
137
- grep "$blue_grep" output >error
138
- grep -v "$blue_grep" output >normal
140
+ prepare_output
139
141
140
142
grep Eight normal >/dev/null &&
141
143
grep HT error >/dev/null &&
@@ -149,9 +151,7 @@ test_expect_success 'with cr-at-eol (attribute)' '
149
151
150
152
git config --unset core.whitespace
151
153
echo "F whitespace=trailing,cr-at-eol" >.gitattributes
152
- git diff --color >output
153
- grep "$blue_grep" output >error
154
- grep -v "$blue_grep" output >normal
154
+ prepare_output
155
155
156
156
grep Eight normal >/dev/null &&
157
157
grep HT error >/dev/null &&
@@ -195,7 +195,7 @@ test_expect_success 'color new trailing blank lines' '
195
195
git add x &&
196
196
{ echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
197
197
git diff --color x >output &&
198
- cnt=$(grep "${blue_grep}" output | wc -l) &&
198
+ cnt=$($grep_a "${blue_grep}" output | wc -l) &&
199
199
test $cnt = 2
200
200
'
201
201
0 commit comments