@matheusbsbs / matheus-bagliano / commits / 00648ba050
Fork 0

Introduce sane_unset and use it to ensure proper && chaining

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Oct 3, 2010 at 14:00 UTC 00648ba0505bbe1999bb6ae2f1d02a0ef923b191
5 files changed +37 -29
t/README
+5 -8
@@ -259,14 +259,11 @@ Do:
259 test ...
260
261 That way all of the commands in your tests will succeed or fail. If
262 - you must ignore the return value of something (e.g., the return
263 - after unsetting a variable that was already unset is unportable) it's
264 - best to indicate so explicitly with a semicolon:
265 -
266 - unset HLAGH;
267 - git merge hla &&
268 - git push gh &&
269 - test ...
262 + you must ignore the return value of something, consider using a
263 + helper function (e.g. use sane_unset instead of unset, in order
264 + to avoid unportable return value for unsetting a variable that was
265 + already unset), or prepending the command with test_might_fail or
266 + test_must_fail.
267
268 - Check the test coverage for your tests. See the "Test coverage"
269 below.
t/t0001-init.sh
+14 -14
@@ -25,7 +25,7 @@ check_config () {
25
26 test_expect_success 'plain' '
27 (
28 - unset GIT_DIR GIT_WORK_TREE
28 + sane_unset GIT_DIR GIT_WORK_TREE &&
29 mkdir plain &&
30 cd plain &&
31 git init
@@ -35,7 +35,7 @@ test_expect_success 'plain' '
35
36 test_expect_success 'plain with GIT_WORK_TREE' '
37 if (
38 - unset GIT_DIR
38 + sane_unset GIT_DIR &&
39 mkdir plain-wt &&
40 cd plain-wt &&
41 GIT_WORK_TREE=$(pwd) git init
@@ -48,7 +48,7 @@ test_expect_success 'plain with GIT_WORK_TREE' '
48
49 test_expect_success 'plain bare' '
50 (
51 - unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
51 + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
52 mkdir plain-bare-1 &&
53 cd plain-bare-1 &&
54 git --bare init
@@ -58,7 +58,7 @@ test_expect_success 'plain bare' '
58
59 test_expect_success 'plain bare with GIT_WORK_TREE' '
60 if (
61 - unset GIT_DIR GIT_CONFIG
61 + sane_unset GIT_DIR GIT_CONFIG &&
62 mkdir plain-bare-2 &&
63 cd plain-bare-2 &&
64 GIT_WORK_TREE=$(pwd) git --bare init
@@ -72,7 +72,7 @@ test_expect_success 'plain bare with GIT_WORK_TREE' '
72 test_expect_success 'GIT_DIR bare' '
73
74 (
75 - unset GIT_CONFIG
75 + sane_unset GIT_CONFIG &&
76 mkdir git-dir-bare.git &&
77 GIT_DIR=git-dir-bare.git git init
78 ) &&
@@ -82,7 +82,7 @@ test_expect_success 'GIT_DIR bare' '
82 test_expect_success 'init --bare' '
83
84 (
85 - unset GIT_DIR GIT_WORK_TREE GIT_CONFIG
85 + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
86 mkdir init-bare.git &&
87 cd init-bare.git &&
88 git init --bare
@@ -93,7 +93,7 @@ test_expect_success 'init --bare' '
93 test_expect_success 'GIT_DIR non-bare' '
94
95 (
96 - unset GIT_CONFIG
96 + sane_unset GIT_CONFIG &&
97 mkdir non-bare &&
98 cd non-bare &&
99 GIT_DIR=.git git init
@@ -104,7 +104,7 @@ test_expect_success 'GIT_DIR non-bare' '
104 test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
105
106 (
107 - unset GIT_CONFIG
107 + sane_unset GIT_CONFIG &&
108 mkdir git-dir-wt-1.git &&
109 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init
110 ) &&
@@ -114,7 +114,7 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' '
114 test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
115
116 if (
117 - unset GIT_CONFIG
117 + sane_unset GIT_CONFIG &&
118 mkdir git-dir-wt-2.git &&
119 GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init
120 )
@@ -127,7 +127,7 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
127 test_expect_success 'reinit' '
128
129 (
130 - unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG
130 + sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG &&
131
132 mkdir again &&
133 cd again &&
@@ -175,8 +175,8 @@ test_expect_success 'init with init.templatedir set' '
175 git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" &&
176 mkdir templatedir-set &&
177 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 &&
180 NO_SET_GIT_TEMPLATE_DIR=t &&
181 export NO_SET_GIT_TEMPLATE_DIR &&
182 git init
@@ -187,7 +187,7 @@ test_expect_success 'init with init.templatedir set' '
187 test_expect_success 'init --bare/--shared overrides system/global config' '
188 (
189 test_config="$HOME"/.gitconfig &&
190 - unset GIT_CONFIG_NOGLOBAL &&
190 + sane_unset GIT_CONFIG_NOGLOBAL &&
191 git config -f "$test_config" core.bare false &&
192 git config -f "$test_config" core.sharedRepository 0640 &&
193 mkdir init-bare-shared-override &&
@@ -202,7 +202,7 @@ test_expect_success 'init --bare/--shared overrides system/global config' '
202 test_expect_success 'init honors global core.sharedRepository' '
203 (
204 test_config="$HOME"/.gitconfig &&
205 - unset GIT_CONFIG_NOGLOBAL &&
205 + sane_unset GIT_CONFIG_NOGLOBAL &&
206 git config -f "$test_config" core.sharedRepository 0666 &&
207 mkdir shared-honor-global &&
208 cd shared-honor-global &&
t/t7006-pager.sh
+5 -5
@@ -41,7 +41,7 @@ else
41 fi
42
43 test_expect_success 'setup' '
44 - unset GIT_PAGER GIT_PAGER_IN_USE;
44 + sane_unset GIT_PAGER GIT_PAGER_IN_USE &&
45 test_might_fail git config --unset core.pager &&
46
47 PAGER="cat >paginated.out" &&
@@ -254,7 +254,7 @@ test_default_pager() {
254 parse_args "$@"
255
256 $test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" "
257 - unset PAGER GIT_PAGER;
257 + sane_unset PAGER GIT_PAGER &&
258 test_might_fail git config --unset core.pager &&
259 rm -f default_pager_used ||
260 cleanup_fail &&
@@ -277,7 +277,7 @@ test_PAGER_overrides() {
277 parse_args "$@"
278
279 $test_expectation TTY "$cmd - PAGER overrides default pager" "
280 - unset GIT_PAGER;
280 + sane_unset GIT_PAGER &&
281 test_might_fail git config --unset core.pager &&
282 rm -f PAGER_used ||
283 cleanup_fail &&
@@ -305,7 +305,7 @@ test_core_pager() {
305 parse_args "$@"
306
307 $test_expectation TTY "$cmd - repository-local core.pager setting $used_if_wanted" "
308 - unset GIT_PAGER;
308 + sane_unset GIT_PAGER &&
309 rm -f core.pager_used ||
310 cleanup_fail &&
311
@@ -333,7 +333,7 @@ test_pager_subdir_helper() {
333 parse_args "$@"
334
335 $test_expectation TTY "$cmd - core.pager $used_if_wanted from subdirectory" "
336 - unset GIT_PAGER;
336 + sane_unset GIT_PAGER &&
337 rm -f core.pager_used &&
338 rm -fr sub ||
339 cleanup_fail &&
t/t7502-commit.sh
+2 -2
@@ -252,8 +252,8 @@ test_expect_success 'committer is automatic' '
252
253 echo >>negative &&
254 (
255 - unset GIT_COMMITTER_EMAIL
256 - unset GIT_COMMITTER_NAME
255 + sane_unset GIT_COMMITTER_EMAIL &&
256 + sane_unset GIT_COMMITTER_NAME &&
257 # must fail because there is no change
258 test_must_fail git commit -e -m "sample"
259 ) &&
t/test-lib.sh
+11
@@ -268,6 +268,17 @@ remove_cr () {
268 tr '\015' Q | sed -e 's/Q$//'
269 }
270
271 +# In some bourne shell implementations, the "unset" builtin returns
272 +# nonzero status when a variable to be unset was not set in the first
273 +# place.
274 +#
275 +# Use sane_unset when that should not be considered an error.
276 +
277 +sane_unset () {
278 + unset "$@"
279 + return 0
280 +}
281 +
282 test_tick () {
283 if test -z "${test_tick+set}"
284 then