Merge branch 'dl/test-must-fail-fixes-6' into master

Dev support to limit the use of test_must_fail to only git commands.

* dl/test-must-fail-fixes-6:
  test-lib-functions: restrict test_must_fail usage
  t9400: don't use test_must_fail with cvs
  t9834: remove use of `test_might_fail p4`
  t7107: don't use test_must_fail()
  t5324: reorder `run_with_limited_open_files test_might_fail`
  t3701: stop using `env` in force_color()
This commit is contained in:
Junio C Hamano 2020-07-30 13:20:32 -07:00
Родитель c28a2d0c12 6a67c75948
Коммит e163cff400
7 изменённых файлов: 86 добавлений и 7 удалений

Просмотреть файл

@ -1271,4 +1271,22 @@ test_expect_success 'very long name in the index handled sanely' '
test $len = 4098
'
test_expect_success 'test_must_fail on a failing git command' '
test_must_fail git notacommand
'
test_expect_success 'test_must_fail on a failing git command with env' '
test_must_fail env var1=a var2=b git notacommand
'
test_expect_success 'test_must_fail rejects a non-git command' '
! test_must_fail grep ^$ notafile 2>err &&
grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
'
test_expect_success 'test_must_fail rejects a non-git command with env' '
! test_must_fail env var1=a var2=b grep ^$ notafile 2>err &&
grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
'
test_done

Просмотреть файл

@ -31,7 +31,16 @@ diff_cmp () {
# indicates a dumb terminal, so we set that variable, too.
force_color () {
env GIT_PAGER_IN_USE=true TERM=vt100 "$@"
# The first element of $@ may be a shell function, as a result POSIX
# does not guarantee that "one-shot assignment" will not persist after
# the function call. Thus, we prevent these variables from escaping
# this function's context with this subshell.
(
GIT_PAGER_IN_USE=true &&
TERM=vt100 &&
export GIT_PAGER_IN_USE TERM &&
"$@"
)
}
test_expect_success 'setup (initial)' '
@ -604,7 +613,7 @@ test_expect_success 'detect bogus diffFilter output' '
echo content >test &&
test_config interactive.diffFilter "sed 1d" &&
printf y >y &&
test_must_fail force_color git add -p <y
force_color test_must_fail git add -p <y
'
test_expect_success 'diff.algorithm is passed to `git diff-files`' '

Просмотреть файл

@ -399,7 +399,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'handles file descriptor exhaustion'
for i in $(test_seq 64)
do
test_commit $i &&
test_might_fail run_with_limited_open_files git commit-graph write \
run_with_limited_open_files test_might_fail git commit-graph write \
--split=no-merge --reachable || return 1
done
)

Просмотреть файл

@ -22,7 +22,12 @@ restore_checkpoint () {
verify_expect () {
git status --porcelain -- fileA.t fileB.t fileC.t fileD.t >actual &&
test_cmp expect actual
if test "x$1" = 'x!'
then
! test_cmp expect actual
else
test_cmp expect actual
fi
}
test_expect_success '--pathspec-from-file from stdin' '
@ -131,7 +136,7 @@ test_expect_success 'quotes not compatible with --pathspec-file-nul' '
cat >expect <<-\EOF &&
D fileA.t
EOF
test_must_fail verify_expect
verify_expect !
'
test_expect_success 'only touches what was listed' '

Просмотреть файл

@ -603,7 +603,7 @@ test_expect_success 'cvs server does not run with vanilla git-shell' '
cd cvswork &&
CVS_SERVER=$WORKDIR/remote-cvs &&
export CVS_SERVER &&
test_must_fail cvs log merge
! cvs log merge
)
'

Просмотреть файл

@ -10,7 +10,7 @@ repository.'
test_expect_success 'start p4d' '
start_p4d &&
test_might_fail p4 configure set submit.collision.check=0
{ p4 configure set submit.collision.check=0 || :; }
'
test_expect_success 'init depot' '

Просмотреть файл

@ -798,6 +798,37 @@ list_contains () {
return 1
}
# Returns success if the arguments indicate that a command should be
# accepted by test_must_fail(). If the command is run with env, the env
# and its corresponding variable settings will be stripped before we
# test the command being run.
test_must_fail_acceptable () {
if test "$1" = "env"
then
shift
while test $# -gt 0
do
case "$1" in
*?=*)
shift
;;
*)
break
;;
esac
done
fi
case "$1" in
git|__git*|test-tool|test-svn-fe|test_terminal)
return 0
;;
*)
return 1
;;
esac
}
# 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:
#
@ -817,6 +848,17 @@ list_contains () {
# Multiple signals can be specified as a comma separated list.
# Currently recognized signal names are: sigpipe, success.
# (Don't use 'success', use 'test_might_fail' instead.)
#
# Do not use this to run anything but "git" and other specific testable
# commands (see test_must_fail_acceptable()). We are not in the
# business of vetting system supplied commands -- in other words, this
# is wrong:
#
# test_must_fail grep pattern output
#
# Instead use '!':
#
# ! grep pattern output
test_must_fail () {
case "$1" in
@ -828,6 +870,11 @@ test_must_fail () {
_test_ok=
;;
esac
if ! test_must_fail_acceptable "$@"
then
echo >&7 "test_must_fail: only 'git' is allowed: $*"
return 1
fi
"$@" 2>&7
exit_code=$?
if test $exit_code -eq 0 && ! list_contains "$_test_ok" success