Skip to content

Commit b3ff808

Browse files
committed
Merge branch 'en/and-cascade-tests'
* en/and-cascade-tests: (25 commits) t4124 (apply --whitespace): use test_might_fail t3404: do not use 'describe' to implement test_cmp_rev t3404 (rebase -i): introduce helper to check position of HEAD t3404 (rebase -i): move comment to description t3404 (rebase -i): unroll test_commit loops t3301 (notes): use test_expect_code for clarity t1400 (update-ref): use test_must_fail t1502 (rev-parse --parseopt): test exit code from "-h" t6022 (renaming merge): chain test commands with && test-lib: introduce test_line_count to measure files tests: add missing &&, batch 2 tests: add missing && Introduce sane_unset and use it to ensure proper && chaining t7800 (difftool): add missing && t7601 (merge-pull-config): add missing && t7001 (mv): add missing && t6016 (rev-list-graph-simplify-history): add missing && t5602 (clone-remote-exec): add missing && t4026 (color): remove unneeded and unchained command t4019 (diff-wserror): add lots of missing && ... Conflicts: t/t7006-pager.sh
2 parents c6caede + 33fc521 commit b3ff808

File tree

114 files changed

+597
-657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+597
-657
lines changed

t/README

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,11 @@ Do:
265265
test ...
266266

267267
That way all of the commands in your tests will succeed or fail. If
268-
you must ignore the return value of something (e.g., the return
269-
after unsetting a variable that was already unset is unportable) it's
270-
best to indicate so explicitly with a semicolon:
271-
272-
unset HLAGH;
273-
git merge hla &&
274-
git push gh &&
275-
test ...
268+
you must ignore the return value of something, consider using a
269+
helper function (e.g. use sane_unset instead of unset, in order
270+
to avoid unportable return value for unsetting a variable that was
271+
already unset), or prepending the command with test_might_fail or
272+
test_must_fail.
276273

277274
- Check the test coverage for your tests. See the "Test coverage"
278275
below.
@@ -401,13 +398,6 @@ library for your script to use.
401398
Like test_expect_success this function can optionally use a three
402399
argument invocation with a prerequisite as the first argument.
403400

404-
- test_expect_code [<prereq>] <code> <message> <script>
405-
406-
Analogous to test_expect_success, but pass the test if it exits
407-
with a given exit <code>
408-
409-
test_expect_code 1 'Merge with d/f conflicts' 'git merge "merge msg" B master'
410-
411401
- test_debug <script>
412402

413403
This takes a single argument, <script>, and evaluates it only
@@ -488,6 +478,15 @@ library for your script to use.
488478
'Perl API' \
489479
"$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl
490480

481+
- test_expect_code <exit-code> <command>
482+
483+
Run a command and ensure that it exits with the given exit code.
484+
For example:
485+
486+
test_expect_success 'Merge with d/f conflicts' '
487+
test_expect_code 1 git merge "merge msg" B master
488+
'
489+
491490
- test_must_fail <git-command>
492491

493492
Run a git command and ensure it fails in a controlled way. Use
@@ -507,6 +506,10 @@ library for your script to use.
507506
<expected> file. This behaves like "cmp" but produces more
508507
helpful output when the test is run with "-v" option.
509508

509+
- test_line_count (= | -lt | -ge | ...) <length> <file>
510+
511+
Check whether a file has the length it is expected to.
512+
510513
- test_path_is_file <file> [<diagnosis>]
511514
test_path_is_dir <dir> [<diagnosis>]
512515
test_path_is_missing <path> [<diagnosis>]

t/annotate-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test_expect_success \
3838
'prepare reference tree' \
3939
'echo "1A quick brown fox jumps over the" >file &&
4040
echo "lazy dog" >>file &&
41-
git add file
41+
git add file &&
4242
GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
4343

4444
test_expect_success \

t/t0000-basic.sh

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,57 @@ test_expect_success 'tests clean up after themselves' '
130130
test_when_finished clean=yes
131131
'
132132

133-
cleaner=no
134-
test_expect_code 1 'tests clean up even after a failure' '
135-
test_when_finished cleaner=yes &&
136-
(exit 1)
137-
'
138-
139-
if test $clean$cleaner != yesyes
133+
if test $clean != yes
140134
then
141-
say "bug in test framework: cleanup commands do not work reliably"
135+
say "bug in test framework: basic cleanup command does not work reliably"
142136
exit 1
143137
fi
144138

145-
test_expect_code 2 'failure to clean up causes the test to fail' '
146-
test_when_finished "(exit 2)"
139+
test_expect_success 'tests clean up even on failures' "
140+
mkdir failing-cleanup &&
141+
(cd failing-cleanup &&
142+
cat >failing-cleanup.sh <<EOF &&
143+
#!$SHELL_PATH
144+
145+
test_description='Failing tests with cleanup commands'
146+
147+
# Point to the t/test-lib.sh, which isn't in ../ as usual
148+
TEST_DIRECTORY=\"$TEST_DIRECTORY\"
149+
. \"\$TEST_DIRECTORY\"/test-lib.sh
150+
151+
test_expect_success 'tests clean up even after a failure' '
152+
touch clean-after-failure &&
153+
test_when_finished rm clean-after-failure &&
154+
(exit 1)
155+
'
156+
157+
test_expect_success 'failure to clean up causes the test to fail' '
158+
test_when_finished \"(exit 2)\"
147159
'
148160
161+
test_done
162+
EOF
163+
chmod +x failing-cleanup.sh &&
164+
test_must_fail ./failing-cleanup.sh >out 2>err &&
165+
! test -s err &&
166+
! test -f \"trash directory.failing-cleanup/clean-after-failure\" &&
167+
sed -e 's/Z$//' >expect <<\EOF &&
168+
not ok - 1 tests clean up even after a failure
169+
# Z
170+
# touch clean-after-failure &&
171+
# test_when_finished rm clean-after-failure &&
172+
# (exit 1)
173+
# Z
174+
not ok - 2 failure to clean up causes the test to fail
175+
# Z
176+
# test_when_finished \"(exit 2)\"
177+
# Z
178+
# failed 2 among 2 test(s)
179+
1..2
180+
EOF
181+
test_cmp expect out)
182+
"
183+
149184
################################################################
150185
# Basics of the basics
151186

t/t0001-init.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ check_config () {
2525

2626
test_expect_success 'plain' '
2727
(
28-
unset GIT_DIR GIT_WORK_TREE
28+
sane_unset GIT_DIR GIT_WORK_TREE &&
2929
mkdir plain &&
3030
cd plain &&
3131
git init
@@ -35,7 +35,7 @@ test_expect_success 'plain' '
3535

3636
test_expect_success 'plain with GIT_WORK_TREE' '
3737
if (
38-
unset GIT_DIR
38+
sane_unset GIT_DIR &&
3939
mkdir plain-wt &&
4040
cd plain-wt &&
4141
GIT_WORK_TREE=$(pwd) git init
@@ -48,7 +48,7 @@ test_expect_success 'plain with GIT_WORK_TREE' '
4848

4949
test_expect_success 'plain bare' '
5050
(
51-
unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
51+
sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
5252
mkdir plain-bare-1 &&
5353
cd plain-bare-1 &&
5454
git --bare init
@@ -58,7 +58,7 @@ test_expect_success 'plain bare' '
5858

5959
test_expect_success 'plain bare with GIT_WORK_TREE' '
6060
if (
61-
unset GIT_DIR GIT_CONFIG
61+
sane_unset GIT_DIR GIT_CONFIG &&
6262
mkdir plain-bare-2 &&
6363
cd plain-bare-2 &&
6464
GIT_WORK_TREE=$(pwd) git --bare init
@@ -72,7 +72,7 @@ test_expect_success 'plain bare with GIT_WORK_TREE' '
7272
test_expect_success 'GIT_DIR bare' '
7373
7474
(
75-
unset GIT_CONFIG
75+
sane_unset GIT_CONFIG &&
7676
mkdir git-dir-bare.git &&
7777
GIT_DIR=git-dir-bare.git git init
7878
) &&
@@ -82,7 +82,7 @@ test_expect_success 'GIT_DIR bare' '
8282
test_expect_success 'init --bare' '
8383
8484
(
85-
unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
85+
sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
8686
mkdir init-bare.git &&
8787
cd init-bare.git &&
8888
git init --bare
@@ -93,7 +93,7 @@ test_expect_success 'init --bare' '
9393
test_expect_success 'GIT_DIR non-bare' '
9494
9595
(
96-
unset GIT_CONFIG
96+
sane_unset GIT_CONFIG &&
9797
mkdir non-bare &&
9898
cd non-bare &&
9999
GIT_DIR=.git git init
@@ -104,7 +104,7 @@ test_expect_success 'GIT_DIR non-bare' '
104104
test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
105105
106106
(
107-
unset GIT_CONFIG
107+
sane_unset GIT_CONFIG &&
108108
mkdir git-dir-wt-1.git &&
109109
GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
110110
) &&
@@ -114,7 +114,7 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
114114
test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
115115
116116
if (
117-
unset GIT_CONFIG
117+
sane_unset GIT_CONFIG &&
118118
mkdir git-dir-wt-2.git &&
119119
GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
120120
)
@@ -127,7 +127,7 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
127127
test_expect_success 'reinit' '
128128
129129
(
130-
unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG
130+
sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG &&
131131
132132
mkdir again &&
133133
cd again &&
@@ -175,8 +175,8 @@ test_expect_success 'init with init.templatedir set' '
175175
git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" &&
176176
mkdir templatedir-set &&
177177
cd templatedir-set &&
178-
unset GIT_CONFIG_NOGLOBAL &&
179-
unset GIT_TEMPLATE_DIR &&
178+
sane_unset GIT_CONFIG_NOGLOBAL &&
179+
sane_unset GIT_TEMPLATE_DIR &&
180180
NO_SET_GIT_TEMPLATE_DIR=t &&
181181
export NO_SET_GIT_TEMPLATE_DIR &&
182182
git init
@@ -187,7 +187,7 @@ test_expect_success 'init with init.templatedir set' '
187187
test_expect_success 'init --bare/--shared overrides system/global config' '
188188
(
189189
test_config="$HOME"/.gitconfig &&
190-
unset GIT_CONFIG_NOGLOBAL &&
190+
sane_unset GIT_CONFIG_NOGLOBAL &&
191191
git config -f "$test_config" core.bare false &&
192192
git config -f "$test_config" core.sharedRepository 0640 &&
193193
mkdir init-bare-shared-override &&
@@ -202,7 +202,7 @@ test_expect_success 'init --bare/--shared overrides system/global config' '
202202
test_expect_success 'init honors global core.sharedRepository' '
203203
(
204204
test_config="$HOME"/.gitconfig &&
205-
unset GIT_CONFIG_NOGLOBAL &&
205+
sane_unset GIT_CONFIG_NOGLOBAL &&
206206
git config -f "$test_config" core.sharedRepository 0666 &&
207207
mkdir shared-honor-global &&
208208
cd shared-honor-global &&

t/t0003-attributes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test_expect_success 'core.attributesfile' '
7272

7373
test_expect_success 'attribute test: read paths from stdin' '
7474
75-
cat <<EOF > expect
75+
cat <<EOF > expect &&
7676
f: test: f
7777
a/f: test: f
7878
a/c/f: test: f

t/t0020-crlf.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ test_expect_success 'checkout when deleting .gitattributes' '
439439
git rm .gitattributes &&
440440
echo "contentsQ" | q_to_cr > .file2 &&
441441
git add .file2 &&
442-
git commit -m third
442+
git commit -m third &&
443443
444444
git checkout master~1 &&
445445
git checkout master &&

t/t0024-crlf-archive.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ UNZIP=${UNZIP:-unzip}
77

88
test_expect_success setup '
99
10-
git config core.autocrlf true
10+
git config core.autocrlf true &&
1111
1212
printf "CRLF line ending\r\nAnd another\r\n" > sample &&
1313
git add sample &&
@@ -20,7 +20,7 @@ test_expect_success setup '
2020
test_expect_success 'tar archive' '
2121
2222
git archive --format=tar HEAD |
23-
( mkdir untarred && cd untarred && "$TAR" -xf - )
23+
( mkdir untarred && cd untarred && "$TAR" -xf - ) &&
2424
2525
test_cmp sample untarred/sample
2626

t/t0026-eol-config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test_expect_success setup '
1212
1313
git config core.autocrlf false &&
1414
15-
echo "one text" > .gitattributes
15+
echo "one text" > .gitattributes &&
1616
1717
for w in Hello world how are you; do echo $w; done >one &&
1818
for w in I am very very fine thank you; do echo $w; done >two &&

t/t0050-filesystem.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ unibad=
1212
no_symlinks=
1313
test_expect_success 'see what we expect' '
1414
15-
test_case=test_expect_success
16-
test_unicode=test_expect_success
15+
test_case=test_expect_success &&
16+
test_unicode=test_expect_success &&
1717
mkdir junk &&
1818
echo good >junk/CamelCase &&
1919
echo bad >junk/camelcase &&
2020
if test "$(cat junk/CamelCase)" != good
2121
then
22-
test_case=test_expect_failure
22+
test_case=test_expect_failure &&
2323
case_insensitive=t
2424
fi &&
2525
rm -fr junk &&
2626
mkdir junk &&
2727
>junk/"$auml" &&
2828
case "$(cd junk && echo *)" in
2929
"$aumlcdiar")
30-
test_unicode=test_expect_failure
30+
test_unicode=test_expect_failure &&
3131
unibad=t
3232
;;
3333
*) ;;
@@ -36,7 +36,7 @@ test_expect_success 'see what we expect' '
3636
{
3737
ln -s x y 2> /dev/null &&
3838
test -h y 2> /dev/null ||
39-
no_symlinks=1
39+
no_symlinks=1 &&
4040
rm -f y
4141
}
4242
'
@@ -128,7 +128,7 @@ test_expect_success "setup unicode normalization tests" '
128128
cd unicode &&
129129
touch "$aumlcdiar" &&
130130
git add "$aumlcdiar" &&
131-
git commit -m initial
131+
git commit -m initial &&
132132
git tag initial &&
133133
git checkout -b topic &&
134134
git mv $aumlcdiar tmp &&

t/t1000-read-tree-m-3way.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ test_expect_success \
309309
test_expect_success \
310310
'6 - must not exist in O && !A && !B case' "
311311
rm -f .git/index DD &&
312-
echo DD >DD
312+
echo DD >DD &&
313313
git update-index --add DD &&
314314
test_must_fail git read-tree -m $tree_O $tree_A $tree_B
315315
"

0 commit comments

Comments
 (0)