mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
commit
f9b28cc2b0
13 changed files with 52 additions and 57 deletions
|
|
@ -5,7 +5,6 @@
|
|||
- The complete test suite depends on having at least the following installed
|
||||
(possibly not a complete list)
|
||||
- git (Version 2.24.0 or above is required to run pre-merge-commit tests)
|
||||
- python2 (Required by a test which checks different python versions)
|
||||
- python3 (Required by a test which checks different python versions)
|
||||
- tox (or virtualenv)
|
||||
- ruby + gem
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
import contextlib
|
||||
import functools
|
||||
import os.path
|
||||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
|
|
@ -99,10 +98,7 @@ def install_rust_with_toolchain(toolchain: str) -> None:
|
|||
if parse_shebang.find_executable('rustup') is None:
|
||||
# We did not detect rustup and need to download it first.
|
||||
if sys.platform == 'win32': # pragma: win32 cover
|
||||
if platform.machine() == 'x86_64':
|
||||
url = 'https://win.rustup.rs/x86_64'
|
||||
else:
|
||||
url = 'https://win.rustup.rs/i686'
|
||||
url = 'https://win.rustup.rs/x86_64'
|
||||
else: # pragma: win32 no cover
|
||||
url = 'https://sh.rustup.rs'
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
set -euo pipefail
|
||||
|
||||
. /etc/lsb-release
|
||||
if [ "$DISTRIB_CODENAME" = "focal" ]; then
|
||||
SWIFT_URL='https://download.swift.org/swift-5.6.1-release/ubuntu2004/swift-5.6.1-RELEASE/swift-5.6.1-RELEASE-ubuntu20.04.tar.gz'
|
||||
SWIFT_HASH='2b4f22d4a8b59fe8e050f0b7f020f8d8f12553cbda56709b2340a4a3bb90cfea'
|
||||
if [ "$DISTRIB_CODENAME" = "jammy" ]; then
|
||||
SWIFT_URL='https://download.swift.org/swift-5.7.1-release/ubuntu2204/swift-5.7.1-RELEASE/swift-5.7.1-RELEASE-ubuntu22.04.tar.gz'
|
||||
SWIFT_HASH='7f60291f5088d3e77b0c2364beaabd29616ee7b37260b7b06bdbeb891a7fe161'
|
||||
else
|
||||
echo "unknown dist: ${DISTRIB_CODENAME}" 1>&2
|
||||
exit 1
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6</TargetFramework>
|
||||
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<ToolCommandName>proj1</ToolCommandName>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6</TargetFramework>
|
||||
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<ToolCommandName>proj2</ToolCommandName>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net6</TargetFramework>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<ToolCommandName>testeroni</ToolCommandName>
|
||||
<PackageOutputPath>./nupkg</PackageOutputPath>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net6</TargetFramework>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<ToolCommandName>testeroni</ToolCommandName>
|
||||
<PackageOutputPath>./nupkg</PackageOutputPath>
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@
|
|||
name: Python 3 Hook
|
||||
entry: python3-hook
|
||||
language: python
|
||||
language_version: python3
|
||||
files: \.py$
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
name: Ruby Hook
|
||||
entry: ruby_hook
|
||||
language: ruby
|
||||
language_version: 2.5.1
|
||||
language_version: 3.1.0
|
||||
files: \.rb$
|
||||
|
|
|
|||
|
|
@ -71,10 +71,10 @@ def test_install_ruby_default(fake_gem_prefix):
|
|||
|
||||
@xfailif_windows # pragma: win32 no cover
|
||||
def test_install_ruby_with_version(fake_gem_prefix):
|
||||
ruby.install_environment(fake_gem_prefix, '2.7.2', ())
|
||||
ruby.install_environment(fake_gem_prefix, '3.1.0', ())
|
||||
|
||||
# Should be able to activate and use rbenv install
|
||||
with ruby.in_env(fake_gem_prefix, '2.7.2'):
|
||||
with ruby.in_env(fake_gem_prefix, '3.1.0'):
|
||||
cmd_output('rbenv', 'install', '--help')
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,3 +68,23 @@ def test_installs_with_bootstrapped_rustup(tmpdir, language_version):
|
|||
|
||||
with rust.in_env(prefix, language_version):
|
||||
assert cmd_output('hello_world')[1] == 'Hello, world!\n'
|
||||
|
||||
|
||||
def test_installs_with_existing_rustup(tmpdir):
|
||||
tmpdir.join('src', 'main.rs').ensure().write(
|
||||
'fn main() {\n'
|
||||
' println!("Hello, world!");\n'
|
||||
'}\n',
|
||||
)
|
||||
tmpdir.join('Cargo.toml').ensure().write(
|
||||
'[package]\n'
|
||||
'name = "hello_world"\n'
|
||||
'version = "0.1.0"\n'
|
||||
'edition = "2021"\n',
|
||||
)
|
||||
prefix = Prefix(str(tmpdir))
|
||||
|
||||
assert parse_shebang.find_executable('rustup') is not None
|
||||
rust.install_environment(prefix, '1.56.0', ())
|
||||
with rust.in_env(prefix, '1.56.0'):
|
||||
assert cmd_output('hello_world')[1] == 'Hello, world!\n'
|
||||
|
|
|
|||
|
|
@ -173,30 +173,20 @@ def test_python_venv(tempdir_factory, store):
|
|||
)
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover # no python 2 in GHA
|
||||
def test_switch_language_versions_doesnt_clobber(tempdir_factory, store):
|
||||
# We're using the python3 repo because it prints the python version
|
||||
path = make_repo(tempdir_factory, 'python3_hooks_repo')
|
||||
|
||||
def run_on_version(version, expected_output):
|
||||
config = make_config_from_repo(path)
|
||||
config['hooks'][0]['language_version'] = version
|
||||
hook = _get_hook(config, store, 'python3-hook')
|
||||
ret, out = _hook_run(hook, [], color=False)
|
||||
assert ret == 0
|
||||
assert _norm_out(out) == expected_output
|
||||
|
||||
run_on_version('python2', b'2\n[]\nHello World\n')
|
||||
run_on_version('python3', b'3\n[]\nHello World\n')
|
||||
|
||||
|
||||
def test_versioned_python_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'python3_hooks_repo',
|
||||
'python3-hook',
|
||||
[os.devnull],
|
||||
f'3\n[{os.devnull!r}]\nHello World\n'.encode(),
|
||||
)
|
||||
def test_language_versioned_python_hook(tempdir_factory, store):
|
||||
# we patch this force virtualenv executing with `-p` since we can't
|
||||
# reliably have multiple pythons available in CI
|
||||
with mock.patch.object(
|
||||
python,
|
||||
'_sys_executable_matches',
|
||||
return_value=False,
|
||||
):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'python3_hooks_repo',
|
||||
'python3-hook',
|
||||
[os.devnull],
|
||||
f'3\n[{os.devnull!r}]\nHello World\n'.encode(),
|
||||
)
|
||||
|
||||
|
||||
@skipif_cant_run_coursier # pragma: win32 no cover
|
||||
|
|
@ -345,7 +335,7 @@ def test_run_versioned_ruby_hook(tempdir_factory, store):
|
|||
tempdir_factory, store, 'ruby_versioned_hooks_repo',
|
||||
'ruby_hook',
|
||||
[os.devnull],
|
||||
b'2.5.1\nHello world from a ruby hook\n',
|
||||
b'3.1.0\nHello world from a ruby hook\n',
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -367,7 +357,7 @@ def test_run_ruby_hook_with_disable_shared_gems(
|
|||
tempdir_factory, store, 'ruby_versioned_hooks_repo',
|
||||
'ruby_hook',
|
||||
[os.devnull],
|
||||
b'2.5.1\nHello world from a ruby hook\n',
|
||||
b'3.1.0\nHello world from a ruby hook\n',
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -883,7 +873,7 @@ def test_tags_on_repositories(in_tmpdir, tempdir_factory, store):
|
|||
@pytest.fixture
|
||||
def local_python_config():
|
||||
# Make a "local" hooks repo that just installs our other hooks repo
|
||||
repo_path = get_resource_path('python3_hooks_repo')
|
||||
repo_path = get_resource_path('python_hooks_repo')
|
||||
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
||||
hooks = [
|
||||
dict(hook, additional_dependencies=[repo_path]) for hook in manifest
|
||||
|
|
@ -892,23 +882,12 @@ def local_python_config():
|
|||
|
||||
|
||||
def test_local_python_repo(store, local_python_config):
|
||||
hook = _get_hook(local_python_config, store, 'python3-hook')
|
||||
hook = _get_hook(local_python_config, store, 'foo')
|
||||
# language_version should have been adjusted to the interpreter version
|
||||
assert hook.language_version != C.DEFAULT
|
||||
ret, out = _hook_run(hook, ('filename',), color=False)
|
||||
assert ret == 0
|
||||
assert _norm_out(out) == b"3\n['filename']\nHello World\n"
|
||||
|
||||
|
||||
@xfailif_windows # pragma: win32 no cover # no python2 in GHA
|
||||
def test_local_python_repo_python2(store, local_python_config):
|
||||
local_python_config['hooks'][0]['language_version'] = 'python2'
|
||||
hook = _get_hook(local_python_config, store, 'python3-hook')
|
||||
# language_version should have been adjusted to the interpreter version
|
||||
assert hook.language_version != C.DEFAULT
|
||||
ret, out = _hook_run(hook, ('filename',), color=False)
|
||||
assert ret == 0
|
||||
assert _norm_out(out) == b"2\n['filename']\nHello World\n"
|
||||
assert _norm_out(out) == b"['filename']\nHello World\n"
|
||||
|
||||
|
||||
def test_default_language_version(store, local_python_config):
|
||||
|
|
|
|||
2
tox.ini
2
tox.ini
|
|
@ -3,7 +3,7 @@ envlist = py37,py38,pypy3,pre-commit
|
|||
|
||||
[testenv]
|
||||
deps = -rrequirements-dev.txt
|
||||
passenv = APPDATA HOME LOCALAPPDATA PROGRAMFILES RUSTUP_HOME
|
||||
passenv = *
|
||||
commands =
|
||||
coverage erase
|
||||
coverage run -m pytest {posargs:tests}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue