Skip to content

Commit 003cdf8

Browse files
avargitster
authored andcommitted
bugreport tests: tighten up "git bugreport -s hooks" test
Amend a test added in 788a776 (bugreport: collect list of populated hooks, 2020-05-07) to "test_cmp" for the expected output, instead of selectively using "grep" to check for specific things we either expect or don't expect in the output. As noted in a preceding commit our .git/hooks directory already contains *.sample hooks, so we have no need to clobber the prepare-commit-msg.sample hook in particular. Instead we should assert that those *.sample hooks are not included in the output, and for good measure let's add a new "unknown-hook", to check that we only look through our own known hooks. See cfe853e (hook-list.h: add a generated list of hooks, like config-list.h, 2021-09-26) for how we generate that data. We're intentionally not piping the "actual" output through "sort" or similar, we'd also like to check that our reported hooks are sorted. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee32abd commit 003cdf8

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

t/t0091-bugreport.sh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,22 @@ test_expect_success 'can create leading directories outside of a git dir' '
6060

6161
test_expect_success 'indicates populated hooks' '
6262
test_when_finished rm git-bugreport-hooks.txt &&
63-
test_when_finished rm -fr .git/hooks &&
64-
rm -fr .git/hooks &&
65-
mkdir .git/hooks &&
66-
for hook in applypatch-msg prepare-commit-msg.sample
67-
do
68-
write_script ".git/hooks/$hook" <<-EOF || return 1
69-
echo "hook $hook exists"
70-
EOF
71-
done &&
63+
64+
test_hook applypatch-msg <<-\EOF &&
65+
true
66+
EOF
67+
test_hook unknown-hook <<-\EOF &&
68+
true
69+
EOF
7270
git bugreport -s hooks &&
73-
grep applypatch-msg git-bugreport-hooks.txt &&
74-
! grep prepare-commit-msg git-bugreport-hooks.txt
71+
72+
sort >expect <<-\EOF &&
73+
[Enabled Hooks]
74+
applypatch-msg
75+
EOF
76+
77+
sed -ne "/^\[Enabled Hooks\]$/,/^$/p" <git-bugreport-hooks.txt >actual &&
78+
test_cmp expect actual
7579
'
7680

7781
test_done

0 commit comments

Comments
 (0)