t0027: support NATIVE_CRLF platforms

t0027 expects the native end-of-lines to be a single line feed character. On Windows, however, we set it to a carriage return character followed by a line feed character. Thus, we have to modify t0027 to expect different warnings depending on the end-of-line markers. Adjust the check of the warnings and use these macros: WILC: Warn if LF becomes CRLF WICL: Warn if CRLF becomes LF WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF Improve the information given by check_warning(). Use test_cmp to show which warning is missing (or shouldn't be there). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Apr 17, 2015 at 17:44 UTC d6d6673e66deb6c6263dbe3d6668748c4f51c9a6
1 file changed +22 -10
t/t0027-auto-crlf.sh
+22 -10
@@ -57,15 +57,13 @@ create_gitattributes () {
57
58 check_warning () {
59 case "$1" in
60 - LF_CRLF) grep "LF will be replaced by CRLF" $2;;
61 - CRLF_LF) grep "CRLF will be replaced by LF" $2;;
62 - '')
63 - >expect
64 - grep "will be replaced by" $2 >actual
65 - test_cmp expect actual
66 - ;;
67 - *) false ;;
60 + LF_CRLF) echo "warning: LF will be replaced by CRLF" >"$2".expect ;;
61 + CRLF_LF) echo "warning: CRLF will be replaced by LF" >"$2".expect ;;
62 + '') >"$2".expect ;;
63 + *) echo >&2 "Illegal 1": "$1" ; return false ;;
64 esac
65 + grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" >"$2".actual
66 + test_cmp "$2".expect "$2".actual
67 }
68
69 commit_check_warn () {
@@ -169,6 +167,20 @@ test_expect_success 'setup master' '
167 warn_LF_CRLF="LF will be replaced by CRLF"
168 warn_CRLF_LF="CRLF will be replaced by LF"
169
170 +# WILC stands for "Warn if (this OS) converts LF into CRLF".
171 +# WICL: Warn if CRLF becomes LF
172 +# WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF
173 +if test_have_prereq NATIVE_CRLF
174 +then
175 + WILC=LF_CRLF
176 + WICL=
177 + WAMIX=LF_CRLF
178 +else
179 + WILC=
180 + WICL=CRLF_LF
181 + WAMIX=CRLF_LF
182 +fi
183 +
184 test_expect_success 'commit files empty attr' '
185 commit_check_warn false "" "" "" "" "" "" &&
186 commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" &&
@@ -176,13 +188,13 @@ test_expect_success 'commit files empty attr' '
188 '
189
190 test_expect_success 'commit files attr=auto' '
179 - commit_check_warn false "auto" "" "CRLF_LF" "CRLF_LF" "" "" &&
191 + commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" &&
192 commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" &&
193 commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" ""
194 '
195
196 test_expect_success 'commit files attr=text' '
185 - commit_check_warn false "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
197 + commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" &&
198 commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
199 commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
200 '