Merge branch 'rr/test-make-sure-we-have-git'
authorJunio C Hamano <gitster@pobox.com>
Tue, 25 Sep 2012 17:40:24 +0000 (10:40 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Sep 2012 17:40:24 +0000 (10:40 -0700)
Only the first test t0000 in the test suite made sure we have built
Git to be tested; move the check to test-lib so that it applies to
all tests equally.

* rr/test-make-sure-we-have-git:
t/test-lib: make sure Git has already been built

1  2 
t/t0000-basic.sh
t/test-lib.sh
diff --combined t/t0000-basic.sh
index ae6a3f077742c0504b8ed8f56b98289c704ce8f9,741b6b6d166ed5b59917d010f777b8f54d0928cc..08677df10e9d2a4c87fbe1e5d24eb836b1117e64
@@@ -18,16 -18,6 +18,6 @@@ swapping compression and hashing order
  modification *should* take notice and update the test vectors here.
  '
  
- ################################################################
- # It appears that people try to run tests without building...
- ../git >/dev/null
- if test $? != 1
- then
-       echo >&2 'You do not seem to have built git yet.'
-       exit 1
- fi
  . ./test-lib.sh
  
  ################################################################
@@@ -450,6 -440,24 +440,6 @@@ test_expect_success 'update-index D/F c
        test $numpath0 = 1
  '
  
 -test_expect_success SYMLINKS 'real path works as expected' '
 -      mkdir first &&
 -      ln -s ../.git first/.git &&
 -      mkdir second &&
 -      ln -s ../first second/other &&
 -      mkdir third &&
 -      dir="$(cd .git; pwd -P)" &&
 -      dir2=third/../second/other/.git &&
 -      test "$dir" = "$(test-path-utils real_path $dir2)" &&
 -      file="$dir"/index &&
 -      test "$file" = "$(test-path-utils real_path $dir2/index)" &&
 -      basename=blub &&
 -      test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" &&
 -      ln -s ../first/file .git/syml &&
 -      sym="$(cd first; pwd -P)"/file &&
 -      test "$sym" = "$(test-path-utils real_path "$dir2/syml")"
 -'
 -
  test_expect_success 'very long name in the index handled sanely' '
  
        a=a && # 1
diff --combined t/test-lib.sh
index aad46066adf0021b721bb3a2e235e2b012f13422,e823d86e415226680299fdd4ad487bd45b9d3bed..bff3d7570c675c7b6fbc71342909b0a930aae1a0
@@@ -51,6 -51,15 +51,15 @@@ the
  fi
  GIT_BUILD_DIR="$TEST_DIRECTORY"/..
  
+ ################################################################
+ # It appears that people try to run tests without building...
+ "$GIT_BUILD_DIR/git" >/dev/null
+ if test $? != 1
+ then
+       echo >&2 'error: you do not seem to have built git yet.'
+       exit 1
+ fi
  . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
  export PERL_PATH SHELL_PATH
  
@@@ -93,27 -102,6 +102,27 @@@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAM
  export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
  export EDITOR
  
 +# Add libc MALLOC and MALLOC_PERTURB test
 +# only if we are not executing the test with valgrind
 +if expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null ||
 +   test -n "TEST_NO_MALLOC_"
 +then
 +      setup_malloc_check () {
 +              : nothing
 +      }
 +      teardown_malloc_check () {
 +              : nothing
 +      }
 +else
 +      setup_malloc_check () {
 +              MALLOC_CHECK_=3 MALLOC_PERTURB_=165
 +              export MALLOC_CHECK_ MALLOC_PERTURB_
 +      }
 +      teardown_malloc_check () {
 +              unset MALLOC_CHECK_ MALLOC_PERTURB_
 +      }
 +fi
 +
  # Protect ourselves from common misconfiguration to export
  # CDPATH into the environment
  unset CDPATH
  unset GREP_OPTIONS
  
  case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
 -      1|2|true)
 -              echo "* warning: Some tests will not work if GIT_TRACE" \
 -                      "is set as to trace on STDERR ! *"
 -              echo "* warning: Please set GIT_TRACE to something" \
 -                      "other than 1, 2 or true ! *"
 -              ;;
 +1|2|true)
 +      echo "* warning: Some tests will not work if GIT_TRACE" \
 +              "is set as to trace on STDERR ! *"
 +      echo "* warning: Please set GIT_TRACE to something" \
 +              "other than 1, 2 or true ! *"
 +      ;;
  esac
  
  # Convenience
        esac
  done
  
 -if test -n "$color"; then
 +if test -n "$color"
 +then
        say_color () {
                (
                TERM=$ORIGINAL_TERM
                export TERM
                case "$1" in
 -                      error) tput bold; tput setaf 1;; # bold red
 -                      skip)  tput bold; tput setaf 2;; # bold green
 -                      pass)  tput setaf 2;;            # green
 -                      info)  tput setaf 3;;            # brown
 -                      *) test -n "$quiet" && return;;
 +              error)
 +                      tput bold; tput setaf 1;; # bold red
 +              skip)
 +                      tput bold; tput setaf 2;; # bold green
 +              pass)
 +                      tput setaf 2;;            # green
 +              info)
 +                      tput setaf 3;;            # brown
 +              *)
 +                      test -n "$quiet" && return;;
                esac
                shift
                printf "%s" "$*"
@@@ -323,12 -305,9 +332,12 @@@ test_run_ () 
  
        if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
        then
 +              setup_malloc_check
                test_eval_ "$test_cleanup"
 +              teardown_malloc_check
        fi
 -      if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then
 +      if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
 +      then
                echo ""
        fi
        return "$eval_ret"
@@@ -376,8 -355,7 +385,8 @@@ test_at_end_hook_ () 
  test_done () {
        GIT_EXIT_OK=t
  
 -      if test -z "$HARNESS_ACTIVE"; then
 +      if test -z "$HARNESS_ACTIVE"
 +      then
                test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"
                mkdir -p "$test_results_dir"
                test_results_path="$test_results_dir/${0%.sh}-$$.counts"
        case "$test_failure" in
        0)
                # Maybe print SKIP message
 +              if test -n "$skip_all" && test $test_count -gt 0
 +              then
 +                      error "Can't use skip_all after running some tests"
 +              fi
                [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all"
  
 -              if test $test_external_has_tap -eq 0; then
 -                      say_color pass "# passed all $msg"
 +              if test $test_external_has_tap -eq 0
 +              then
 +                      if test $test_count -gt 0
 +                      then
 +                              say_color pass "# passed all $msg"
 +                      fi
                        say "1..$test_count$skip_all"
                fi
  
                exit 0 ;;
  
        *)
 -              if test $test_external_has_tap -eq 0; then
 +              if test $test_external_has_tap -eq 0
 +              then
                        say_color error "# failed $test_failure among $msg"
                        say "1..$test_count"
                fi
@@@ -511,26 -480,22 +520,26 @@@ the
        PATH=$GIT_VALGRIND/bin:$PATH
        GIT_EXEC_PATH=$GIT_VALGRIND/bin
        export GIT_VALGRIND
 -elif test -n "$GIT_TEST_INSTALLED" ; then
 +elif test -n "$GIT_TEST_INSTALLED"
 +then
        GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)  ||
        error "Cannot run git from $GIT_TEST_INSTALLED."
        PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH
        GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
  else # normal case, use ../bin-wrappers only unless $with_dashes:
        git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
 -      if ! test -x "$git_bin_dir/git" ; then
 -              if test -z "$with_dashes" ; then
 +      if ! test -x "$git_bin_dir/git"
 +      then
 +              if test -z "$with_dashes"
 +              then
                        say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
                fi
                with_dashes=t
        fi
        PATH="$git_bin_dir:$PATH"
        GIT_EXEC_PATH=$GIT_BUILD_DIR
 -      if test -n "$with_dashes" ; then
 +      if test -n "$with_dashes"
 +      then
                PATH="$GIT_BUILD_DIR:$PATH"
        fi
  fi
@@@ -565,8 -530,7 +574,8 @@@ the
        }
  fi
  
 -if ! test -x "$GIT_BUILD_DIR"/test-chmtime; then
 +if ! test -x "$GIT_BUILD_DIR"/test-chmtime
 +then
        echo >&2 'You need to build test-chmtime:'
        echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
        exit 1
@@@ -589,8 -553,7 +598,8 @@@ rm -fr "$test" || 
  HOME="$TRASH_DIRECTORY"
  export HOME
  
 -if test -z "$TEST_NO_CREATE_REPO"; then
 +if test -z "$TEST_NO_CREATE_REPO"
 +then
        test_create_repo "$test"
  else
        mkdir -p "$test"