Skip to content

Commit 0981140

Browse files
peffgitster
authored andcommitted
t0001: use test_must_fail
We've hand-rolled several "if" statements looking for failures. We can use test_must_fail here, which is shorter and more robust. Note that we modify the commands slightly (to use "git init foo" rather than "cd foo && git init") to avoid dealing with a subshell, but this should not affect the outcome. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2a47241 commit 0981140

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

t/t0001-init.sh

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,8 @@ test_expect_failure 'plain nested in bare through aliased command' '
8585
'
8686

8787
test_expect_success 'plain with GIT_WORK_TREE' '
88-
if (
89-
mkdir plain-wt &&
90-
cd plain-wt &&
91-
GIT_WORK_TREE=$(pwd) git init
92-
)
93-
then
94-
echo Should have failed -- GIT_WORK_TREE should not be used
95-
false
96-
fi
88+
mkdir plain-wt &&
89+
test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt
9790
'
9891

9992
test_expect_success 'plain bare' '
@@ -106,15 +99,10 @@ test_expect_success 'plain bare' '
10699
'
107100

108101
test_expect_success 'plain bare with GIT_WORK_TREE' '
109-
if (
110-
mkdir plain-bare-2 &&
111-
cd plain-bare-2 &&
112-
GIT_WORK_TREE=$(pwd) git --bare init
113-
)
114-
then
115-
echo Should have failed -- GIT_WORK_TREE should not be used
116-
false
117-
fi
102+
mkdir plain-bare-2 &&
103+
test_must_fail \
104+
env GIT_WORK_TREE="$(pwd)/plain-bare-2" \
105+
git --bare init plain-bare-2
118106
'
119107

120108
test_expect_success 'GIT_DIR bare' '
@@ -156,15 +144,11 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
156144
'
157145

158146
test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
159-
160-
if (
161-
mkdir git-dir-wt-2.git &&
162-
GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
163-
)
164-
then
165-
echo Should have failed -- --bare should not be used
166-
false
167-
fi
147+
mkdir git-dir-wt-2.git &&
148+
test_must_fail env \
149+
GIT_WORK_TREE="$(pwd)" \
150+
GIT_DIR=git-dir-wt-2.git \
151+
git --bare init
168152
'
169153

170154
test_expect_success 'reinit' '

0 commit comments

Comments
 (0)