gc + p4 tests: use "test_hook", remove sub-shells
Refactor the repository setup code for tests that test hooks the use of sub-shells when setting up the test repository and hooks, and use the "test_hook" wrapper instead of "write_scripts". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 17, 2022 at 11:13 UTC
d7ef03681fbcbd0314d91c71d60f79a51338690a
2 files changed
+24
-21
t/t6500-gc.sh
+10
-12
@@ -101,12 +101,12 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' '
101
EOF
102
103
git init pre-auto-gc-hook &&
104
+ test_hook -C pre-auto-gc-hook pre-auto-gc <<-\EOF &&
105
+ echo >&2 no gc for you &&
106
+ exit 1
107
+ EOF
108
(
109
cd pre-auto-gc-hook &&
106
- write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
107
- echo >&2 no gc for you &&
108
- exit 1
109
- EOF
110
111
git config gc.auto 3 &&
112
git config gc.autoDetach false &&
@@ -128,14 +128,12 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' '
128
See "git help gc" for manual housekeeping.
129
EOF
130
131
- (
132
- cd pre-auto-gc-hook &&
133
- write_script ".git/hooks/pre-auto-gc" <<-\EOF &&
134
- echo >&2 will gc for you &&
135
- exit 0
136
- EOF
137
- git gc --auto >../out.actual 2>../err.actual
138
- ) &&
131
+ test_hook -C pre-auto-gc-hook --clobber pre-auto-gc <<-\EOF &&
132
+ echo >&2 will gc for you &&
133
+ exit 0
134
+ EOF
135
+
136
+ git -C pre-auto-gc-hook gc --auto >out.actual 2>err.actual &&
137
138
test_must_be_empty out.actual &&
139
test_cmp err.expect err.actual
t/t9800-git-p4-basic.sh
+14
-9
@@ -277,16 +277,21 @@ test_expect_success 'run hook p4-pre-submit before submit' '
277
git commit -m "add hello.txt" &&
278
git config git-p4.skipSubmitEdit true &&
279
git p4 submit --dry-run >out &&
280
- grep "Would apply" out &&
281
- mkdir -p .git/hooks &&
282
- write_script .git/hooks/p4-pre-submit <<-\EOF &&
283
- exit 0
284
- EOF
280
+ grep "Would apply" out
281
+ ) &&
282
+ test_hook -C "$git" p4-pre-submit <<-\EOF &&
283
+ exit 0
284
+ EOF
285
+ (
286
+ cd "$git" &&
287
git p4 submit --dry-run >out &&
286
- grep "Would apply" out &&
287
- write_script .git/hooks/p4-pre-submit <<-\EOF &&
288
- exit 1
289
- EOF
288
+ grep "Would apply" out
289
+ ) &&
290
+ test_hook -C "$git" --clobber p4-pre-submit <<-\EOF &&
291
+ exit 1
292
+ EOF
293
+ (
294
+ cd "$git" &&
295
test_must_fail git p4 submit --dry-run >errs 2>&1 &&
296
! grep "Would apply" errs
297
)