git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: git@vger.kernel.org
Cc: tboegi@web.de
Subject: [PATCH RFC] t0027: check the eol conversion warnings
Date: Thu, 20 Nov 2014 22:29:10 +0100	[thread overview]
Message-ID: <546E5D26.8030109@web.de> (raw)

Add tests to check the warnings when adding file with eol=lf and eol=crlf.

Add a function check_warning() to check the warnings on stderr
"CRLF will be replaced..." or "LF will be replaced..."

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
 t/t0027-auto-crlf.sh | 103 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 80 insertions(+), 23 deletions(-)

diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh
index 2a4a6c1..9570947 100755
--- a/t/t0027-auto-crlf.sh
+++ b/t/t0027-auto-crlf.sh
@@ -55,16 +55,36 @@ create_gitattributes () {
 	esac
 }
 
-create_file_in_repo () {
+check_warning () {
+	case "$1" in
+	LF_CRLF) grep "LF will be replaced by CRLF" $2;;
+	CRLF_LF) grep "CRLF will be replaced by LF" $2;;
+	*) test_cmp /dev/null $2;;
+	esac
+}
+
+add_check_warn () {
 	crlf=$1
 	attr=$2
+	lfname=$3
+	crlfname=$4
+	lfmixcrlf=$5
+	lfmixcr=$6
+	crlfnul=$7
 	create_gitattributes "$attr" &&
+	pfx=crlf_${crlf}_attr_${attr}
 	for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
 	do
-		pfx=crlf_${crlf}_attr_${attr}_$f.txt &&
-		cp $f $pfx && git -c core.autocrlf=$crlf add $pfx
+		fname=${pfx}_$f.txt &&
+		cp $f $fname &&
+		git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err"
 	done &&
-	git commit -m "core.autocrlf $crlf"
+	git commit -m "core.autocrlf $crlf" &&
+	check_warning "$lfname" ${pfx}_LF.err &&
+	check_warning "$crlfname" ${pfx}_CRLF.err &&
+	check_warning "$lfmixcrlf" ${pfx}_LF_mix_CR.err &&
+	check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err &&
+	check_warning "$crlfnul" ${pfx}_CRLF_nul.err
 }
 
 check_files_in_repo () {
@@ -140,50 +160,87 @@ test_expect_success 'setup master' '
 '
 
 
-test_expect_success 'create files' '
-	create_file_in_repo false "" &&
-	create_file_in_repo true  "" &&
-	create_file_in_repo input "" &&
 
-	create_file_in_repo false "auto" &&
-	create_file_in_repo true  "auto" &&
-	create_file_in_repo input "auto" &&
+warn_LF_CRLF="LF will be replaced by CRLF"
+warn_CRLF_LF="CRLF will be replaced by LF"
+
+test_expect_success 'add files empty attr' '
+	add_check_warn false ""     ""        ""        ""        ""        "" &&
+	add_check_warn true  ""     "LF_CRLF" ""        ""        ""        "" &&
+	add_check_warn input ""     ""        "CRLF_LF" ""        ""        ""
+'
 
-	create_file_in_repo false "text" &&
-	create_file_in_repo true  "text" &&
-	create_file_in_repo input "text" &&
+test_expect_success 'add files attr=auto' '
+	add_check_warn false "auto" ""        "CRLF_LF" ""        ""        "" &&
+	add_check_warn true  "auto" "LF_CRLF" ""        ""        ""        "" &&
+	add_check_warn input "auto" ""        "CRLF_LF" ""        ""        ""
+'
 
-	create_file_in_repo false "-text" &&
-	create_file_in_repo true  "-text" &&
-	create_file_in_repo input "-text" &&
+test_expect_success 'add files attr=text' '
+	add_check_warn false "text" ""        "CRLF_LF" ""        ""        "CRLF_LF" &&
+	add_check_warn true  "text" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" ""        &&
+	add_check_warn input "text" ""        "CRLF_LF" ""        ""        "CRLF_LF"
+'
+
+test_expect_success 'add files attr=-text' '
+	add_check_warn false "-text" ""       ""        ""        ""        "" &&
+	add_check_warn true  "-text" ""       ""        ""        ""        "" &&
+	add_check_warn input "-text" ""       ""        ""        ""        ""
+'
+
+test_expect_success 'add files attr=lf' '
+	add_check_warn false "lf"    ""       "CRLF_LF" ""         ""       "CRLF_LF" &&
+	add_check_warn true  "lf"    ""       "CRLF_LF" ""         ""       "CRLF_LF" &&
+	add_check_warn input "lf"    ""       "CRLF_LF" ""         ""       "CRLF_LF"
+'
+
+test_expect_success 'add files attr=crlf' '
+	add_check_warn false "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "" &&
+	add_check_warn true  "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" "" &&
+	add_check_warn input "crlf" "LF_CRLF" ""        "LF_CRLF" "LF_CRLF" ""
+'
+
+test_expect_success 'create files cleanup' '
 	rm -f *.txt &&
 	git reset --hard
 '
 
-test_expect_success 'commit empty gitattribues' '
+test_expect_success 'check file in repo empty gitattribues' '
 	check_files_in_repo false ""      LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
 	check_files_in_repo true  ""      LF LF   LF          LF_mix_CR CRLF_nul &&
 	check_files_in_repo input ""      LF LF   LF          LF_mix_CR CRLF_nul
 '
 
-test_expect_success 'commit text=auto' '
+test_expect_success 'check file in repo text=auto' '
 	check_files_in_repo false "auto"  LF LF   LF          LF_mix_CR CRLF_nul &&
 	check_files_in_repo true  "auto"  LF LF   LF          LF_mix_CR CRLF_nul &&
 	check_files_in_repo input "auto"  LF LF   LF          LF_mix_CR CRLF_nul
 '
 
-test_expect_success 'commit text' '
+test_expect_success 'check file in repo text' '
 	check_files_in_repo false "text"  LF LF   LF          LF_mix_CR LF_nul &&
 	check_files_in_repo true  "text"  LF LF   LF          LF_mix_CR LF_nul &&
 	check_files_in_repo input "text"  LF LF   LF          LF_mix_CR LF_nul
 '
 
-test_expect_success 'commit -text' '
+test_expect_success 'check file in repo -text' '
 	check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
 	check_files_in_repo true  "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
 	check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
 '
 
+test_expect_success 'check file in repo lf' '
+	check_files_in_repo false "lf"    LF LF   LF          LF_mix_CR LF_nul &&
+	check_files_in_repo true  "lf"    LF LF   LF          LF_mix_CR LF_nul &&
+	check_files_in_repo input "lf"    LF LF   LF          LF_mix_CR LF_nul
+'
+
+test_expect_success 'check file in repo crlf' '
+	check_files_in_repo false "crlf"  LF LF   LF          LF_mix_CR LF_nul &&
+	check_files_in_repo true  "crlf"  LF LF   LF          LF_mix_CR LF_nul &&
+	check_files_in_repo input "crlf"  LF LF   LF          LF_mix_CR LF_nul
+'
+
 ################################################################################
 # Check how files in the repo are changed when they are checked out
 # How to read the table below:
@@ -199,8 +256,8 @@ test_expect_success 'commit -text' '
 # - parameter $8 : reference for a file with CRLF and a NUL (should be handled as binary when auto)
 
 #                                            What we have in the repo:
-#                														 ----------------- EOL in repo ----------------
-#                														 LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
+#                                            ----------------- EOL in repo ----------------
+#                                            LF    CRLF  CRLF_mix_LF  LF_mix_CR    CRLF_nul
 #                   settings with checkout:
 #                   core.   core.   .gitattr
 #                    eol     acrlf
-- 
1.9.1.dirty

             reply	other threads:[~2014-11-20 21:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 21:29 Torsten Bögershausen [this message]
2014-11-20 22:37 ` [PATCH RFC] t0027: check the eol conversion warnings Junio C Hamano
2014-11-21 12:37   ` Torsten Bögershausen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=546E5D26.8030109@web.de \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).