Skip to content

Commit c36f03c

Browse files
committed
test swift language directly
1 parent a26b631 commit c36f03c

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

testing/resources/swift_hooks_repo/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

testing/resources/swift_hooks_repo/.pre-commit-hooks.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

testing/resources/swift_hooks_repo/Package.swift

Lines changed: 0 additions & 7 deletions
This file was deleted.

testing/resources/swift_hooks_repo/Sources/swift_hooks_repo/main.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

testing/util.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import pytest
88

9-
from pre_commit import parse_shebang
109
from pre_commit.util import CalledProcessError
1110
from pre_commit.util import cmd_output
1211
from pre_commit.util import cmd_output_b
@@ -50,10 +49,6 @@ def cmd_output_mocked_pre_commit_home(
5049
os.name == 'nt',
5150
reason="lua isn't installed or can't be found",
5251
)
53-
skipif_cant_run_swift = pytest.mark.skipif(
54-
parse_shebang.find_executable('swift') is None,
55-
reason="swift isn't installed or can't be found",
56-
)
5752
xfailif_windows = pytest.mark.xfail(os.name == 'nt', reason='windows')
5853

5954

tests/languages/swift_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
import pytest
6+
7+
from pre_commit.languages import swift
8+
from testing.language_helpers import run_language
9+
10+
11+
@pytest.mark.skipif(
12+
sys.platform == 'win32',
13+
reason='swift is not supported on windows',
14+
)
15+
def test_swift_language(tmp_path): # pragma: win32 no cover
16+
package_swift = '''\
17+
// swift-tools-version:5.0
18+
import PackageDescription
19+
20+
let package = Package(
21+
name: "swift_hooks_repo",
22+
targets: [.target(name: "swift_hooks_repo")]
23+
)
24+
'''
25+
tmp_path.joinpath('Package.swift').write_text(package_swift)
26+
src_dir = tmp_path.joinpath('Sources/swift_hooks_repo')
27+
src_dir.mkdir(parents=True)
28+
src_dir.joinpath('main.swift').write_text('print("Hello, world!")\n')
29+
30+
expected = (0, b'Hello, world!\n')
31+
assert run_language(tmp_path, swift, 'swift_hooks_repo') == expected

tests/repository_test.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from testing.util import get_resource_path
3535
from testing.util import skipif_cant_run_docker
3636
from testing.util import skipif_cant_run_lua
37-
from testing.util import skipif_cant_run_swift
3837
from testing.util import xfailif_windows
3938

4039

@@ -329,14 +328,6 @@ def test_system_hook_with_spaces(tempdir_factory, store):
329328
)
330329

331330

332-
@skipif_cant_run_swift # pragma: win32 no cover
333-
def test_swift_hook(tempdir_factory, store):
334-
_test_hook_repo(
335-
tempdir_factory, store, 'swift_hooks_repo',
336-
'swift-hooks-repo', [], b'Hello, world!\n',
337-
)
338-
339-
340331
def test_golang_system_hook(tempdir_factory, store):
341332
_test_hook_repo(
342333
tempdir_factory, store, 'golang_hooks_repo',

0 commit comments

Comments
 (0)