mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
test lua directly
This commit is contained in:
parent
6014ebd2e7
commit
f042540311
6 changed files with 58 additions and 53 deletions
|
|
@ -1,4 +0,0 @@
|
||||||
- id: hello-world-lua
|
|
||||||
name: hello world lua
|
|
||||||
entry: hello-world-lua
|
|
||||||
language: lua
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/env lua
|
|
||||||
|
|
||||||
print('hello world')
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
package = "hello"
|
|
||||||
version = "dev-1"
|
|
||||||
|
|
||||||
source = {
|
|
||||||
url = "git+ssh://git@github.com/pre-commit/pre-commit.git"
|
|
||||||
}
|
|
||||||
description = {}
|
|
||||||
dependencies = {}
|
|
||||||
build = {
|
|
||||||
type = "builtin",
|
|
||||||
modules = {},
|
|
||||||
install = {
|
|
||||||
bin = {"bin/hello-world-lua"}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
@ -45,10 +45,6 @@ skipif_cant_run_docker = pytest.mark.skipif(
|
||||||
os.name == 'nt' or not docker_is_running(),
|
os.name == 'nt' or not docker_is_running(),
|
||||||
reason="Docker isn't running or can't be accessed",
|
reason="Docker isn't running or can't be accessed",
|
||||||
)
|
)
|
||||||
skipif_cant_run_lua = pytest.mark.skipif(
|
|
||||||
os.name == 'nt',
|
|
||||||
reason="lua isn't installed or can't be found",
|
|
||||||
)
|
|
||||||
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
|
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
58
tests/languages/lua_test.py
Normal file
58
tests/languages/lua_test.py
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pre_commit.languages import lua
|
||||||
|
from pre_commit.util import make_executable
|
||||||
|
from testing.language_helpers import run_language
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.skipif(
|
||||||
|
sys.platform == 'win32',
|
||||||
|
reason='lua is not supported on windows',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_lua(tmp_path): # pragma: win32 no cover
|
||||||
|
rockspec = '''\
|
||||||
|
package = "hello"
|
||||||
|
version = "dev-1"
|
||||||
|
|
||||||
|
source = {
|
||||||
|
url = "git+ssh://git@github.com/pre-commit/pre-commit.git"
|
||||||
|
}
|
||||||
|
description = {}
|
||||||
|
dependencies = {}
|
||||||
|
build = {
|
||||||
|
type = "builtin",
|
||||||
|
modules = {},
|
||||||
|
install = {
|
||||||
|
bin = {"bin/hello-world-lua"}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
hello_world_lua = '''\
|
||||||
|
#!/usr/bin/env lua
|
||||||
|
print('hello world')
|
||||||
|
'''
|
||||||
|
tmp_path.joinpath('hello-dev-1.rockspec').write_text(rockspec)
|
||||||
|
bin_dir = tmp_path.joinpath('bin')
|
||||||
|
bin_dir.mkdir()
|
||||||
|
bin_file = bin_dir.joinpath('hello-world-lua')
|
||||||
|
bin_file.write_text(hello_world_lua)
|
||||||
|
make_executable(bin_file)
|
||||||
|
|
||||||
|
expected = (0, b'hello world\n')
|
||||||
|
assert run_language(tmp_path, lua, 'hello-world-lua') == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_lua_additional_dependencies(tmp_path): # pragma: win32 no cover
|
||||||
|
ret, out = run_language(
|
||||||
|
tmp_path,
|
||||||
|
lua,
|
||||||
|
'luacheck --version',
|
||||||
|
deps=('luacheck',),
|
||||||
|
)
|
||||||
|
assert ret == 0
|
||||||
|
assert out.startswith(b'Luacheck: ')
|
||||||
|
|
@ -33,7 +33,6 @@ from testing.fixtures import modify_manifest
|
||||||
from testing.util import cwd
|
from testing.util import cwd
|
||||||
from testing.util import get_resource_path
|
from testing.util import get_resource_path
|
||||||
from testing.util import skipif_cant_run_docker
|
from testing.util import skipif_cant_run_docker
|
||||||
from testing.util import skipif_cant_run_lua
|
|
||||||
from testing.util import xfailif_windows
|
from testing.util import xfailif_windows
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1041,29 +1040,3 @@ def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
|
||||||
'using language `system` which does not install an environment. '
|
'using language `system` which does not install an environment. '
|
||||||
'Perhaps you meant to use a specific language?'
|
'Perhaps you meant to use a specific language?'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@skipif_cant_run_lua # pragma: win32 no cover
|
|
||||||
def test_lua_hook(tempdir_factory, store):
|
|
||||||
_test_hook_repo(
|
|
||||||
tempdir_factory, store, 'lua_repo',
|
|
||||||
'hello-world-lua', [], b'hello world\n',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@skipif_cant_run_lua # pragma: win32 no cover
|
|
||||||
def test_local_lua_additional_dependencies(store):
|
|
||||||
config = {
|
|
||||||
'repo': 'local',
|
|
||||||
'hooks': [{
|
|
||||||
'id': 'local-lua',
|
|
||||||
'name': 'local-lua',
|
|
||||||
'entry': 'luacheck --version',
|
|
||||||
'language': 'lua',
|
|
||||||
'additional_dependencies': ['luacheck'],
|
|
||||||
}],
|
|
||||||
}
|
|
||||||
hook = _get_hook(config, store, 'local-lua')
|
|
||||||
ret, out = _hook_run(hook, (), color=False)
|
|
||||||
assert b'Luacheck' in out
|
|
||||||
assert ret == 0
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue