Merge branch 'js/mingw-isatty'
[gitweb.git] / t / t0021-conversion.sh
index a20b9f58e3fe1de2932046d5d7f692b45e3ac854..4ea534e9fa70ea302d4a88a8bc922c100f896873 100755 (executable)
@@ -4,15 +4,17 @@ test_description='blob conversion via gitattributes'
 
 . ./test-lib.sh
 
-TEST_ROOT="$(pwd)"
+TEST_ROOT="$PWD"
+PATH=$TEST_ROOT:$PATH
 
-cat <<EOF >"$TEST_ROOT/rot13.sh"
-#!$SHELL_PATH
+write_script <<\EOF "$TEST_ROOT/rot13.sh"
 tr \
   'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
   'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
 EOF
-chmod +x "$TEST_ROOT/rot13.sh"
+
+write_script rot13-filter.pl "$PERL_PATH" \
+       <"$TEST_DIRECTORY"/t0021/rot13-filter.pl
 
 generate_random_characters () {
        LEN=$1
@@ -22,13 +24,12 @@ generate_random_characters () {
 }
 
 file_size () {
-       cat "$1" | wc -c | sed "s/^[ ]*//"
+       perl -e 'print -s $ARGV[0]' "$1"
 }
 
 filter_git () {
        rm -f rot13-filter.log &&
-       git "$@" 2>git-stderr.log &&
-       rm -f git-stderr.log
+       git "$@"
 }
 
 # Compare two files and ensure that `clean` and `smudge` respectively are
@@ -40,10 +41,9 @@ test_cmp_count () {
        actual=$2
        for FILE in "$expect" "$actual"
        do
-               sort "$FILE" | uniq -c | sed "s/^[ ]*//" |
-                       sed "s/^\([0-9]\) IN: clean/x IN: clean/" |
-                       sed "s/^\([0-9]\) IN: smudge/x IN: smudge/" >"$FILE.tmp" &&
-               mv "$FILE.tmp" "$FILE"
+               sort "$FILE" | uniq -c |
+               sed -e "s/^ *[0-9][0-9]*[       ]*IN: /x IN: /" >"$FILE.tmp" &&
+               mv "$FILE.tmp" "$FILE" || return
        done &&
        test_cmp "$expect" "$actual"
 }
@@ -66,7 +66,7 @@ test_cmp_exclude_clean () {
 # is equal to the committed content.
 test_cmp_committed_rot13 () {
        test_cmp "$1" "$2" &&
-       "$TEST_ROOT/rot13.sh" <"$1" >expected &&
+       rot13.sh <"$1" >expected &&
        git cat-file blob :"$2" >actual &&
        test_cmp expected actual
 }
@@ -342,7 +342,7 @@ test_expect_success 'diff does not reuse worktree files that need cleaning' '
 '
 
 test_expect_success PERL 'required process filter should filter data' '
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
        test_config_global filter.protocol.required true &&
        rm -rf repo &&
        mkdir repo &&
@@ -435,7 +435,7 @@ test_expect_success PERL 'required process filter should filter data' '
 
 test_expect_success PERL 'required process filter takes precedence' '
        test_config_global filter.protocol.clean false &&
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean" &&
        test_config_global filter.protocol.required true &&
        rm -rf repo &&
        mkdir repo &&
@@ -460,7 +460,7 @@ test_expect_success PERL 'required process filter takes precedence' '
 '
 
 test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean" &&
        rm -rf repo &&
        mkdir repo &&
        (
@@ -495,7 +495,7 @@ test_expect_success PERL 'required process filter should be used only for "clean
 '
 
 test_expect_success PERL 'required process filter should process multiple packets' '
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
        test_config_global filter.protocol.required true &&
 
        rm -rf repo &&
@@ -515,7 +515,7 @@ test_expect_success PERL 'required process filter should process multiple packet
                for FILE in "$TEST_ROOT"/*.file
                do
                        cp "$FILE" . &&
-                       "$TEST_ROOT/rot13.sh" <"$FILE" >"$FILE.rot13"
+                       rot13.sh <"$FILE" >"$FILE.rot13"
                done &&
 
                echo "*.file filter=protocol" >.gitattributes &&
@@ -555,7 +555,7 @@ test_expect_success PERL 'required process filter should process multiple packet
 '
 
 test_expect_success PERL 'required process filter with clean error should fail' '
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
        test_config_global filter.protocol.required true &&
        rm -rf repo &&
        mkdir repo &&
@@ -574,7 +574,7 @@ test_expect_success PERL 'required process filter with clean error should fail'
 '
 
 test_expect_success PERL 'process filter should restart after unexpected write failure' '
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
        rm -rf repo &&
        mkdir repo &&
        (
@@ -618,14 +618,14 @@ test_expect_success PERL 'process filter should restart after unexpected write f
 
                # Smudge failed
                ! test_cmp smudge-write-fail.o smudge-write-fail.r &&
-               "$TEST_ROOT/rot13.sh" <smudge-write-fail.o >expected &&
+               rot13.sh <smudge-write-fail.o >expected &&
                git cat-file blob :smudge-write-fail.r >actual &&
                test_cmp expected actual
        )
 '
 
 test_expect_success PERL 'process filter should not be restarted if it signals an error' '
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
        rm -rf repo &&
        mkdir repo &&
        (
@@ -664,7 +664,7 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
 '
 
 test_expect_success PERL 'process filter abort stops processing of all further files' '
-       test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
+       test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
        rm -rf repo &&
        mkdir repo &&
        (