From 74df7228401237225caa4372e2917eaf947d1c79 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Tue, 22 Dec 2020 11:52:44 -0600 Subject: [PATCH] Add tests for hook executable bit --- test/test_hooks.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/test_hooks.py b/test/test_hooks.py index 01a524a..704636a 100644 --- a/test/test_hooks.py +++ b/test/test_hooks.py @@ -127,6 +127,39 @@ def test_escaped(runner, yadm_cmd, paths): 'a\\ b c\\\td e\\\\f\n') in run.out +@pytest.mark.parametrize('condition', ['exec', 'no-exec', 'mingw']) +def test_executable(runner, paths, condition): + """Verify hook must be exectuable""" + cmd = 'version' + hook = paths.hooks.join(f'pre_{cmd}') + hook.write('#!/bin/sh\necho HOOK\n') + hook.chmod(0o644) + if condition == 'exec': + hook.chmod(0o755) + + mingw = 'OPERATING_SYSTEM="MINGWx"' if condition == 'mingw' else '' + script = f""" + YADM_TEST=1 source {paths.pgm} + YADM_HOOKS="{paths.hooks}" + HOOK_COMMAND="{cmd}" + {mingw} + invoke_hook "pre" + """ + run = runner(command=['bash'], inp=script) + + if condition != 'mingw': + assert run.success + assert run.err == '' + else: + assert run.failure + assert 'Permission denied' in run.err + + if condition == 'exec': + assert 'HOOK' in run.out + elif condition == 'no-exec': + assert 'HOOK' not in run.out + + def create_hook(paths, name, code): """Create hook""" hook = paths.hooks.join(name)