]> rtime.felk.cvut.cz Git - git.git/commitdiff
Merge branch 'jn/t7006-fixup'
authorJunio C Hamano <gitster@pobox.com>
Fri, 21 May 2010 11:02:20 +0000 (04:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 May 2010 11:02:20 +0000 (04:02 -0700)
* jn/t7006-fixup:
  t7006: guard cleanup with test_expect_success

1  2 
t/test-lib.sh

diff --combined t/test-lib.sh
index 7422bba47e75e00073779e4b2d7a162862cdb426,a596f2aa023d57ed6f0624c150ffc5635be7cd6b..9bfa14be7f1c3935013d04318eeaecc68b4ef88c
@@@ -2,18 -2,6 +2,18 @@@
  #
  # Copyright (c) 2005 Junio C Hamano
  #
 +# This program is free software: you can redistribute it and/or modify
 +# it under the terms of the GNU General Public License as published by
 +# the Free Software Foundation, either version 2 of the License, or
 +# (at your option) any later version.
 +#
 +# This program is distributed in the hope that it will be useful,
 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +# GNU General Public License for more details.
 +#
 +# You should have received a copy of the GNU General Public License
 +# along with this program.  If not, see http://www.gnu.org/licenses/ .
  
  # if --tee was passed, write the output not only to the terminal, but
  # additionally to the file test-results/$BASENAME.out, too.
@@@ -66,10 -54,6 +66,10 @@@ unset GIT_OBJECT_DIRECTOR
  unset GIT_CEILING_DIRECTORIES
  unset SHA1_FILE_DIRECTORIES
  unset SHA1_FILE_DIRECTORY
 +unset GIT_NOTES_REF
 +unset GIT_NOTES_DISPLAY_REF
 +unset GIT_NOTES_REWRITE_REF
 +unset GIT_NOTES_REWRITE_MODE
  GIT_MERGE_VERBOSITY=5
  export GIT_MERGE_VERBOSITY
  export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
@@@ -366,10 -350,8 +366,10 @@@ test_debug () 
  }
  
  test_run_ () {
 +      test_cleanup=:
        eval >&3 2>&4 "$1"
 -      eval_ret="$?"
 +      eval_ret=$?
 +      eval >&3 2>&4 "$test_cleanup"
        return 0
  }
  
@@@ -530,6 -512,22 +530,22 @@@ test_must_fail () 
        test $? -gt 0 -a $? -le 129 -o $? -gt 192
  }
  
+ # Similar to test_must_fail, but tolerates success, too.  This is
+ # meant to be used in contexts like:
+ #
+ #     test_expect_success 'some command works without configuration' '
+ #             test_might_fail git config --unset all.configuration &&
+ #             do something
+ #     '
+ #
+ # Writing "git config --unset all.configuration || :" would be wrong,
+ # because we want to notice if it fails due to segv.
+ test_might_fail () {
+       "$@"
+       test $? -ge 0 -a $? -le 129 -o $? -gt 192
+ }
  # test_cmp is a helper function to compare actual and expected output.
  # You can use it like:
  #
@@@ -547,31 -545,6 +563,31 @@@ test_cmp() 
        $GIT_TEST_CMP "$@"
  }
  
 +# This function can be used to schedule some commands to be run
 +# unconditionally at the end of the test to restore sanity:
 +#
 +#     test_expect_success 'test core.capslock' '
 +#             git config core.capslock true &&
 +#             test_when_finished "git config --unset core.capslock" &&
 +#             hello world
 +#     '
 +#
 +# That would be roughly equivalent to
 +#
 +#     test_expect_success 'test core.capslock' '
 +#             git config core.capslock true &&
 +#             hello world
 +#             git config --unset core.capslock
 +#     '
 +#
 +# except that the greeting and config --unset must both succeed for
 +# the test to pass.
 +
 +test_when_finished () {
 +      test_cleanup="{ $*
 +              } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
 +}
 +
  # Most tests can use the created repository, but some may need to create more.
  # Usage: test_create_repo <directory>
  test_create_repo () {