Skip to content

Commit f042540

Browse files
committed
test lua directly
1 parent 6014ebd commit f042540

File tree

6 files changed

+58
-53
lines changed

6 files changed

+58
-53
lines changed

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

testing/util.py

Lines changed: 0 additions & 4 deletions
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

Lines changed: 58 additions & 0 deletions
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://git@github.com/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

Lines changed: 0 additions & 27 deletions
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

@@ -1041,29 +1040,3 @@ def test_non_installable_hook_error_for_additional_dependencies(store, caplog):
10411040
'using language `system` which does not install an environment. '
10421041
'Perhaps you meant to use a specific language?'
10431042
)
1044-
1045-
1046-
@skipif_cant_run_lua # pragma: win32 no cover
1047-
def test_lua_hook(tempdir_factory, store):
1048-
_test_hook_repo(
1049-
tempdir_factory, store, 'lua_repo',
1050-
'hello-world-lua', [], b'hello world\n',
1051-
)
1052-
1053-
1054-
@skipif_cant_run_lua # pragma: win32 no cover
1055-
def test_local_lua_additional_dependencies(store):
1056-
config = {
1057-
'repo': 'local',
1058-
'hooks': [{
1059-
'id': 'local-lua',
1060-
'name': 'local-lua',
1061-
'entry': 'luacheck --version',
1062-
'language': 'lua',
1063-
'additional_dependencies': ['luacheck'],
1064-
}],
1065-
}
1066-
hook = _get_hook(config, store, 'local-lua')
1067-
ret, out = _hook_run(hook, (), color=False)
1068-
assert b'Luacheck' in out
1069-
assert ret == 0

0 commit comments

Comments
 (0)