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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 20, 2014 at 19:19 UTC 0981140fcc2fe33c37da87802b95e01af2a94add
1 file changed +11 -27
t/t0001-init.sh
+11 -27
@@ -85,15 +85,8 @@ test_expect_failure 'plain nested in bare through aliased command' '
85 '
86
87 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
90 '
91
92 test_expect_success 'plain bare' '
@@ -106,15 +99,10 @@ test_expect_success 'plain bare' '
99 '
100
101 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
106 '
107
108 test_expect_success 'GIT_DIR bare' '
@@ -156,15 +144,11 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
144 '
145
146 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
152 '
153
154 test_expect_success 'reinit' '