Skip to content

Commit 8161b23

Browse files
committed
Merge branch 'en/and-cascade-tests' into pu
* en/and-cascade-tests: 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 && t4202 (log): Replace '<git-command> || :' with test_might_fail t4002 (diff-basic): use test_might_fail for commands that might fail t100[12] (read-tree-m-2way, read_tree_m_u_2way): add missing && t4017 (diff-retval): replace manual exit code check with test_expect_code test-lib: make test_expect_code a test command Conflicts: t/t6020-merge-df.sh t/t7006-pager.sh
2 parents 598a1be + 00648ba commit 8161b23

20 files changed

+223
-203
lines changed

t/README

Lines changed: 14 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

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/t1001-read-tree-m-2way.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ test_expect_success \
9898
git checkout-index -u -f -q -a &&
9999
git update-index --add yomin &&
100100
read_tree_twoway $treeH $treeM &&
101-
git ls-files --stage >4.out || return 1
102-
git diff --no-index M.out 4.out >4diff.out
101+
git ls-files --stage >4.out &&
102+
test_must_fail git diff --no-index M.out 4.out >4diff.out &&
103103
compare_change 4diff.out expected &&
104104
check_cache_at yomin clean'
105105

@@ -112,8 +112,8 @@ test_expect_success \
112112
git update-index --add yomin &&
113113
echo yomin yomin >yomin &&
114114
read_tree_twoway $treeH $treeM &&
115-
git ls-files --stage >5.out || return 1
116-
git diff --no-index M.out 5.out >5diff.out
115+
git ls-files --stage >5.out &&
116+
test_must_fail git diff --no-index M.out 5.out >5diff.out &&
117117
compare_change 5diff.out expected &&
118118
check_cache_at yomin dirty'
119119

@@ -213,8 +213,8 @@ test_expect_success \
213213
echo nitfol nitfol >nitfol &&
214214
git update-index --add nitfol &&
215215
read_tree_twoway $treeH $treeM &&
216-
git ls-files --stage >14.out || return 1
217-
git diff --no-index M.out 14.out >14diff.out
216+
git ls-files --stage >14.out &&
217+
test_must_fail git diff --no-index M.out 14.out >14diff.out &&
218218
compare_change 14diff.out expected &&
219219
check_cache_at nitfol clean'
220220

@@ -227,8 +227,8 @@ test_expect_success \
227227
git update-index --add nitfol &&
228228
echo nitfol nitfol nitfol >nitfol &&
229229
read_tree_twoway $treeH $treeM &&
230-
git ls-files --stage >15.out || return 1
231-
git diff --no-index M.out 15.out >15diff.out
230+
git ls-files --stage >15.out &&
231+
test_must_fail git diff --no-index M.out 15.out >15diff.out &&
232232
compare_change 15diff.out expected &&
233233
check_cache_at nitfol dirty'
234234

@@ -377,7 +377,7 @@ test_expect_success \
377377
git ls-files --stage >treeM.out &&
378378
379379
rm -f a &&
380-
mkdir a
380+
mkdir a &&
381381
: >a/b &&
382382
git update-index --add --remove a a/b &&
383383
treeH=`git write-tree` &&

t/t1002-read-tree-m-u-2way.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ test_expect_success \
205205
echo nitfol nitfol >nitfol &&
206206
git update-index --add nitfol &&
207207
git read-tree -m -u $treeH $treeM &&
208-
git ls-files --stage >14.out || return 1
209-
git diff -U0 --no-index M.out 14.out >14diff.out
208+
git ls-files --stage >14.out &&
209+
test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out &&
210210
compare_change 14diff.out expected &&
211211
sum bozbar frotz >actual14.sum &&
212212
grep -v nitfol M.sum > expected14.sum &&
@@ -226,8 +226,8 @@ test_expect_success \
226226
git update-index --add nitfol &&
227227
echo nitfol nitfol nitfol >nitfol &&
228228
git read-tree -m -u $treeH $treeM &&
229-
git ls-files --stage >15.out || return 1
230-
git diff -U0 --no-index M.out 15.out >15diff.out
229+
git ls-files --stage >15.out &&
230+
test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out &&
231231
compare_change 15diff.out expected &&
232232
check_cache_at nitfol dirty &&
233233
sum bozbar frotz >actual15.sum &&
@@ -314,7 +314,7 @@ test_expect_success \
314314
# Also make sure we did not break DF vs DF/DF case.
315315
test_expect_success \
316316
'DF vs DF/DF case setup.' \
317-
'rm -f .git/index
317+
'rm -f .git/index &&
318318
echo DF >DF &&
319319
git update-index --add DF &&
320320
treeDF=`git write-tree` &&

t/t1504-ceiling-dirs.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ test_prefix() {
99
}
1010

1111
test_fail() {
12-
test_expect_code 128 "$1: prefix" \
13-
"git rev-parse --show-prefix"
12+
test_expect_success "$1: prefix" '
13+
test_expect_code 128 git rev-parse --show-prefix
14+
'
1415
}
1516

1617
TRASH_ROOT="$PWD"

t/t4002-diff-basic.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ test_expect_success \
205205
'rm -fr Z [A-Z][A-Z] &&
206206
git read-tree $tree_A &&
207207
git checkout-index -f -a &&
208-
git read-tree --reset $tree_O || return 1
209-
git update-index --refresh >/dev/null ;# this can exit non-zero
208+
git read-tree --reset $tree_O &&
209+
test_must_fail git update-index --refresh -q &&
210210
git diff-files >.test-a &&
211211
cmp_diff_files_output .test-a .test-recursive-OA'
212212

@@ -215,8 +215,8 @@ test_expect_success \
215215
'rm -fr Z [A-Z][A-Z] &&
216216
git read-tree $tree_B &&
217217
git checkout-index -f -a &&
218-
git read-tree --reset $tree_O || return 1
219-
git update-index --refresh >/dev/null ;# this can exit non-zero
218+
git read-tree --reset $tree_O &&
219+
test_must_fail git update-index --refresh -q &&
220220
git diff-files >.test-a &&
221221
cmp_diff_files_output .test-a .test-recursive-OB'
222222

@@ -225,8 +225,8 @@ test_expect_success \
225225
'rm -fr Z [A-Z][A-Z] &&
226226
git read-tree $tree_B &&
227227
git checkout-index -f -a &&
228-
git read-tree --reset $tree_A || return 1
229-
git update-index --refresh >/dev/null ;# this can exit non-zero
228+
git read-tree --reset $tree_A &&
229+
test_must_fail git update-index --refresh -q &&
230230
git diff-files >.test-a &&
231231
cmp_diff_files_output .test-a .test-recursive-AB'
232232

0 commit comments

Comments
 (0)