mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
get lua version from luarocks itself
This commit is contained in:
parent
3f8be7400d
commit
54331dca6f
3 changed files with 27 additions and 144 deletions
|
|
@ -1,55 +0,0 @@
|
|||
import os
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.languages import lua
|
||||
from testing.util import xfailif_windows
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'lua_name', ('lua', 'lua5.4', 'lua-5.4', 'lua5.4.exe'),
|
||||
)
|
||||
def test_find_lua(tmp_path, lua_name):
|
||||
"""The language support can find common lua executable names."""
|
||||
lua_file = tmp_path / lua_name
|
||||
lua_file.touch(0o555)
|
||||
with mock.patch.dict(os.environ, {'PATH': str(tmp_path)}):
|
||||
lua_executable = lua._find_lua(C.DEFAULT)
|
||||
assert lua_name in lua_executable
|
||||
|
||||
|
||||
def test_find_lua_language_version(tmp_path):
|
||||
"""Language discovery can find a specific version."""
|
||||
lua_file = tmp_path / 'lua5.99'
|
||||
lua_file.touch(0o555)
|
||||
with mock.patch.dict(os.environ, {'PATH': str(tmp_path)}):
|
||||
lua_executable = lua._find_lua('5.99')
|
||||
assert 'lua5.99' in lua_executable
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('invalid', 'mode'),
|
||||
(
|
||||
('foobar', 0o555),
|
||||
('luac', 0o555),
|
||||
# Windows doesn't respect the executable checking.
|
||||
pytest.param('lua5.4', 0o444, marks=xfailif_windows),
|
||||
),
|
||||
)
|
||||
def test_find_lua_fail(tmp_path, invalid, mode):
|
||||
"""No lua executable on the system will fail."""
|
||||
non_lua_file = tmp_path / invalid
|
||||
non_lua_file.touch(mode)
|
||||
with mock.patch.dict(os.environ, {'PATH': str(tmp_path)}):
|
||||
with pytest.raises(ValueError):
|
||||
lua._find_lua(C.DEFAULT)
|
||||
|
||||
|
||||
@mock.patch.object(lua, 'cmd_output')
|
||||
def test_bad_package_path(mock_cmd_output):
|
||||
"""A package path missing path info returns an unknown version."""
|
||||
mock_cmd_output.return_value = (0, '', '')
|
||||
with pytest.raises(ValueError):
|
||||
lua._get_lua_path_version('lua')
|
||||
|
|
@ -17,7 +17,6 @@ from pre_commit.envcontext import envcontext
|
|||
from pre_commit.hook import Hook
|
||||
from pre_commit.languages import golang
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages import lua
|
||||
from pre_commit.languages import node
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.languages import ruby
|
||||
|
|
@ -1142,18 +1141,17 @@ def test_lua_hook(tempdir_factory, store):
|
|||
|
||||
@skipif_cant_run_lua # pragma: win32 no cover
|
||||
def test_local_lua_additional_dependencies(store):
|
||||
lua_entry = lua._find_lua(C.DEFAULT)
|
||||
config = {
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'local-lua',
|
||||
'name': 'local-lua',
|
||||
'entry': lua_entry,
|
||||
'entry': 'luacheck --version',
|
||||
'language': 'lua',
|
||||
'args': ['-e', 'require "inspect"; print("hello world")'],
|
||||
'additional_dependencies': ['inspect'],
|
||||
'additional_dependencies': ['luacheck'],
|
||||
}],
|
||||
}
|
||||
hook = _get_hook(config, store, 'local-lua')
|
||||
ret, out = _hook_run(hook, (), color=False)
|
||||
assert (ret, _norm_out(out)) == (0, b'hello world\n')
|
||||
assert b'Luacheck' in out
|
||||
assert ret == 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue