Merge branch 'jc/test-seq' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 26 May 2016 20:17:16 +0000 (13:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 May 2016 20:17:16 +0000 (13:17 -0700)
Test fix.

* jc/test-seq:
test-lib-functions.sh: rewrite test_seq without Perl
test-lib-functions.sh: remove misleading comment on test_seq

1  2 
t/test-lib-functions.sh
diff --combined t/test-lib-functions.sh
index 8d99eb303fd62a1c179ab31f471a3376898586b0,9734e322223c77c558d6198ab4a7ce56742839fd..3978fc0b45de2645560207cc6e884a505506215d
@@@ -145,14 -145,6 +145,14 @@@ test_pause () 
        fi
  }
  
 +# Wrap git in gdb. Adding this to a command can make it easier to
 +# understand what is going on in a failing test.
 +#
 +# Example: "debug git checkout master".
 +debug () {
 +       GIT_TEST_GDB=1 "$@"
 +}
 +
  # Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
  #
  # This will commit a file with the given contents and the given commit
@@@ -209,14 -201,7 +209,14 @@@ test_chmod () 
  
  # Unset a configuration variable, but don't fail if it doesn't exist.
  test_unconfig () {
 -      git config --unset-all "$@"
 +      config_dir=
 +      if test "$1" = -C
 +      then
 +              shift
 +              config_dir=$1
 +              shift
 +      fi
 +      git ${config_dir:+-C "$config_dir"} config --unset-all "$@"
        config_status=$?
        case "$config_status" in
        5) # ok, nothing to unset
  
  # Set git config, automatically unsetting it after the test is over.
  test_config () {
 -      test_when_finished "test_unconfig '$1'" &&
 -      git config "$@"
 +      config_dir=
 +      if test "$1" = -C
 +      then
 +              shift
 +              config_dir=$1
 +              shift
 +      fi
 +      test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" &&
 +      git ${config_dir:+-C "$config_dir"} config "$@"
  }
  
  test_config_global () {
@@@ -370,18 -348,11 +370,18 @@@ test_declared_prereq () 
        return 1
  }
  
 +test_verify_prereq () {
 +      test -z "$test_prereq" ||
 +      expr >/dev/null "$test_prereq" : '[A-Z0-9_,!]*$' ||
 +      error "bug in the test script: '$test_prereq' does not look like a prereq"
 +}
 +
  test_expect_failure () {
        test_start_
        test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
        test "$#" = 2 ||
        error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
 +      test_verify_prereq
        export test_prereq
        if ! test_skip "$@"
        then
@@@ -401,7 -372,6 +401,7 @@@ test_expect_success () 
        test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
        test "$#" = 2 ||
        error "bug in the test script: not 2 or 3 parameters to test-expect-success"
 +      test_verify_prereq
        export test_prereq
        if ! test_skip "$@"
        then
@@@ -430,7 -400,6 +430,7 @@@ test_external () 
        error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
        descr="$1"
        shift
 +      test_verify_prereq
        export test_prereq
        if ! test_skip "$descr" "$@"
        then
@@@ -569,21 -538,6 +569,21 @@@ test_line_count () 
        fi
  }
  
 +# Returns success if a comma separated string of keywords ($1) contains a
 +# given keyword ($2).
 +# Examples:
 +# `list_contains "foo,bar" bar` returns 0
 +# `list_contains "foo" bar` returns 1
 +
 +list_contains () {
 +      case ",$1," in
 +      *,$2,*)
 +              return 0
 +              ;;
 +      esac
 +      return 1
 +}
 +
  # This is not among top-level (test_expect_success | test_expect_failure)
  # but is a prefix that can be used in the test script, like:
  #
  # the failure could be due to a segv.  We want a controlled failure.
  
  test_must_fail () {
 +      case "$1" in
 +      ok=*)
 +              _test_ok=${1#ok=}
 +              shift
 +              ;;
 +      *)
 +              _test_ok=
 +              ;;
 +      esac
        "$@"
        exit_code=$?
 -      if test $exit_code = 0; then
 +      if test $exit_code -eq 0 && ! list_contains "$_test_ok" success
 +      then
                echo >&2 "test_must_fail: command succeeded: $*"
                return 1
 -      elif test $exit_code -gt 129 && test $exit_code -le 192; then
 -              echo >&2 "test_must_fail: died by signal: $*"
 +      elif test $exit_code -eq 141 && list_contains "$_test_ok" sigpipe
 +      then
 +              return 0
 +      elif test $exit_code -gt 129 && test $exit_code -le 192
 +      then
 +              echo >&2 "test_must_fail: died by signal $(($exit_code - 128)): $*"
                return 1
 -      elif test $exit_code = 127; then
 +      elif test $exit_code -eq 127
 +      then
                echo >&2 "test_must_fail: command not found: $*"
                return 1
 -      elif test $exit_code = 126; then
 +      elif test $exit_code -eq 126
 +      then
                echo >&2 "test_must_fail: valgrind error: $*"
                return 1
        fi
  # because we want to notice if it fails due to segv.
  
  test_might_fail () {
 -      "$@"
 -      exit_code=$?
 -      if test $exit_code -gt 129 && test $exit_code -le 192; then
 -              echo >&2 "test_might_fail: died by signal: $*"
 -              return 1
 -      elif test $exit_code = 127; then
 -              echo >&2 "test_might_fail: command not found: $*"
 -              return 1
 -      fi
 -      return 0
 +      test_must_fail ok=success "$@"
  }
  
  # Similar to test_must_fail and test_might_fail, but check that a
@@@ -718,20 -665,13 +718,13 @@@ test_cmp_rev () 
        test_cmp expect.rev actual.rev
  }
  
- # Print a sequence of numbers or letters in increasing order.  This is
- # similar to GNU seq(1), but the latter might not be available
- # everywhere (and does not do letters).  It may be used like:
+ # Print a sequence of integers in increasing order, either with
+ # two arguments (start and end):
  #
- #     for i in $(test_seq 100)
- #     do
- #             for j in $(test_seq 10 20)
- #             do
- #                     for k in $(test_seq a z)
- #                     do
- #                             echo $i-$j-$k
- #                     done
- #             done
- #     done
+ #     test_seq 1 5 -- outputs 1 2 3 4 5 one line at a time
+ #
+ # or with one argument (end), in which case it starts counting
+ # from 1.
  
  test_seq () {
        case $# in
        2)      ;;
        *)      error "bug in the test script: not 1 or 2 parameters to test_seq" ;;
        esac
-       perl -le 'print for $ARGV[0]..$ARGV[1]' -- "$@"
+       test_seq_counter__=$1
+       while test "$test_seq_counter__" -le "$2"
+       do
+               echo "$test_seq_counter__"
+               test_seq_counter__=$(( $test_seq_counter__ + 1 ))
+       done
  }
  
  # This function can be used to schedule some commands to be run
  # what went wrong.
  
  test_when_finished () {
 +      # We cannot detect when we are in a subshell in general, but by
 +      # doing so on Bash is better than nothing (the test will
 +      # silently pass on other shells).
 +      test "${BASH_SUBSHELL-0}" = 0 ||
 +      error "bug in test script: test_when_finished does nothing in a subshell"
        test_cleanup="{ $*
                } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
  }