Merge branch 'jk/wrap-perl-used-in-tests'
authorJunio C Hamano <gitster@pobox.com>
Mon, 4 Nov 2013 22:58:01 +0000 (14:58 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 4 Nov 2013 22:58:02 +0000 (14:58 -0800)
* jk/wrap-perl-used-in-tests:
t: use perl instead of "$PERL_PATH" where applicable
t: provide a perl() function which uses $PERL_PATH

1  2 
t/README
t/t5300-pack-object.sh
t/t5551-http-fetch.sh
t/test-lib-functions.sh
diff --combined t/README
index 0a939ebba0ec8bc28375eb52c2f228a23f41601a,06bc5ed8a165116b214bfc6d5680d4f2c8ff6210..caeeb9dedc46940132dceb65f2ea976709945e2d
+++ b/t/README
@@@ -340,7 -340,11 +340,11 @@@ Don't
   - use perl without spelling it as "$PERL_PATH". This is to help our
     friends on Windows where the platform Perl often adds CR before
     the end of line, and they bundle Git with a version of Perl that
-    does not do so, whose path is specified with $PERL_PATH.
+    does not do so, whose path is specified with $PERL_PATH. Note that we
+    provide a "perl" function which uses $PERL_PATH under the hood, so
+    you do not need to worry when simply running perl in the test scripts
+    (but you do, for example, on a shebang line or in a sub script
+    created via "write_script").
  
   - use sh without spelling it as "$SHELL_PATH", when the script can
     be misinterpreted by broken platform shell (e.g. Solaris).
@@@ -387,7 -391,7 +391,7 @@@ of the test_* functions (see the "Test 
  below), e.g.:
  
      test_expect_success PERL 'I need Perl' '
-         "$PERL_PATH" -e "hlagh() if unf_unf()"
+         perl -e "hlagh() if unf_unf()"
      '
  
  The advantage of skipping tests like this is that platforms that don't
@@@ -520,7 -524,7 +524,7 @@@ library for your script to use
  
        test_external \
            'GitwebCache::*FileCache*' \
-           "$PERL_PATH" "$TEST_DIRECTORY"/t9503/test_cache_interface.pl
+           perl "$TEST_DIRECTORY"/t9503/test_cache_interface.pl
  
     If the test is outputting its own TAP you should set the
     test_external_has_tap variable somewhere before calling the first
  
        test_external_without_stderr \
            'Perl API' \
-           "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl
+           perl "$TEST_DIRECTORY"/t9700/test.pl
  
   - test_expect_code <exit-code> <command>
  
@@@ -629,18 -633,11 +633,18 @@@ See the prereq argument to the test_* f
  library" section above and the "test_have_prereq" function for how to
  use these, and "test_set_prereq" for how to define your own.
  
 - - PERL & PYTHON
 + - PYTHON
  
 -   Git wasn't compiled with NO_PERL=YesPlease or
 -   NO_PYTHON=YesPlease. Wrap any tests that need Perl or Python in
 -   these.
 +   Git wasn't compiled with NO_PYTHON=YesPlease. Wrap any tests that
 +   need Python with this.
 +
 + - PERL
 +
 +   Git wasn't compiled with NO_PERL=YesPlease.
 +
 +   Even without the PERL prerequisite, tests can assume there is a
 +   usable perl interpreter at $PERL_PATH, though it need not be
 +   particularly modern.
  
   - POSIXPERM
  
diff --combined t/t5300-pack-object.sh
index 61e787dca121928a191051acc40aefffabbcc0e1,c755c0903dca34a84e92cf4b6f330a2867a61029..20c1961515a02e3411d02a5656bf8a9dc6b198de
@@@ -13,9 -13,9 +13,9 @@@ TRASH=`pwd
  test_expect_success \
      'setup' \
      'rm -f .git/index* &&
-      "$PERL_PATH" -e "print \"a\" x 4096;" > a &&
-      "$PERL_PATH" -e "print \"b\" x 4096;" > b &&
-      "$PERL_PATH" -e "print \"c\" x 4096;" > c &&
+      perl -e "print \"a\" x 4096;" > a &&
+      perl -e "print \"b\" x 4096;" > b &&
+      perl -e "print \"c\" x 4096;" > c &&
       test-genrandom "seed a" 2097152 > a_big &&
       test-genrandom "seed b" 2097152 > b_big &&
       git update-index --add a a_big b b_big c &&
@@@ -129,7 -129,7 +129,7 @@@ test_expect_success 
  cd "$TRASH"
  
  test_expect_success 'compare delta flavors' '
-       "$PERL_PATH" -e '\''
+       perl -e '\''
                defined($_ = -s $_) or die for @ARGV;
                exit 1 if $ARGV[0] <= $ARGV[1];
        '\'' test-2-$packname_2.pack test-3-$packname_3.pack
@@@ -151,7 -151,7 +151,7 @@@ test_expect_success 
            git cat-file $t $object || return 1
         done <obj-list
      } >current &&
 -    test_cmp expect current'
 +    cmp expect current'
  
  test_expect_success \
      'use packed deltified (REF_DELTA) objects' \
            git cat-file $t $object || return 1
         done <obj-list
      } >current &&
 -    test_cmp expect current'
 +    cmp expect current'
  
  test_expect_success \
      'use packed deltified (OFS_DELTA) objects' \
            git cat-file $t $object || return 1
         done <obj-list
      } >current &&
 -    test_cmp expect current'
 +    cmp expect current'
  
  unset GIT_OBJECT_DIRECTORY
  
@@@ -195,9 -195,9 +195,9 @@@ test_expect_success 'survive missing ob
                rm -fr $GOP &&
                git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
                test -f $GOP/pack-${packname_3}.pack &&
 -              test_cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
 +              cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
                test -f $GOP/pack-${packname_3}.idx &&
 -              test_cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
 +              cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
                test -f $GOP/pack-${packname_3}.keep
        )
  '
diff --combined t/t5551-http-fetch.sh
index fb16833f7673ed33cd097b98e4ca91df1a89b135,f036392c295830c66cdb4b0ec37afd623e7d5549..afb439e09c2db4853c6eba88a1e630f319337cf8
@@@ -113,10 -113,6 +113,10 @@@ test_expect_success 'follow redirects (
        git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
  '
  
 +test_expect_success 'redirects re-root further requests' '
 +      git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
 +'
 +
  test_expect_success 'clone from password-protected repository' '
        echo two >expect &&
        set_askpass user@host &&
@@@ -150,13 -146,6 +150,13 @@@ test_expect_success 'no-op half-auth fe
        expect_askpass none
  '
  
 +test_expect_success 'redirects send auth to new location' '
 +      set_askpass user@host &&
 +      git -c credential.useHttpPath=true \
 +        clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
 +      expect_askpass both user@host auth/smart/repo.git
 +'
 +
  test_expect_success 'disable dumb http on server' '
        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
                config http.getanyfile false
@@@ -235,7 -224,7 +235,7 @@@ test_expect_success EXPENSIVE 'create 5
        done | git fast-import --export-marks=marks &&
  
        # now assign tags to all the dangling commits we created above
-       tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
+       tag=$(perl -e "print \"bla\" x 30") &&
        sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
        )
  '
diff --combined t/test-lib-functions.sh
index f98769427b51017db7b9d757fd12e582609dbb03,bb878f3b1e14bd595693c51a473988b4534f8389..2f79146e6ce0c5df32845f7c9c0927cea133ad5f
@@@ -76,11 -76,11 +76,11 @@@ test_decode_color () 
  }
  
  nul_to_q () {
-       "$PERL_PATH" -pe 'y/\000/Q/'
+       perl -pe 'y/\000/Q/'
  }
  
  q_to_nul () {
-       "$PERL_PATH" -pe 'y/Q/\000/'
+       perl -pe 'y/Q/\000/'
  }
  
  q_to_cr () {
@@@ -648,7 -648,7 +648,7 @@@ test_seq () 
        2)      ;;
        *)      error "bug in the test script: not 1 or 2 parameters to test_seq" ;;
        esac
-       "$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' -- "$@"
+       perl -le 'print for $ARGV[0]..$ARGV[1]' -- "$@"
  }
  
  # This function can be used to schedule some commands to be run
@@@ -711,68 -711,6 +711,72 @@@ test_ln_s_add () 
        fi
  }
  
+ perl () {
+       command "$PERL_PATH" "$@"
+ }
++
 +# The following mingw_* functions obey POSIX shell syntax, but are actually
 +# bash scripts, and are meant to be used only with bash on Windows.
 +
 +# A test_cmp function that treats LF and CRLF equal and avoids to fork
 +# diff when possible.
 +mingw_test_cmp () {
 +      # Read text into shell variables and compare them. If the results
 +      # are different, use regular diff to report the difference.
 +      local test_cmp_a= test_cmp_b=
 +
 +      # When text came from stdin (one argument is '-') we must feed it
 +      # to diff.
 +      local stdin_for_diff=
 +
 +      # Since it is difficult to detect the difference between an
 +      # empty input file and a failure to read the files, we go straight
 +      # to diff if one of the inputs is empty.
 +      if test -s "$1" && test -s "$2"
 +      then
 +              # regular case: both files non-empty
 +              mingw_read_file_strip_cr_ test_cmp_a <"$1"
 +              mingw_read_file_strip_cr_ test_cmp_b <"$2"
 +      elif test -s "$1" && test "$2" = -
 +      then
 +              # read 2nd file from stdin
 +              mingw_read_file_strip_cr_ test_cmp_a <"$1"
 +              mingw_read_file_strip_cr_ test_cmp_b
 +              stdin_for_diff='<<<"$test_cmp_b"'
 +      elif test "$1" = - && test -s "$2"
 +      then
 +              # read 1st file from stdin
 +              mingw_read_file_strip_cr_ test_cmp_a
 +              mingw_read_file_strip_cr_ test_cmp_b <"$2"
 +              stdin_for_diff='<<<"$test_cmp_a"'
 +      fi
 +      test -n "$test_cmp_a" &&
 +      test -n "$test_cmp_b" &&
 +      test "$test_cmp_a" = "$test_cmp_b" ||
 +      eval "diff -u \"\$@\" $stdin_for_diff"
 +}
 +
 +# $1 is the name of the shell variable to fill in
 +mingw_read_file_strip_cr_ () {
 +      # Read line-wise using LF as the line separator
 +      # and use IFS to strip CR.
 +      local line
 +      while :
 +      do
 +              if IFS=$'\r' read -r -d $'\n' line
 +              then
 +                      # good
 +                      line=$line$'\n'
 +              else
 +                      # we get here at EOF, but also if the last line
 +                      # was not terminated by LF; in the latter case,
 +                      # some text was read
 +                      if test -z "$line"
 +                      then
 +                              # EOF, really
 +                              break
 +                      fi
 +              fi
 +              eval "$1=\$$1\$line"
 +      done
 +}