Merge branch 'ab/test-lib-updates'

Test clean-up.

* ab/test-lib-updates:
  test-lib: split up and deprecate test_create_repo()
  test-lib: do not show advice about init.defaultBranch under --verbose
  test-lib: reformat argument list in test_create_repo()
  submodule tests: use symbolic-ref --short to discover branch name
  test-lib functions: add --printf option to test_commit
  describe tests: convert setup to use test_commit
  test-lib functions: add an --annotated option to "test_commit"
  test-lib-functions: document test_commit --no-tag
  test-lib-functions: reword "test_commit --append" docs
  test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  test-lib: bring $remove_trash out of retirement
This commit is contained in:
Junio C Hamano 2021-06-14 13:33:29 +09:00
commit 2019256717
14 changed files with 97 additions and 127 deletions

View File

@ -63,6 +63,7 @@ create_lib_submodule_repo () {
git init submodule_update_repo &&
(
cd submodule_update_repo &&
branch=$(git symbolic-ref --short HEAD) &&
echo "expect" >>.gitignore &&
echo "actual" >>.gitignore &&
echo "x" >file1 &&
@ -144,7 +145,7 @@ create_lib_submodule_repo () {
git checkout -b valid_sub1 &&
git revert HEAD &&
git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
git checkout "$branch"
)
}

View File

@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
passing metrics
'
# Tell the framework that we are self-testing to make sure
# it yields a stable result.
GIT_TEST_FRAMEWORK_SELFTEST=t &&
# Point to the t/test-lib.sh, which isn't in ../ as usual
. "\$TEST_DIRECTORY"/test-lib.sh
EOF

View File

@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
'
test_expect_success 'can parse blob ending with CR' '
printf "[some]key = value\\r" >config &&
git add config &&
git commit -m CR &&
test_commit --printf CR config "[some]key = value\\r" &&
echo value >expect &&
git config --blob=HEAD:config some.key >actual &&
test_cmp expect actual

View File

@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_expect_success setup '
test_commit A &&
git tag -f -a -m "annotated A" A &&
test_commit --annotate A &&
git checkout -b side &&
test_commit B &&
git tag -f -a -m "annotated B" B &&
test_commit --annotate B &&
git checkout main &&
test_commit C &&
git branch B A^0

View File

@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
test_expect_success 'rerere forget (binary)' '
git checkout -f side &&
printf "a\0c" >binary &&
git commit -a -m binary &&
test_commit --printf binary binary "a\0c" &&
test_must_fail git merge second &&
git rerere forget binary
'

View File

@ -26,10 +26,8 @@ test_expect_success 'chmod' '
'
test_expect_success 'prepare binary file' '
git commit -m rezrov &&
printf "\00\01\02\03\04\05\06" >binbin &&
git add binbin &&
git commit -m binbin
git commit -m one &&
test_commit --printf two binbin "\00\01\02\03\04\05\06"
'
test_expect_success '--stat output after text chmod' '

View File

@ -26,12 +26,8 @@ EOF
chmod +x hexdump
test_expect_success 'setup binary file with history' '
printf "\\0\\n" >file &&
git add file &&
git commit -m one &&
printf "\\01\\n" >>file &&
git add file &&
git commit -m two
test_commit --printf one file "\\0\\n" &&
test_commit --printf --append two file "\\01\\n"
'
test_expect_success 'file is considered binary by porcelain' '

View File

@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
. ./test-lib.sh
test_expect_success 'setup' '
mkdir .git/hooks &&
write_script .git/hooks/update <<-\EOF &&
exit 1
EOF

View File

@ -20,8 +20,6 @@ test_expect_success 'setup' '
git checkout main
'
mkdir .git/hooks
cat >.git/hooks/post-rewrite <<EOF
#!/bin/sh
echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args

View File

@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
. ./test-lib.sh
test_expect_success 'setup' '
mkdir .git/hooks &&
write_script .git/hooks/update <<-\EOF &&
echo error: error
echo ERROR: also highlighted

View File

@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
'
test_expect_success 'setup for detecting upstreamed changes' '
mkdir src &&
(
cd src &&
git init &&
printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
git add stuff &&
git commit -m "Initial revision"
) &&
test_create_repo src &&
test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
git clone src dst &&
(
cd src &&

View File

@ -31,64 +31,32 @@ check_describe () {
}
test_expect_success setup '
test_commit initial file one &&
test_commit second file two &&
test_commit third file three &&
test_commit --annotate A file A &&
test_commit c file c &&
test_tick &&
echo one >file && git add file && git commit -m initial &&
one=$(git rev-parse HEAD) &&
git describe --always HEAD &&
test_tick &&
echo two >file && git add file && git commit -m second &&
two=$(git rev-parse HEAD) &&
test_tick &&
echo three >file && git add file && git commit -m third &&
test_tick &&
echo A >file && git add file && git commit -m A &&
test_tick &&
git tag -a -m A A &&
test_tick &&
echo c >file && git add file && git commit -m c &&
test_tick &&
git tag c &&
git reset --hard $two &&
test_tick &&
echo B >side && git add side && git commit -m B &&
test_tick &&
git tag -a -m B B &&
git reset --hard second &&
test_commit --annotate B side B &&
test_tick &&
git merge -m Merged c &&
merged=$(git rev-parse HEAD) &&
git reset --hard $two &&
test_tick &&
echo D >another && git add another && git commit -m D &&
test_tick &&
git tag -a -m D D &&
git reset --hard second &&
test_commit --no-tag D another D &&
test_tick &&
git tag -a -m R R &&
test_tick &&
echo DD >another && git commit -a -m another &&
test_tick &&
git tag e &&
test_tick &&
echo DDD >another && git commit -a -m "yet another" &&
test_commit e another DD &&
test_commit --no-tag "yet another" another DDD &&
test_tick &&
git merge -m Merged $merged &&
test_tick &&
echo X >file && echo X >side && git add file side &&
git commit -m x
test_commit --no-tag x file
'
check_describe A-* HEAD

View File

@ -172,12 +172,23 @@ debug () {
# --notick
# Do not call test_tick before making a commit
# --append
# Use "echo >>" instead of "echo >" when writing "<contents>" to
# "<file>"
# Use ">>" instead of ">" when writing "<contents>" to "<file>"
# --printf
# Use "printf" instead of "echo" when writing "<contents>" to
# "<file>", use this to write escape sequences such as "\0", a
# trailing "\n" won't be added automatically. This option
# supports nothing but the FORMAT of printf(1), i.e. no custom
# ARGUMENT(s).
# --signoff
# Invoke "git commit" with --signoff
# --author <author>
# Invoke "git commit" with --author <author>
# --no-tag
# Do not tag the resulting commit
# --annotate
# Create an annotated tag with "--annotate -m <message>". Calls
# test_tick between making the commit and tag, unless --notick
# is given.
#
# This will commit a file with the given contents and the given commit
# message, and tag the resulting commit with the given tag name.
@ -186,17 +197,21 @@ debug () {
test_commit () {
notick= &&
echo=echo &&
append= &&
author= &&
signoff= &&
indir= &&
no_tag= &&
tag=light &&
while test $# != 0
do
case "$1" in
--notick)
notick=yes
;;
--printf)
echo=printf
;;
--append)
append=yes
;;
@ -218,7 +233,10 @@ test_commit () {
shift
;;
--no-tag)
no_tag=yes
tag=none
;;
--annotate)
tag=annotate
;;
*)
break
@ -230,9 +248,9 @@ test_commit () {
file=${2:-"$1.t"} &&
if test -n "$append"
then
echo "${3-$1}" >>"$indir$file"
$echo "${3-$1}" >>"$indir$file"
else
echo "${3-$1}" >"$indir$file"
$echo "${3-$1}" >"$indir$file"
fi &&
git ${indir:+ -C "$indir"} add "$file" &&
if test -z "$notick"
@ -242,10 +260,20 @@ test_commit () {
git ${indir:+ -C "$indir"} commit \
${author:+ --author "$author"} \
$signoff -m "$1" &&
if test -z "$no_tag"
then
case "$tag" in
none)
;;
light)
git ${indir:+ -C "$indir"} tag "${4:-$1}"
fi
;;
annotate)
if test -z "$notick"
then
test_tick
fi &&
git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
;;
esac
}
# Call test_merge with the arguments "<message> <commit>", where <commit>
@ -1215,22 +1243,10 @@ test_atexit () {
} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
}
# Most tests can use the created repository, but some may need to create more.
# Deprecated wrapper for "git init", use "git init" directly instead
# Usage: test_create_repo <directory>
test_create_repo () {
test "$#" = 1 ||
BUG "not 1 parameter to test-create-repo"
repo="$1"
mkdir -p "$repo"
(
cd "$repo" || error "Cannot setup test environment"
"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
init \
"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
error "cannot run git init -- have you built things yet?"
mv .git/hooks .git/hooks-disabled
) || exit
git init "$@"
}
# This function helps on symlink challenged file systems when it is not

View File

@ -64,6 +64,11 @@ then
export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
fi
# Explicitly set the default branch name for testing, to avoid the
# transitory "git init" warning under --verbose.
: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
################################################################
# It appears that people try to run tests without building...
"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
@ -1172,7 +1177,7 @@ test_done () {
esac
fi
if test -z "$debug"
if test -z "$debug" && test -n "$remove_trash"
then
test -d "$TRASH_DIRECTORY" ||
error "Tests passed but trash directory already removed before test cleanup; aborting"
@ -1337,28 +1342,8 @@ then
exit 1
fi
# Test repository
rm -fr "$TRASH_DIRECTORY" || {
GIT_EXIT_OK=t
echo >&5 "FATAL: Cannot prepare test area"
exit 1
}
HOME="$TRASH_DIRECTORY"
GNUPGHOME="$HOME/gnupg-home-not-used"
export HOME GNUPGHOME
if test -z "$TEST_NO_CREATE_REPO"
then
test_create_repo "$TRASH_DIRECTORY"
else
mkdir -p "$TRASH_DIRECTORY"
fi
# Use -P to resolve symlinks in our working directory so that the cwd
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$TRASH_DIRECTORY" || exit 1
# Are we running this test at all?
remove_trash=
this_test=${0##*/}
this_test=${this_test%%-*}
if match_pattern_list "$this_test" $GIT_SKIP_TESTS
@ -1368,6 +1353,31 @@ then
test_done
fi
# Last-minute variable setup
HOME="$TRASH_DIRECTORY"
GNUPGHOME="$HOME/gnupg-home-not-used"
export HOME GNUPGHOME
# Test repository
rm -fr "$TRASH_DIRECTORY" || {
GIT_EXIT_OK=t
echo >&5 "FATAL: Cannot prepare test area"
exit 1
}
remove_trash=t
if test -z "$TEST_NO_CREATE_REPO"
then
git init "$TRASH_DIRECTORY" >&3 2>&4 ||
error "cannot run git init"
else
mkdir -p "$TRASH_DIRECTORY"
fi
# Use -P to resolve symlinks in our working directory so that the cwd
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$TRASH_DIRECTORY" || exit 1
if test -n "$write_junit_xml"
then
junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"