test lua directly by asottile · Pull Request #2709 · pre-commit/pre-commit · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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