Skip to content

Commit 6b6fe8b

Browse files
rscharfegitster
authored andcommitted
t1800: loosen matching of error message for bad shebang
t1800.16 checks whether an attempt to run a hook script with a missing executable in its #! line fails and reports that error. The expected error message differs between platforms. The test handles two common variants, but on NonStop OS we get a third one: "fatal: cannot exec 'bad-hooks/test-hook': ...", which causes the test to fail there. We don't really care about the specific message text all that much here. Use grep and a single regex with alternations to ascertain that we get an error message (fatal or otherwise) about the failed invocation of the hook, but don't bother checking if we get the right variant for the platform the test is running on or whether quoting is done. This looser check let's the test pass on NonStop OS. Reported-by: Randall S. Becker <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1bd1d commit 6b6fe8b

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

t/t1800-hook.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,15 @@ test_expect_success 'git hook run a hook with a bad shebang' '
156156
mkdir bad-hooks &&
157157
write_script bad-hooks/test-hook "/bad/path/no/spaces" </dev/null &&
158158
159-
# TODO: We should emit the same (or at least a more similar)
160-
# error on MINGW (essentially Git for Windows) and all other
161-
# platforms.. See the OS-specific code in start_command()
162-
if test_have_prereq !MINGW
163-
then
164-
cat >expect <<-\EOF
165-
fatal: cannot run bad-hooks/test-hook: ...
166-
EOF
167-
else
168-
cat >expect <<-\EOF
169-
error: cannot spawn bad-hooks/test-hook: ...
170-
EOF
171-
fi &&
172159
test_expect_code 1 git \
173160
-c core.hooksPath=bad-hooks \
174161
hook run test-hook >out 2>err &&
175162
test_must_be_empty out &&
176-
sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
177-
test_cmp expect actual
163+
164+
# TODO: We should emit the same (or at least a more similar)
165+
# error on MINGW (essentially Git for Windows) and all other
166+
# platforms.. See the OS-specific code in start_command()
167+
grep -E "^(error|fatal): cannot (exec|run|spawn) .*bad-hooks/test-hook" err
178168
'
179169

180170
test_expect_success 'stdin to hooks' '

0 commit comments

Comments
 (0)