mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2704 from pre-commit/swift-language-tests
test swift language directly
This commit is contained in:
commit
f5a365c2c8
7 changed files with 31 additions and 32 deletions
|
|
@ -1,4 +0,0 @@
|
||||||
.DS_Store
|
|
||||||
/.build
|
|
||||||
/Packages
|
|
||||||
/*.xcodeproj
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
- id: swift-hooks-repo
|
|
||||||
name: Swift hooks repo example
|
|
||||||
description: Runs the hello world app generated by swift package init --type executable (binary called swift_hooks_repo here)
|
|
||||||
entry: swift_hooks_repo
|
|
||||||
language: swift
|
|
||||||
files: \.(swift)$
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
// swift-tools-version:5.0
|
|
||||||
import PackageDescription
|
|
||||||
|
|
||||||
let package = Package(
|
|
||||||
name: "swift_hooks_repo",
|
|
||||||
targets: [.target(name: "swift_hooks_repo")]
|
|
||||||
)
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
print("Hello, world!")
|
|
||||||
|
|
@ -6,7 +6,6 @@ import subprocess
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pre_commit import parse_shebang
|
|
||||||
from pre_commit.util import CalledProcessError
|
from pre_commit.util import CalledProcessError
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
from pre_commit.util import cmd_output_b
|
from pre_commit.util import cmd_output_b
|
||||||
|
|
@ -50,10 +49,6 @@ skipif_cant_run_lua = pytest.mark.skipif(
|
||||||
os.name == 'nt',
|
os.name == 'nt',
|
||||||
reason="lua isn't installed or can't be found",
|
reason="lua isn't installed or can't be found",
|
||||||
)
|
)
|
||||||
skipif_cant_run_swift = pytest.mark.skipif(
|
|
||||||
parse_shebang.find_executable('swift') is None,
|
|
||||||
reason="swift isn't installed or can't be found",
|
|
||||||
)
|
|
||||||
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
|
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
31
tests/languages/swift_test.py
Normal file
31
tests/languages/swift_test.py
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pre_commit.languages import swift
|
||||||
|
from testing.language_helpers import run_language
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
sys.platform == 'win32',
|
||||||
|
reason='swift is not supported on windows',
|
||||||
|
)
|
||||||
|
def test_swift_language(tmp_path): # pragma: win32 no cover
|
||||||
|
package_swift = '''\
|
||||||
|
// swift-tools-version:5.0
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "swift_hooks_repo",
|
||||||
|
targets: [.target(name: "swift_hooks_repo")]
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
tmp_path.joinpath('Package.swift').write_text(package_swift)
|
||||||
|
src_dir = tmp_path.joinpath('Sources/swift_hooks_repo')
|
||||||
|
src_dir.mkdir(parents=True)
|
||||||
|
src_dir.joinpath('main.swift').write_text('print("Hello, world!")\n')
|
||||||
|
|
||||||
|
expected = (0, b'Hello, world!\n')
|
||||||
|
assert run_language(tmp_path, swift, 'swift_hooks_repo') == expected
|
||||||
|
|
@ -34,7 +34,6 @@ from testing.util import cwd
|
||||||
from testing.util import get_resource_path
|
from testing.util import get_resource_path
|
||||||
from testing.util import skipif_cant_run_docker
|
from testing.util import skipif_cant_run_docker
|
||||||
from testing.util import skipif_cant_run_lua
|
from testing.util import skipif_cant_run_lua
|
||||||
from testing.util import skipif_cant_run_swift
|
|
||||||
from testing.util import xfailif_windows
|
from testing.util import xfailif_windows
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -329,14 +328,6 @@ def test_system_hook_with_spaces(tempdir_factory, store):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@skipif_cant_run_swift # pragma: win32 no cover
|
|
||||||
def test_swift_hook(tempdir_factory, store):
|
|
||||||
_test_hook_repo(
|
|
||||||
tempdir_factory, store, 'swift_hooks_repo',
|
|
||||||
'swift-hooks-repo', [], b'Hello, world!\n',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_golang_system_hook(tempdir_factory, store):
|
def test_golang_system_hook(tempdir_factory, store):
|
||||||
_test_hook_repo(
|
_test_hook_repo(
|
||||||
tempdir_factory, store, 'golang_hooks_repo',
|
tempdir_factory, store, 'golang_hooks_repo',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue