Merge pull request #2709 from pre-commit/test-lua · hack3ric/pre-commit@50848aa · GitHub
Skip to content

Commit 50848aa

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

6 files changed

Lines changed: 58 additions & 53 deletions

File tree

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

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

0 commit comments

Comments
 (0)