Commit 9065160bfb55bea6d4bf932783d7ceab952ed1c9

Sven Strickroth 2015-07-01T16:55:06

crlf: script to generate expected crlf data for adding files to index Include a shell script that will generate the expected data of OIDs and failures for calling git.git to capture its output as a test resource. Right now, there is no need to differentiate different systems as git behaves the same on all systems IIRC. Signed-off-by: Sven Strickroth <email@cs-ware.de>

diff --git a/tests/resources/crlf_data/README b/tests/resources/crlf_data/README
index 2347e12..0c8badf 100644
--- a/tests/resources/crlf_data/README
+++ b/tests/resources/crlf_data/README
@@ -1,2 +1,3 @@
 This test data was generated using the `tests/resources/generate_crlf.sh`
-script.  Please see that script for usage information.
+(posix and windows directories) and `tests/resources/generate_crlf_checkin.sh`
+(checkin_results directory) scripts. Please see these scripts for usage information.
diff --git a/tests/resources/crlf_data/checkin_input_files/all-crlf b/tests/resources/crlf_data/checkin_input_files/all-crlf
new file mode 100644
index 0000000..a9a2e89
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/all-crlf
@@ -0,0 +1,4 @@
+crlf
+crlf
+crlf
+crlf
diff --git a/tests/resources/crlf_data/checkin_input_files/all-crlf-utf8bom b/tests/resources/crlf_data/checkin_input_files/all-crlf-utf8bom
new file mode 100644
index 0000000..0aa76e4
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/all-crlf-utf8bom
@@ -0,0 +1,4 @@
+crlf
+crlf
+crlf
+crlf
diff --git a/tests/resources/crlf_data/checkin_input_files/all-lf b/tests/resources/crlf_data/checkin_input_files/all-lf
new file mode 100644
index 0000000..799770d
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/all-lf
@@ -0,0 +1,5 @@
+lf
+lf
+lf
+lf
+lf
diff --git a/tests/resources/crlf_data/checkin_input_files/all-lf-utf8bom b/tests/resources/crlf_data/checkin_input_files/all-lf-utf8bom
new file mode 100644
index 0000000..7cce67e
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/all-lf-utf8bom
@@ -0,0 +1,5 @@
+lf
+lf
+lf
+lf
+lf
diff --git a/tests/resources/crlf_data/checkin_input_files/binary-all-crlf b/tests/resources/crlf_data/checkin_input_files/binary-all-crlf
new file mode 100644
index 0000000..8534075
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/binary-all-crlf
@@ -0,0 +1,4 @@
+one
+two
+three
+four
diff --git a/tests/resources/crlf_data/checkin_input_files/binary-all-lf b/tests/resources/crlf_data/checkin_input_files/binary-all-lf
new file mode 100644
index 0000000..af6fcf6
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/binary-all-lf
@@ -0,0 +1,4 @@
+one
+two
+three
+four
diff --git a/tests/resources/crlf_data/checkin_input_files/binary-mixed-lf-cr b/tests/resources/crlf_data/checkin_input_files/binary-mixed-lf-cr
new file mode 100644
index 0000000..203555c
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/binary-mixed-lf-cr
@@ -0,0 +1,3 @@
+one
+two
three
+four
\ No newline at end of file
diff --git a/tests/resources/crlf_data/checkin_input_files/binary-mixed-lf-cr-crlf b/tests/resources/crlf_data/checkin_input_files/binary-mixed-lf-cr-crlf
new file mode 100644
index 0000000..aaf083a
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/binary-mixed-lf-cr-crlf
@@ -0,0 +1,3 @@
+one
+two
three
+four
\ No newline at end of file
diff --git a/tests/resources/crlf_data/checkin_input_files/few-utf8-chars-crlf b/tests/resources/crlf_data/checkin_input_files/few-utf8-chars-crlf
new file mode 100644
index 0000000..0e05288
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/few-utf8-chars-crlf
@@ -0,0 +1,22 @@
+⚽The rest is ASCII01.
+The rest is ASCII02.
+The rest is ASCII03.
+The rest is ASCII04.
+The rest is ASCII05.
+The rest is ASCII06.
+The rest is ASCII07.
+The rest is ASCII08.
+The rest is ASCII09.
+The rest is ASCII10.
+The rest is ASCII11.
+The rest is ASCII12.
+The rest is ASCII13.
+The rest is ASCII14.
+The rest is ASCII15.
+The rest is ASCII16.
+The rest is ASCII17.
+The rest is ASCII18.
+The rest is ASCII19.
+The rest is ASCII20.
+The rest is ASCII21.
+The rest is ASCII22.
diff --git a/tests/resources/crlf_data/checkin_input_files/few-utf8-chars-lf b/tests/resources/crlf_data/checkin_input_files/few-utf8-chars-lf
new file mode 100644
index 0000000..f4d25b7
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/few-utf8-chars-lf
@@ -0,0 +1,22 @@
+⚽The rest is ASCII01.
+The rest is ASCII02.
+The rest is ASCII03.
+The rest is ASCII04.
+The rest is ASCII05.
+The rest is ASCII06.
+The rest is ASCII07.
+The rest is ASCII08.
+The rest is ASCII09.
+The rest is ASCII10.
+The rest is ASCII11.
+The rest is ASCII12.
+The rest is ASCII13.
+The rest is ASCII14.
+The rest is ASCII15.
+The rest is ASCII16.
+The rest is ASCII17.
+The rest is ASCII18.
+The rest is ASCII19.
+The rest is ASCII20.
+The rest is ASCII21.
+The rest is ASCII22.
diff --git a/tests/resources/crlf_data/checkin_input_files/many-utf8-chars-crlf b/tests/resources/crlf_data/checkin_input_files/many-utf8-chars-crlf
new file mode 100644
index 0000000..cd574f5
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/many-utf8-chars-crlf
@@ -0,0 +1,4 @@
+Lets sing!
+♫♪♬♩
+Eat food
+🍅🍕
diff --git a/tests/resources/crlf_data/checkin_input_files/many-utf8-chars-lf b/tests/resources/crlf_data/checkin_input_files/many-utf8-chars-lf
new file mode 100644
index 0000000..9a6c353
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/many-utf8-chars-lf
@@ -0,0 +1,4 @@
+Lets sing!
+♫♪♬♩
+Eat food
+🍅🍕
diff --git a/tests/resources/crlf_data/checkin_input_files/mixed-lf-cr b/tests/resources/crlf_data/checkin_input_files/mixed-lf-cr
new file mode 100644
index 0000000..d11e7ef
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/mixed-lf-cr
@@ -0,0 +1,3 @@
+one
+two
three
+four
\ No newline at end of file
diff --git a/tests/resources/crlf_data/checkin_input_files/mixed-lf-cr-crlf b/tests/resources/crlf_data/checkin_input_files/mixed-lf-cr-crlf
new file mode 100644
index 0000000..417786f
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/mixed-lf-cr-crlf
@@ -0,0 +1,3 @@
+one
+two
three
+four
\ No newline at end of file
diff --git a/tests/resources/crlf_data/checkin_input_files/more-crlf b/tests/resources/crlf_data/checkin_input_files/more-crlf
new file mode 100644
index 0000000..0ff5a53
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/more-crlf
@@ -0,0 +1,5 @@
+crlf
+crlf
+lf
+crlf
+crlf
diff --git a/tests/resources/crlf_data/checkin_input_files/more-crlf-utf8bom b/tests/resources/crlf_data/checkin_input_files/more-crlf-utf8bom
new file mode 100644
index 0000000..ea030d3
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/more-crlf-utf8bom
@@ -0,0 +1,5 @@
+crlf
+crlf
+lf
+crlf
+crlf
diff --git a/tests/resources/crlf_data/checkin_input_files/more-lf b/tests/resources/crlf_data/checkin_input_files/more-lf
new file mode 100644
index 0000000..04de00b
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/more-lf
@@ -0,0 +1,5 @@
+lf
+lf
+crlf
+lf
+lf
diff --git a/tests/resources/crlf_data/checkin_input_files/more-lf-utf8bom b/tests/resources/crlf_data/checkin_input_files/more-lf-utf8bom
new file mode 100644
index 0000000..dc88e3b
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/more-lf-utf8bom
@@ -0,0 +1,5 @@
+lf
+lf
+crlf
+lf
+lf
diff --git a/tests/resources/crlf_data/checkin_input_files/zero-byte b/tests/resources/crlf_data/checkin_input_files/zero-byte
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/resources/crlf_data/checkin_input_files/zero-byte
diff --git a/tests/resources/generate_crlf.sh b/tests/resources/generate_crlf.sh
index 9e6f51a..db109ac 100755
--- a/tests/resources/generate_crlf.sh
+++ b/tests/resources/generate_crlf.sh
@@ -8,9 +8,9 @@
 # the configuration that git produces.
 #
 # To update the test resource data, from the test resource directory:
-#     git rm -r ./crlf_data
+#     git rm -r ./crlf_data/{posix,windows}
 #     sh ./generate_crlf.sh ./crlf ./crlf_data /tmp/crlf_gitdirs
-#     git add ./crlf_data
+#     git add ./crlf_data/{posix,windows}
 
 set -e
 
diff --git a/tests/resources/generate_crlf_checkin.sh b/tests/resources/generate_crlf_checkin.sh
new file mode 100755
index 0000000..d94ee99
--- /dev/null
+++ b/tests/resources/generate_crlf_checkin.sh
@@ -0,0 +1,118 @@
+#!/usr/bin/env bash
+#
+# This script will generate the test corpus for CR/LF data using git;
+# we created files with all possible line ending varieties (all LF, all
+# CRLF, mixed, etc) on all the possible line ending configurations
+# (`core.autocrlf=true`, `text=auto` in gitattributes, etc) add add them
+# to git and check the added hash.  This allows us to validate that our
+# configuration will match byte-for-byte the configuration that git produces.
+#
+# To update the test resource data, from the test resource directory:
+#     git rm -r ./crlf_data/checkin_results
+#     sh ./generate_crlf_checkin.sh ./crlf_data/checkin_input_files ./crlf_data/checkin_results /tmp/crlf_gitdirs
+#     git add ./crlf_data/checkin_results
+
+set -e
+
+if [ "$1" == "" -o "$2" == "" ]; then
+	echo "usage: $0 inputfiles-directory directory [tempdir]"
+	exit 1
+fi
+
+input=$1
+output=$2
+tempdir=$3
+
+if [ ${input:1} != "/" ]; then
+	input="$PWD/$input"
+fi
+
+if [ ${output:1} != "/" ]; then
+	output="$PWD/$output"
+fi
+
+if [ "${tempdir}" != "" -a "${tempdir:1}" != "/" ]; then
+	tempdir="$PWD/$tempdir"
+fi
+
+set -u
+
+create_test_data() {
+	local input=$1
+	local output=$2
+	local tempdir=$3
+	local safecrlf=$4
+	local autocrlf=$5
+	local attr=$6
+
+	local destdir="${output}/safecrlf_${safecrlf},autocrlf_${autocrlf}"
+
+	if [ "$attr" != "" ]; then
+		local attrdir=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
+		destdir="${destdir},${attrdir}"
+	fi
+
+	if [ "$tempdir" = "" ]; then
+		tempdir="${output}/generate_crlf_${RANDOM}"
+	else
+		tempdir="${tempdir}/generate_crlf_${RANDOM}"
+	fi
+
+	echo "Generating ${destdir}"
+	mkdir -p "${destdir}"
+	mkdir -p "${tempdir}"
+
+	git init "${tempdir}"
+	if [ "$attr" != "" ]; then
+		echo "* ${attr}" > "${tempdir}/.gitattributes"
+	fi
+	cp "$input"/* "${tempdir}"
+	pushd "${tempdir}"
+		git config core.autocrlf ${autocrlf}
+		git config core.safecrlf ${safecrlf}
+		for file in *
+		do
+			process_file "$destdir" "$file"
+		done
+	popd
+
+	rm -rf "$tempdir"
+}
+
+function process_file() {
+	destdir=$1
+	file=$2
+
+	rm -f "$destdir/$file.obj" "$destdir/$file.fail"
+
+	set +e
+	OUTPUT=$(git add "$file" 2>&1)
+	if [ $? -ne 0 ]; then
+		set -e
+		touch "$destdir/$file.fail"
+		if [ "${OUTPUT:0:38}" == "fatal: CRLF would be replaced by LF in" ]; then
+			echo "CRLF would be replaced by LF" > "$destdir/$file.fail"
+		elif [ "${OUTPUT:0:38}" == "fatal: LF would be replaced by CRLF in" ]; then
+			echo "LF would be replaced by CRLF" > "$destdir/$file.fail"
+		fi
+	else
+		OBJ=$(git ls-files -s | cut -d ' ' -f 2)
+ 		set -e
+		echo "$OBJ" > "$destdir/$file.obj"
+	fi
+	rm -f .git/index
+}
+
+export LC_ALL=C
+
+for safecrlf in true false warn; do
+	for autocrlf in true false input; do
+		for attr in "" text text=auto -text crlf -crlf eol=lf eol=crlf \
+			"text eol=lf" "text eol=crlf" \
+			"text=auto eol=lf" "text=auto eol=crlf"; do
+	
+			create_test_data "${input}" "${output}" "${tempdir}" \
+				"${safecrlf}" "${autocrlf}" "${attr}"
+		done
+	done
+done