Merge branch 'jk/filter-process-fix'
authorJunio C Hamano <gitster@pobox.com>
Thu, 10 Nov 2016 21:17:30 +0000 (13:17 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Nov 2016 21:17:30 +0000 (13:17 -0800)
Test portability improvements and cleanups for t0021.

* jk/filter-process-fix:
t0021: fix filehandle usage on older perl
t0021: use $PERL_PATH for rot13-filter.pl
t0021: put $TEST_ROOT in $PATH
t0021: use write_script to create rot13 shell script

1  2 
t/t0021-conversion.sh
diff --combined t/t0021-conversion.sh
index cb72fa49deb1bc51acd53e01dc980fbb806c67bd,a8fa52148d479ba6d9e5b1078693e720dc05e5e0..9ff502773d07819b43d027a0a1ee0fdf98f77e93
@@@ -5,14 -5,16 +5,16 @@@ test_description='blob conversion via g
  . ./test-lib.sh
  
  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,7 -24,7 +24,7 @@@
  }
  
  file_size () {
 -      cat "$1" | wc -c | sed "s/^[ ]*//"
 +      perl -e 'print -s $ARGV[0]' "$1"
  }
  
  filter_git () {
@@@ -40,9 -42,10 +42,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"
  }
@@@ -65,7 -68,7 +67,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
  }
@@@ -341,7 -344,7 +343,7 @@@ test_expect_success 'diff does not reus
  '
  
  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 &&
  
  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 &&
  '
  
  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 &&
        (
  '
  
  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 &&
                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 &&
  '
  
  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 &&
  '
  
  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 &&
        (
  
                # 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 &&
        (
  '
  
  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 &&
        (