Adding upstream version 4.1.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
c4faf5b6cb
commit
a38bf5d420
14 changed files with 374 additions and 21 deletions
|
@ -1,10 +1,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages import docker_image
|
||||
from pre_commit.util import cmd_output_b
|
||||
from testing.language_helpers import run_language
|
||||
from testing.util import xfailif_windows
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope='module')
|
||||
def _ensure_image_available():
|
||||
cmd_output_b('docker', 'run', '--rm', 'ubuntu:22.04', 'echo')
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover
|
||||
def test_docker_image_hook_via_entrypoint(tmp_path):
|
||||
ret = run_language(
|
||||
|
|
|
@ -27,7 +27,7 @@ def _csproj(tool_name):
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6</TargetFramework>
|
||||
<TargetFramework>net8</TargetFramework>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<ToolCommandName>{tool_name}</ToolCommandName>
|
||||
<PackageOutputPath>./nupkg</PackageOutputPath>
|
||||
|
|
|
@ -11,11 +11,13 @@ from pre_commit.commands.install_uninstall import install
|
|||
from pre_commit.envcontext import envcontext
|
||||
from pre_commit.languages import golang
|
||||
from pre_commit.store import _make_local_repo
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import cmd_output
|
||||
from testing.fixtures import add_config_to_repo
|
||||
from testing.fixtures import make_config_from_repo
|
||||
from testing.language_helpers import run_language
|
||||
from testing.util import cmd_output_mocked_pre_commit_home
|
||||
from testing.util import cwd
|
||||
from testing.util import git_commit
|
||||
|
||||
|
||||
|
@ -165,3 +167,70 @@ def test_during_commit_all(tmp_path, tempdir_factory, store, in_git_dir):
|
|||
fn=cmd_output_mocked_pre_commit_home,
|
||||
tempdir_factory=tempdir_factory,
|
||||
)
|
||||
|
||||
|
||||
def test_automatic_toolchain_switching(tmp_path):
|
||||
go_mod = '''\
|
||||
module toolchain-version-test
|
||||
|
||||
go 1.23.1
|
||||
'''
|
||||
main_go = '''\
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
'''
|
||||
tmp_path.joinpath('go.mod').write_text(go_mod)
|
||||
mod_dir = tmp_path.joinpath('toolchain-version-test')
|
||||
mod_dir.mkdir()
|
||||
main_file = mod_dir.joinpath('main.go')
|
||||
main_file.write_text(main_go)
|
||||
|
||||
with pytest.raises(CalledProcessError) as excinfo:
|
||||
run_language(
|
||||
path=tmp_path,
|
||||
language=golang,
|
||||
version='1.22.0',
|
||||
exe='golang-version-test',
|
||||
)
|
||||
|
||||
assert 'go.mod requires go >= 1.23.1' in excinfo.value.stderr.decode()
|
||||
|
||||
|
||||
def test_automatic_toolchain_switching_go_fmt(tmp_path, monkeypatch):
|
||||
go_mod_hook = '''\
|
||||
module toolchain-version-test
|
||||
|
||||
go 1.22.0
|
||||
'''
|
||||
go_mod = '''\
|
||||
module toolchain-version-test
|
||||
|
||||
go 1.23.1
|
||||
'''
|
||||
main_go = '''\
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
'''
|
||||
hook_dir = tmp_path.joinpath('hook')
|
||||
hook_dir.mkdir()
|
||||
hook_dir.joinpath('go.mod').write_text(go_mod_hook)
|
||||
|
||||
test_dir = tmp_path.joinpath('test')
|
||||
test_dir.mkdir()
|
||||
test_dir.joinpath('go.mod').write_text(go_mod)
|
||||
main_file = test_dir.joinpath('main.go')
|
||||
main_file.write_text(main_go)
|
||||
|
||||
with cwd(test_dir):
|
||||
ret, out = run_language(
|
||||
path=hook_dir,
|
||||
language=golang,
|
||||
version='1.22.0',
|
||||
exe='go fmt',
|
||||
file_args=(str(main_file),),
|
||||
)
|
||||
|
||||
assert ret == 1
|
||||
assert 'go.mod requires go >= 1.23.1' in out.decode()
|
||||
|
|
97
tests/languages/julia_test.py
Normal file
97
tests/languages/julia_test.py
Normal file
|
@ -0,0 +1,97 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pre_commit.languages import julia
|
||||
from testing.language_helpers import run_language
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def _make_hook(tmp_path, julia_code):
|
||||
src_dir = tmp_path.joinpath('src')
|
||||
src_dir.mkdir()
|
||||
src_dir.joinpath('main.jl').write_text(julia_code)
|
||||
tmp_path.joinpath('Project.toml').write_text(
|
||||
'[deps]\n'
|
||||
'Example = "7876af07-990d-54b4-ab0e-23690620f79a"\n',
|
||||
)
|
||||
|
||||
|
||||
def test_julia_hook(tmp_path):
|
||||
code = """
|
||||
using Example
|
||||
function main()
|
||||
println("Hello, world!")
|
||||
end
|
||||
main()
|
||||
"""
|
||||
_make_hook(tmp_path, code)
|
||||
expected = (0, b'Hello, world!\n')
|
||||
assert run_language(tmp_path, julia, 'src/main.jl') == expected
|
||||
|
||||
|
||||
def test_julia_hook_manifest(tmp_path):
|
||||
code = """
|
||||
using Example
|
||||
println(pkgversion(Example))
|
||||
"""
|
||||
_make_hook(tmp_path, code)
|
||||
|
||||
tmp_path.joinpath('Manifest.toml').write_text(
|
||||
'manifest_format = "2.0"\n\n'
|
||||
'[[deps.Example]]\n'
|
||||
'git-tree-sha1 = "11820aa9c229fd3833d4bd69e5e75ef4e7273bf1"\n'
|
||||
'uuid = "7876af07-990d-54b4-ab0e-23690620f79a"\n'
|
||||
'version = "0.5.4"\n',
|
||||
)
|
||||
expected = (0, b'0.5.4\n')
|
||||
assert run_language(tmp_path, julia, 'src/main.jl') == expected
|
||||
|
||||
|
||||
def test_julia_hook_args(tmp_path):
|
||||
code = """
|
||||
function main(argv)
|
||||
foreach(println, argv)
|
||||
end
|
||||
main(ARGS)
|
||||
"""
|
||||
_make_hook(tmp_path, code)
|
||||
expected = (0, b'--arg1\n--arg2\n')
|
||||
assert run_language(
|
||||
tmp_path, julia, 'src/main.jl --arg1 --arg2',
|
||||
) == expected
|
||||
|
||||
|
||||
def test_julia_hook_additional_deps(tmp_path):
|
||||
code = """
|
||||
using TOML
|
||||
function main()
|
||||
project_file = Base.active_project()
|
||||
dict = TOML.parsefile(project_file)
|
||||
for (k, v) in dict["deps"]
|
||||
println(k, " = ", v)
|
||||
end
|
||||
end
|
||||
main()
|
||||
"""
|
||||
_make_hook(tmp_path, code)
|
||||
deps = ('TOML=fa267f1f-6049-4f14-aa54-33bafae1ed76',)
|
||||
ret, out = run_language(tmp_path, julia, 'src/main.jl', deps=deps)
|
||||
assert ret == 0
|
||||
assert b'Example = 7876af07-990d-54b4-ab0e-23690620f79a' in out
|
||||
assert b'TOML = fa267f1f-6049-4f14-aa54-33bafae1ed76' in out
|
||||
|
||||
|
||||
def test_julia_repo_local(tmp_path):
|
||||
env_dir = tmp_path.joinpath('envdir')
|
||||
env_dir.mkdir()
|
||||
local_dir = tmp_path.joinpath('local')
|
||||
local_dir.mkdir()
|
||||
local_dir.joinpath('local.jl').write_text(
|
||||
'using TOML; foreach(println, ARGS)',
|
||||
)
|
||||
with cwd(local_dir):
|
||||
deps = ('TOML=fa267f1f-6049-4f14-aa54-33bafae1ed76',)
|
||||
expected = (0, b'--local-arg1\n--local-arg2\n')
|
||||
assert run_language(
|
||||
env_dir, julia, 'local.jl --local-arg1 --local-arg2',
|
||||
deps=deps, is_local=True,
|
||||
) == expected
|
|
@ -286,7 +286,7 @@ def test_health_check_without_version(prefix, installed_environment, version):
|
|||
prefix, env_dir = installed_environment
|
||||
|
||||
# simulate old pre-commit install by unsetting the installed version
|
||||
r._execute_vanilla_r_code_as_script(
|
||||
r._execute_r_in_renv(
|
||||
f'renv::settings$r.version({version})',
|
||||
prefix=prefix, version=C.DEFAULT, cwd=env_dir,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue