Skip to content

Commit 50848aa

Browse files
authored
Merge pull request #2709 from pre-commit/test-lua
test lua directly
2 parents a0fc602 + f042540 commit 50848aa

File tree

6 files changed

+58
-53
lines changed

6 files changed

+58
-53
lines changed

testing/resources/lua_repo/.pre-commit-hooks.yaml

-4
This file was deleted.

testing/resources/lua_repo/bin/hello-world-lua

-3
This file was deleted.

testing/resources/lua_repo/hello-dev-1.rockspec

-15
This file was deleted.

testing/util.py

-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ def cmd_output_mocked_pre_commit_home(
4545
os.name == 'nt' or not docker_is_running(),
4646
reason="Docker isn't running or can't be accessed",
4747
)
48-
skipif_cant_run_lua = pytest.mark.skipif(
49-
os.name == 'nt',
50-
reason="lua isn't installed or can't be found",
51-
)
5248
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
5349

5450

tests/languages/lua_test.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
import pytest
6+
7+
from pre_commit.languages import lua
8+
from pre_commit.util import make_executable
9+
from testing.language_helpers import run_language
10+
11+
pytestmark = pytest.mark.skipif(
12+
sys.platform == 'win32',
13+
reason='lua is not supported on windows',
14+
)
15+
16+
17+
def test_lua(tmp_path): # pragma: win32 no cover
18+
rockspec = '''\
19+
package = "hello"
20+
version = "dev-1"
21+
22+
source = {
23+
url = "git+ssh://[email protected]/pre-commit/pre-commit.git"
24+
}
25+
description = {}
26+
dependencies = {}
27+
build = {
28+
type = "builtin",
29+
modules = {},
30+
install = {
31+
bin = {"bin/hello-world-lua"}
32+
},
33+
}
34+
'''
35+
hello_world_lua = '''\
36+
#!/usr/bin/env lua
37+
print('hello world')
38+
'''
39+
tmp_path.joinpath('hello-dev-1.rockspec').write_text(rockspec)
40+
bin_dir = tmp_path.joinpath('bin')
41+
bin_dir.mkdir()
42+
bin_file = bin_dir.joinpath('hello-world-lua')
43+
bin_file.write_text(hello_world_lua)
44+
make_executable(bin_file)
45+
46+
expected = (0, b'hello world\n')
47+
assert run_language(tmp_path, lua, 'hello-world-lua') == expected
48+
49+
50+
def test_lua_additional_dependencies(tmp_path): # pragma: win32 no cover
51+
ret, out = run_language(
52+
tmp_path,
53+
lua,
54+
'luacheck --version',
55+
deps=('luacheck',),
56+
)
57+
assert ret == 0
58+
assert out.startswith(b'Luacheck: ')

tests/repository_test.py

-27
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from testing.util import cwd
3434
from testing.util import get_resource_path
3535
from testing.util import skipif_cant_run_docker
36-
from testing.util import skipif_cant_run_lua
3736
from testing.util import xfailif_windows
3837

3938

@@ -993,29 +992,3 @@ def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
993992
'using language `system` which does not install an environment. '
994993
'Perhaps you meant to use a specific language?'
995994
)
996-
997-
998-
@skipif_cant_run_lua # pragma: win32 no cover
999-
def test_lua_hook(tempdir_factory, store):
1000-
_test_hook_repo(
1001-
tempdir_factory, store, 'lua_repo',
1002-
'hello-world-lua', [], b'hello world\n',
1003-
)
1004-
1005-
1006-
@skipif_cant_run_lua # pragma: win32 no cover
1007-
def test_local_lua_additional_dependencies(store):
1008-
config = {
1009-
'repo': 'local',
1010-
'hooks': [{
1011-
'id': 'local-lua',
1012-
'name': 'local-lua',
1013-
'entry': 'luacheck --version',
1014-
'language': 'lua',
1015-
'additional_dependencies': ['luacheck'],
1016-
}],
1017-
}
1018-
hook = _get_hook(config, store, 'local-lua')
1019-
ret, out = _hook_run(hook, (), color=False)
1020-
assert b'Luacheck' in out
1021-
assert ret == 0

0 commit comments

Comments
 (0)