Skip to content

Commit 2019256

Browse files
committed
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
2 parents c189dba + f0d4d39 commit 2019256

14 files changed

+89
-119
lines changed

t/lib-submodule-update.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
6363
git init submodule_update_repo &&
6464
(
6565
cd submodule_update_repo &&
66+
branch=$(git symbolic-ref --short HEAD) &&
6667
echo "expect" >>.gitignore &&
6768
echo "actual" >>.gitignore &&
6869
echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
144145
git checkout -b valid_sub1 &&
145146
git revert HEAD &&
146147

147-
git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
148+
git checkout "$branch"
148149
)
149150
}
150151

t/t0000-basic.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
8484
passing metrics
8585
'
8686
87-
# Tell the framework that we are self-testing to make sure
88-
# it yields a stable result.
89-
GIT_TEST_FRAMEWORK_SELFTEST=t &&
90-
9187
# Point to the t/test-lib.sh, which isn't in ../ as usual
9288
. "\$TEST_DIRECTORY"/test-lib.sh
9389
EOF

t/t1307-config-blob.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
6565
'
6666

6767
test_expect_success 'can parse blob ending with CR' '
68-
printf "[some]key = value\\r" >config &&
69-
git add config &&
70-
git commit -m CR &&
68+
test_commit --printf CR config "[some]key = value\\r" &&
7169
echo value >expect &&
7270
git config --blob=HEAD:config some.key >actual &&
7371
test_cmp expect actual

t/t1403-show-ref.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77
. ./test-lib.sh
88

99
test_expect_success setup '
10-
test_commit A &&
11-
git tag -f -a -m "annotated A" A &&
10+
test_commit --annotate A &&
1211
git checkout -b side &&
13-
test_commit B &&
14-
git tag -f -a -m "annotated B" B &&
12+
test_commit --annotate B &&
1513
git checkout main &&
1614
test_commit C &&
1715
git branch B A^0

t/t2030-unresolve-info.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
179179

180180
test_expect_success 'rerere forget (binary)' '
181181
git checkout -f side &&
182-
printf "a\0c" >binary &&
183-
git commit -a -m binary &&
182+
test_commit --printf binary binary "a\0c" &&
184183
test_must_fail git merge second &&
185184
git rerere forget binary
186185
'

t/t4006-diff-mode.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
2626
'
2727

2828
test_expect_success 'prepare binary file' '
29-
git commit -m rezrov &&
30-
printf "\00\01\02\03\04\05\06" >binbin &&
31-
git add binbin &&
32-
git commit -m binbin
29+
git commit -m one &&
30+
test_commit --printf two binbin "\00\01\02\03\04\05\06"
3331
'
3432

3533
test_expect_success '--stat output after text chmod' '

t/t4030-diff-textconv.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ EOF
2626
chmod +x hexdump
2727

2828
test_expect_success 'setup binary file with history' '
29-
printf "\\0\\n" >file &&
30-
git add file &&
31-
git commit -m one &&
32-
printf "\\01\\n" >>file &&
33-
git add file &&
34-
git commit -m two
29+
test_commit --printf one file "\\0\\n" &&
30+
test_commit --printf --append two file "\\01\\n"
3531
'
3632

3733
test_expect_success 'file is considered binary by porcelain' '

t/t5406-remote-rejects.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
55
. ./test-lib.sh
66

77
test_expect_success 'setup' '
8-
mkdir .git/hooks &&
98
write_script .git/hooks/update <<-\EOF &&
109
exit 1
1110
EOF

t/t5407-post-rewrite-hook.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ test_expect_success 'setup' '
2020
git checkout main
2121
'
2222

23-
mkdir .git/hooks
24-
2523
cat >.git/hooks/post-rewrite <<EOF
2624
#!/bin/sh
2725
echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args

t/t5409-colorize-remote-messages.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
55
. ./test-lib.sh
66

77
test_expect_success 'setup' '
8-
mkdir .git/hooks &&
98
write_script .git/hooks/update <<-\EOF &&
109
echo error: error
1110
echo ERROR: also highlighted

t/t5520-pull.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
746746
'
747747

748748
test_expect_success 'setup for detecting upstreamed changes' '
749-
mkdir src &&
750-
(
751-
cd src &&
752-
git init &&
753-
printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
754-
git add stuff &&
755-
git commit -m "Initial revision"
756-
) &&
749+
test_create_repo src &&
750+
test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
757751
git clone src dst &&
758752
(
759753
cd src &&

t/t6120-describe.sh

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,64 +31,32 @@ check_describe () {
3131
}
3232

3333
test_expect_success setup '
34+
test_commit initial file one &&
35+
test_commit second file two &&
36+
test_commit third file three &&
37+
test_commit --annotate A file A &&
38+
test_commit c file c &&
3439
35-
test_tick &&
36-
echo one >file && git add file && git commit -m initial &&
37-
one=$(git rev-parse HEAD) &&
38-
39-
git describe --always HEAD &&
40-
41-
test_tick &&
42-
echo two >file && git add file && git commit -m second &&
43-
two=$(git rev-parse HEAD) &&
44-
45-
test_tick &&
46-
echo three >file && git add file && git commit -m third &&
47-
48-
test_tick &&
49-
echo A >file && git add file && git commit -m A &&
50-
test_tick &&
51-
git tag -a -m A A &&
52-
53-
test_tick &&
54-
echo c >file && git add file && git commit -m c &&
55-
test_tick &&
56-
git tag c &&
57-
58-
git reset --hard $two &&
59-
test_tick &&
60-
echo B >side && git add side && git commit -m B &&
61-
test_tick &&
62-
git tag -a -m B B &&
40+
git reset --hard second &&
41+
test_commit --annotate B side B &&
6342
6443
test_tick &&
6544
git merge -m Merged c &&
6645
merged=$(git rev-parse HEAD) &&
6746
68-
git reset --hard $two &&
69-
test_tick &&
70-
echo D >another && git add another && git commit -m D &&
71-
test_tick &&
72-
git tag -a -m D D &&
73-
test_tick &&
74-
git tag -a -m R R &&
75-
76-
test_tick &&
77-
echo DD >another && git commit -a -m another &&
47+
git reset --hard second &&
48+
test_commit --no-tag D another D &&
7849
7950
test_tick &&
80-
git tag e &&
51+
git tag -a -m R R &&
8152
82-
test_tick &&
83-
echo DDD >another && git commit -a -m "yet another" &&
53+
test_commit e another DD &&
54+
test_commit --no-tag "yet another" another DDD &&
8455
8556
test_tick &&
8657
git merge -m Merged $merged &&
8758
88-
test_tick &&
89-
echo X >file && echo X >side && git add file side &&
90-
git commit -m x
91-
59+
test_commit --no-tag x file
9260
'
9361

9462
check_describe A-* HEAD

t/test-lib-functions.sh

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,23 @@ debug () {
172172
# --notick
173173
# Do not call test_tick before making a commit
174174
# --append
175-
# Use "echo >>" instead of "echo >" when writing "<contents>" to
176-
# "<file>"
175+
# Use ">>" instead of ">" when writing "<contents>" to "<file>"
176+
# --printf
177+
# Use "printf" instead of "echo" when writing "<contents>" to
178+
# "<file>", use this to write escape sequences such as "\0", a
179+
# trailing "\n" won't be added automatically. This option
180+
# supports nothing but the FORMAT of printf(1), i.e. no custom
181+
# ARGUMENT(s).
177182
# --signoff
178183
# Invoke "git commit" with --signoff
179184
# --author <author>
180185
# Invoke "git commit" with --author <author>
186+
# --no-tag
187+
# Do not tag the resulting commit
188+
# --annotate
189+
# Create an annotated tag with "--annotate -m <message>". Calls
190+
# test_tick between making the commit and tag, unless --notick
191+
# is given.
181192
#
182193
# This will commit a file with the given contents and the given commit
183194
# message, and tag the resulting commit with the given tag name.
@@ -186,17 +197,21 @@ debug () {
186197

187198
test_commit () {
188199
notick= &&
200+
echo=echo &&
189201
append= &&
190202
author= &&
191203
signoff= &&
192204
indir= &&
193-
no_tag= &&
205+
tag=light &&
194206
while test $# != 0
195207
do
196208
case "$1" in
197209
--notick)
198210
notick=yes
199211
;;
212+
--printf)
213+
echo=printf
214+
;;
200215
--append)
201216
append=yes
202217
;;
@@ -218,7 +233,10 @@ test_commit () {
218233
shift
219234
;;
220235
--no-tag)
221-
no_tag=yes
236+
tag=none
237+
;;
238+
--annotate)
239+
tag=annotate
222240
;;
223241
*)
224242
break
@@ -230,9 +248,9 @@ test_commit () {
230248
file=${2:-"$1.t"} &&
231249
if test -n "$append"
232250
then
233-
echo "${3-$1}" >>"$indir$file"
251+
$echo "${3-$1}" >>"$indir$file"
234252
else
235-
echo "${3-$1}" >"$indir$file"
253+
$echo "${3-$1}" >"$indir$file"
236254
fi &&
237255
git ${indir:+ -C "$indir"} add "$file" &&
238256
if test -z "$notick"
@@ -242,10 +260,20 @@ test_commit () {
242260
git ${indir:+ -C "$indir"} commit \
243261
${author:+ --author "$author"} \
244262
$signoff -m "$1" &&
245-
if test -z "$no_tag"
246-
then
263+
case "$tag" in
264+
none)
265+
;;
266+
light)
247267
git ${indir:+ -C "$indir"} tag "${4:-$1}"
248-
fi
268+
;;
269+
annotate)
270+
if test -z "$notick"
271+
then
272+
test_tick
273+
fi &&
274+
git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
275+
;;
276+
esac
249277
}
250278

251279
# Call test_merge with the arguments "<message> <commit>", where <commit>
@@ -1215,22 +1243,10 @@ test_atexit () {
12151243
} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
12161244
}
12171245

1218-
# Most tests can use the created repository, but some may need to create more.
1246+
# Deprecated wrapper for "git init", use "git init" directly instead
12191247
# Usage: test_create_repo <directory>
12201248
test_create_repo () {
1221-
test "$#" = 1 ||
1222-
BUG "not 1 parameter to test-create-repo"
1223-
repo="$1"
1224-
mkdir -p "$repo"
1225-
(
1226-
cd "$repo" || error "Cannot setup test environment"
1227-
"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
1228-
init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
1229-
init \
1230-
"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
1231-
error "cannot run git init -- have you built things yet?"
1232-
mv .git/hooks .git/hooks-disabled
1233-
) || exit
1249+
git init "$@"
12341250
}
12351251

12361252
# This function helps on symlink challenged file systems when it is not

0 commit comments

Comments
 (0)