tests: add information about the crlf data generator The CRLF data generator is somewhat obscure; add information about how to use it and what it does.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
diff --git a/tests/generate_crlf.sh b/tests/generate_crlf.sh
deleted file mode 100644
index d3fd1bb..0000000
--- a/tests/generate_crlf.sh
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-if [ "$1" == "" -o "$2" == "" ]; then
- echo "usage: $0 crlfrepo directory [tempdir]"
- exit 1
-fi
-
-input=$1
-output=$2
-tempdir=$3
-
-set -u
-
-create_repo() {
- local input=$1
- local output=$2
- local tempdir=$3
- local systype=$4
- local autocrlf=$5
- local attr=$6
-
- local worktree="${output}/${systype}/autocrlf_${autocrlf}"
-
- if [ "$attr" != "" ]; then
- local attrdir=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
- worktree="${worktree},${attrdir}"
- fi
-
- if [ "$tempdir" = "" ]; then
- local gitdir="${worktree}/.git"
- else
- local gitdir="${tempdir}/generate_crlf_${RANDOM}"
- fi
-
- echo "Creating ${worktree}"
- mkdir -p "${worktree}"
-
- git clone --no-checkout --quiet --bare "${input}/.gitted" "${gitdir}"
- git --work-tree="${worktree}" --git-dir="${gitdir}" config core.autocrlf ${autocrlf}
-
- if [ "$attr" != "" ]; then
- echo "* ${attr}" >> "${worktree}/.gitattributes"
- fi
-
- git --work-tree="${worktree}" --git-dir="${gitdir}" checkout HEAD
-
- if [ "$attr" != "" ]; then
- rm "${worktree}/.gitattributes"
- fi
-
- if [ "$tempdir" != "" ]; then
- rm -rf "${gitdir}"
- fi
-}
-
-if [[ `uname -s` == MINGW* ]]; then
- systype="windows"
-else
- systype="posix"
-fi
-
-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_repo "${input}" "${output}" "${tempdir}" \
- "${systype}" "${autocrlf}" "${attr}"
- done
-done
-
diff --git a/tests/resources/crlf_data/README b/tests/resources/crlf_data/README
new file mode 100644
index 0000000..2347e12
--- /dev/null
+++ b/tests/resources/crlf_data/README
@@ -0,0 +1,2 @@
+This test data was generated using the `tests/resources/generate_crlf.sh`
+script. Please see that script for usage information.
diff --git a/tests/resources/generate_crlf.sh b/tests/resources/generate_crlf.sh
new file mode 100755
index 0000000..7053454
--- /dev/null
+++ b/tests/resources/generate_crlf.sh
@@ -0,0 +1,85 @@
+#!/usr/bin/env bash
+#
+# This script will generate the test corpus for CR/LF data using git;
+# we create 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). 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
+# sh ./generate_crlf.sh ./crlf ./crlf_data /tmp/crlf_gitdirs
+# git add ./crlf_data
+
+set -e
+
+if [ "$1" == "" -o "$2" == "" ]; then
+ echo "usage: $0 crlfrepo directory [tempdir]"
+ exit 1
+fi
+
+input=$1
+output=$2
+tempdir=$3
+
+set -u
+
+create_repo() {
+ local input=$1
+ local output=$2
+ local tempdir=$3
+ local systype=$4
+ local autocrlf=$5
+ local attr=$6
+
+ local worktree="${output}/${systype}/autocrlf_${autocrlf}"
+
+ if [ "$attr" != "" ]; then
+ local attrdir=`echo $attr | sed -e "s/ /,/g" | sed -e "s/=/_/g"`
+ worktree="${worktree},${attrdir}"
+ fi
+
+ if [ "$tempdir" = "" ]; then
+ local gitdir="${worktree}/.git"
+ else
+ local gitdir="${tempdir}/generate_crlf_${RANDOM}"
+ fi
+
+ echo "Creating ${worktree}"
+ mkdir -p "${worktree}"
+
+ git clone --no-checkout --quiet --bare "${input}/.gitted" "${gitdir}"
+ git --work-tree="${worktree}" --git-dir="${gitdir}" config core.autocrlf ${autocrlf}
+
+ if [ "$attr" != "" ]; then
+ echo "* ${attr}" >> "${worktree}/.gitattributes"
+ fi
+
+ git --work-tree="${worktree}" --git-dir="${gitdir}" checkout HEAD
+
+ if [ "$attr" != "" ]; then
+ rm "${worktree}/.gitattributes"
+ fi
+
+ if [ "$tempdir" != "" ]; then
+ rm -rf "${gitdir}"
+ fi
+}
+
+if [[ `uname -s` == MINGW* ]]; then
+ systype="windows"
+else
+ systype="posix"
+fi
+
+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_repo "${input}" "${output}" "${tempdir}" \
+ "${systype}" "${autocrlf}" "${attr}"
+ done
+done
+