t0027: improve test for not-normalized files
When a text file with mixed line endings is commited into the repo, it is called "not normalized" (or NNO) in t0027. The existing test case using repoMIX did not fully test all combinations: (Especially when core.autocrlf = true) Files with NL are not converted at commit, but at checkout, so a warning NL->CRLF is given. Files with CRLF are not converted at all (so no warning will be given), unless they are marked as "text" or "auto". Remove repoMIX introduced in commit 8eeab92f02, and replace it with a combination of NNO tests. Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Torsten Bögershausen committed
Oct 10, 2015 at 06:23 UTC
710b4e8a167f6fe968d2f4f540be5baa3ddcfdd6
1 file changed
+157
-34
t/t0027-auto-crlf.sh
+157
-34
@@ -55,6 +55,26 @@ create_gitattributes () {
55
esac
56
}
57
58
+create_NNO_files () {
59
+ lfname=$1
60
+ crlfname=$2
61
+ lfmixcrlf=$3
62
+ lfmixcr=$4
63
+ crlfnul=$5
64
+ for crlf in false true input
65
+ do
66
+ for attr in "" auto text -text lf crlf
67
+ do
68
+ pfx=NNO_${crlf}_attr_${attr} &&
69
+ cp $lfname ${pfx}_LF.txt &&
70
+ cp $crlfname ${pfx}_CRLF.txt &&
71
+ cp $lfmixcrlf ${pfx}_CRLF_mix_LF.txt &&
72
+ cp $lfmixcr ${pfx}_LF_mix_CR.txt &&
73
+ cp $crlfnul ${pfx}_CRLF_nul.txt
74
+ done
75
+ done
76
+}
77
+
78
check_warning () {
79
case "$1" in
80
LF_CRLF) echo "warning: LF will be replaced by CRLF" >"$2".expect ;;
@@ -62,7 +82,7 @@ check_warning () {
82
'') >"$2".expect ;;
83
*) echo >&2 "Illegal 1": "$1" ; return false ;;
84
esac
65
- grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" >"$2".actual
85
+ grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" | uniq >"$2".actual
86
test_cmp "$2".expect "$2".actual
87
}
88
@@ -71,19 +91,10 @@ commit_check_warn () {
91
attr=$2
92
lfname=$3
93
crlfname=$4
74
- repoMIX=$5
75
- lfmixcrlf=$6
76
- lfmixcr=$7
77
- crlfnul=$8
94
+ lfmixcrlf=$5
95
+ lfmixcr=$6
96
+ crlfnul=$7
97
pfx=crlf_${crlf}_attr_${attr}
79
- # Special handling for repoMIX: It should already be in the repo
80
- # with CRLF
81
- f=repoMIX
82
- fname=${pfx}_$f.txt
83
- echo >.gitattributes &&
84
- cp $f $fname &&
85
- git -c core.autocrlf=false add $fname 2>"${pfx}_$f.err" &&
86
- git commit -m "repoMIX" &&
98
create_gitattributes "$attr" &&
99
for f in LF CRLF repoMIX LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
100
do
@@ -99,6 +110,45 @@ commit_check_warn () {
110
check_warning "$crlfnul" ${pfx}_CRLF_nul.err
111
}
112
113
+commit_chk_wrnNNO () {
114
+ crlf=$1
115
+ attr=$2
116
+ lfwarn=$3
117
+ crlfwarn=$4
118
+ lfmixcrlf=$5
119
+ lfmixcr=$6
120
+ crlfnul=$7
121
+ pfx=NNO_${crlf}_attr_${attr}
122
+ #Commit files on top of existing file
123
+ create_gitattributes "$attr" &&
124
+ for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
125
+ do
126
+ fname=${pfx}_$f.txt &&
127
+ cp $f $fname &&
128
+ git -c core.autocrlf=$crlf add $fname 2>/dev/null &&
129
+ git -c core.autocrlf=$crlf commit -m "commit_$fname" $fname >"${pfx}_$f.err" 2>&1
130
+ done
131
+
132
+ test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" '
133
+ check_warning "$lfwarn" ${pfx}_LF.err
134
+ '
135
+ test_expect_success "commit NNO files crlf=$crlf attr=$attr CRLF" '
136
+ check_warning "$crlfwarn" ${pfx}_CRLF.err
137
+ '
138
+
139
+ test_expect_success "commit NNO files crlf=$crlf attr=$attr CRLF_mix_LF" '
140
+ check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
141
+ '
142
+
143
+ test_expect_success "commit NNO files crlf=$crlf attr=$attr LF_mix_cr" '
144
+ check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
145
+ '
146
+
147
+ test_expect_success "commit NNO files crlf=$crlf attr=$attr CRLF_nul" '
148
+ check_warning "$crlfnul" ${pfx}_CRLF_nul.err
149
+ '
150
+}
151
+
152
check_files_in_repo () {
153
crlf=$1
154
attr=$2
@@ -115,6 +165,31 @@ check_files_in_repo () {
165
compare_files $crlfnul ${pfx}CRLF_nul.txt
166
}
167
168
+check_in_repo_NNO () {
169
+ crlf=$1
170
+ attr=$2
171
+ lfname=$3
172
+ crlfname=$4
173
+ lfmixcrlf=$5
174
+ lfmixcr=$6
175
+ crlfnul=$7
176
+ pfx=NNO_${crlf}_attr_${attr}_
177
+ test_expect_success "compare_files $lfname ${pfx}LF.txt" '
178
+ compare_files $lfname ${pfx}LF.txt
179
+ '
180
+ test_expect_success "compare_files $crlfname ${pfx}CRLF.txt" '
181
+ compare_files $crlfname ${pfx}CRLF.txt
182
+ '
183
+ test_expect_success "compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt" '
184
+ compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt
185
+ '
186
+ test_expect_success "compare_files $lfmixcr ${pfx}LF_mix_CR.txt" '
187
+ compare_files $lfmixcr ${pfx}LF_mix_CR.txt
188
+ '
189
+ test_expect_success "compare_files $crlfnul ${pfx}CRLF_nul.txt" '
190
+ compare_files $crlfnul ${pfx}CRLF_nul.txt
191
+ '
192
+}
193
194
checkout_files () {
195
eol=$1
@@ -169,7 +244,11 @@ test_expect_success 'setup master' '
244
printf "line1\nline2\rline3" >LF_mix_CR &&
245
printf "line1\r\nline2\rline3" >CRLF_mix_CR &&
246
printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul &&
172
- printf "line1Q\nline2\nline3" | q_to_nul >LF_nul
247
+ printf "line1Q\nline2\nline3" | q_to_nul >LF_nul &&
248
+ create_NNO_files CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF &&
249
+ git -c core.autocrlf=false add NNO_*.txt &&
250
+ git commit -m "mixed line endings" &&
251
+ test_tick
252
'
253
254
@@ -191,46 +270,72 @@ else
270
WAMIX=CRLF_LF
271
fi
272
194
-# attr LF CRLF repoMIX CRLFmixLF LFmixCR CRLFNUL
273
+# attr LF CRLF CRLFmixLF LFmixCR CRLFNUL
274
test_expect_success 'commit files empty attr' '
196
- commit_check_warn false "" "" "" "" "" "" "" &&
197
- commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" "" &&
198
- commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" ""
275
+ commit_check_warn false "" "" "" "" "" "" &&
276
+ commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" &&
277
+ commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" ""
278
'
279
280
test_expect_success 'commit files attr=auto' '
202
- commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "$WAMIX" "" "" &&
203
- commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" "" &&
204
- commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" ""
281
+ commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" &&
282
+ commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" &&
283
+ commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" ""
284
'
285
286
test_expect_success 'commit files attr=text' '
208
- commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WAMIX" "$WILC" "$WICL" &&
209
- commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
210
- commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
287
+ commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" &&
288
+ commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
289
+ commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
290
'
291
292
test_expect_success 'commit files attr=-text' '
214
- commit_check_warn false "-text" "" "" "" "" "" "" &&
215
- commit_check_warn true "-text" "" "" "" "" "" "" &&
216
- commit_check_warn input "-text" "" "" "" "" "" ""
293
+ commit_check_warn false "-text" "" "" "" "" "" &&
294
+ commit_check_warn true "-text" "" "" "" "" "" &&
295
+ commit_check_warn input "-text" "" "" "" "" ""
296
'
297
298
test_expect_success 'commit files attr=lf' '
220
- commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
221
- commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
222
- commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
299
+ commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
300
+ commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
301
+ commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
302
'
303
304
test_expect_success 'commit files attr=crlf' '
226
- commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
227
- commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
228
- commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" ""
305
+ commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
306
+ commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
307
+ commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
308
'
309
310
+# attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
311
+commit_chk_wrnNNO false "" "" "" "" "" ""
312
+commit_chk_wrnNNO true "" "LF_CRLF" "" "" "" ""
313
+commit_chk_wrnNNO input "" "" "" "" "" ""
314
+
315
+
316
+commit_chk_wrnNNO false "auto" "$WILC" "$WICL" "$WAMIX" "" ""
317
+commit_chk_wrnNNO true "auto" "LF_CRLF" "" "LF_CRLF" "" ""
318
+commit_chk_wrnNNO input "auto" "" "CRLF_LF" "CRLF_LF" "" ""
319
+
320
+commit_chk_wrnNNO false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL"
321
+commit_chk_wrnNNO true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
322
+commit_chk_wrnNNO input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
323
+
324
+commit_chk_wrnNNO false "-text" "" "" "" "" ""
325
+commit_chk_wrnNNO true "-text" "" "" "" "" ""
326
+commit_chk_wrnNNO input "-text" "" "" "" "" ""
327
+
328
+commit_chk_wrnNNO false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
329
+commit_chk_wrnNNO true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
330
+commit_chk_wrnNNO input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
331
+
332
+commit_chk_wrnNNO false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
333
+commit_chk_wrnNNO true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
334
+commit_chk_wrnNNO input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
335
+
336
test_expect_success 'create files cleanup' '
337
rm -f *.txt &&
233
- git reset --hard
338
+ git -c core.autocrlf=false reset --hard
339
'
340
341
test_expect_success 'commit empty gitattribues' '
@@ -257,6 +362,24 @@ test_expect_success 'commit -text' '
362
check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
363
'
364
365
+# attr LF CRLF CRLF_mix_LF LF_mix_CR CRLFNUL
366
+check_in_repo_NNO false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
367
+check_in_repo_NNO true "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
368
+check_in_repo_NNO input "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
369
+
370
+check_in_repo_NNO false "auto" LF LF LF LF_mix_CR CRLF_nul
371
+check_in_repo_NNO true "auto" LF LF LF LF_mix_CR CRLF_nul
372
+check_in_repo_NNO input "auto" LF LF LF LF_mix_CR CRLF_nul
373
+
374
+check_in_repo_NNO false "text" LF LF LF LF_mix_CR LF_nul
375
+check_in_repo_NNO true "text" LF LF LF LF_mix_CR LF_nul
376
+check_in_repo_NNO input "text" LF LF LF LF_mix_CR LF_nul
377
+
378
+check_in_repo_NNO false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
379
+check_in_repo_NNO true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
380
+check_in_repo_NNO input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
381
+
382
+
383
################################################################################
384
# Check how files in the repo are changed when they are checked out
385
# How to read the table below: