mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 04:50:20 -06:00
@@ -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(),
|
||||
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')
|
||||
|
||||
|
||||
|
||||
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 get_resource_path
|
||||
from testing.util import skipif_cant_run_docker
|
||||
from testing.util import skipif_cant_run_lua
|
||||
from testing.util import xfailif_windows
|
||||
|
||||
|
||||
@@ -993,29 +992,3 @@ def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
|
||||
'using language `system` which does not install an environment. '
|
||||
'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
|
||||
|
||||
Reference in New Issue
Block a user