mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
xargs returns nonzero for negate + not found exe (fixes pcre + not found #447)
This commit is contained in:
parent
0e2c3c1ff9
commit
a157e1a63f
7 changed files with 49 additions and 11 deletions
|
|
@ -12,11 +12,13 @@ import pkg_resources
|
|||
import pytest
|
||||
|
||||
from pre_commit import five
|
||||
from pre_commit import parse_shebang
|
||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages import node
|
||||
from pre_commit.languages import pcre
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.languages import ruby
|
||||
from pre_commit.repository import Repository
|
||||
|
|
@ -187,6 +189,25 @@ def test_missing_executable(tempdir_factory, store):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_missing_pcre_support(tempdir_factory, store):
|
||||
orig_find_executable = parse_shebang.find_executable
|
||||
|
||||
def no_grep(exe, **kwargs):
|
||||
if exe == pcre.GREP:
|
||||
return None
|
||||
else:
|
||||
return orig_find_executable(exe, **kwargs)
|
||||
|
||||
with mock.patch.object(parse_shebang, 'find_executable', no_grep):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'pcre_hooks_repo',
|
||||
'regex-with-quotes', ['/dev/null'],
|
||||
'Executable `{}` not found'.format(pcre.GREP).encode('UTF-8'),
|
||||
expected_return_code=1,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_a_script_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import random
|
|||
import pytest
|
||||
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import memoize_by_cwd
|
||||
from pre_commit.util import tmpdir
|
||||
|
|
@ -81,3 +82,9 @@ def test_tmpdir():
|
|||
with tmpdir() as tempdir:
|
||||
assert os.path.exists(tempdir)
|
||||
assert not os.path.exists(tempdir)
|
||||
|
||||
|
||||
def test_cmd_output_exe_not_found():
|
||||
ret, out, _ = cmd_output('i-dont-exist', retcode=None)
|
||||
assert ret == 1
|
||||
assert out == 'Executable `i-dont-exist` not found'
|
||||
|
|
|
|||
|
|
@ -64,6 +64,11 @@ def test_xargs_negate():
|
|||
assert ret == 1
|
||||
|
||||
|
||||
def test_xargs_negate_command_not_found():
|
||||
ret, _, _ = xargs.xargs(('cmd-not-found',), ('1',), negate=True)
|
||||
assert ret != 0
|
||||
|
||||
|
||||
def test_xargs_retcode_normal():
|
||||
ret, _, _ = xargs.xargs(exit_cmd, ('0',), _max_length=max_length)
|
||||
assert ret == 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue