Skip to content

Commit

Permalink
Merge pull request #2709 from pre-commit/test-lua
Browse files Browse the repository at this point in the history
test lua directly
  • Loading branch information
asottile authored Jan 18, 2023
2 parents a0fc602 + f042540 commit 50848aa
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 53 deletions.
4 changes: 0 additions & 4 deletions testing/resources/lua_repo/.pre-commit-hooks.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions testing/resources/lua_repo/bin/hello-world-lua

This file was deleted.

15 changes: 0 additions & 15 deletions testing/resources/lua_repo/hello-dev-1.rockspec

This file was deleted.

4 changes: 0 additions & 4 deletions testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def cmd_output_mocked_pre_commit_home(
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')


Expand Down
58 changes: 58 additions & 0 deletions tests/languages/lua_test.py
Original file line number Diff line number Diff line change
@@ -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: ')
27 changes: 0 additions & 27 deletions tests/repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
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


Expand Down Expand Up @@ -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

0 comments on commit 50848aa

Please sign in to comment.