mirror of
https://github.com/unclebob/dryer.git
synced 2026-11-26 18:58:51 +00:00
Skip Swift test files the way the other languages skip theirs.
A Swift package keeps tests in Tests/ and names them *Tests.swift. Both were scanned as production code, so test helpers showed up as duplicate candidates. The suffix checks were one list already in spirit. Tests.swift joins that list, and Tests joins the skipped directories. Folding the old suffix branches into the list keeps the decision in one place. Proved: test_a_swift_package_skips_its_tests failed while reporting Sources/HiddenTests.swift and Tests/AppTests.swift, then passed with only Sources/App.swift. The existing test-name suite still passed. 91 tests. Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
co-authored by
Robert C. Martin
parent
ae38087644
commit
f667ad03ba
+23
-20
@@ -44,7 +44,27 @@ SKIP_DIRS = {
|
|||||||
".clj-kondo",
|
".clj-kondo",
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_DIRS = {"test", "tests", "spec", "specs", "__tests__"}
|
TEST_DIRS = {"test", "tests", "spec", "specs", "__tests__", "Tests"}
|
||||||
|
|
||||||
|
# One suffix list. Swift packages name XCTest files *Tests.swift.
|
||||||
|
_TEST_SUFFIXES = (
|
||||||
|
"_test.go",
|
||||||
|
"_test.clj",
|
||||||
|
"_test.cljc",
|
||||||
|
"_test.cljs",
|
||||||
|
"_test.cljd",
|
||||||
|
"_test.bb",
|
||||||
|
".test.ts",
|
||||||
|
".spec.ts",
|
||||||
|
".test.tsx",
|
||||||
|
".spec.tsx",
|
||||||
|
".test.mts",
|
||||||
|
".spec.mts",
|
||||||
|
".test.cts",
|
||||||
|
".spec.cts",
|
||||||
|
"_test.py",
|
||||||
|
"Tests.swift",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def language_of(path: str | Path) -> str | None:
|
def language_of(path: str | Path) -> str | None:
|
||||||
@@ -58,26 +78,9 @@ def language_of(path: str | Path) -> str | None:
|
|||||||
def is_test_file(path: str | Path) -> bool:
|
def is_test_file(path: str | Path) -> bool:
|
||||||
file_path = Path(path)
|
file_path = Path(path)
|
||||||
name = file_path.name
|
name = file_path.name
|
||||||
if name.endswith("_test.go"):
|
if name == "conftest.py" or name.endswith(_TEST_SUFFIXES):
|
||||||
return True
|
return True
|
||||||
if name.endswith(("_test.clj", "_test.cljc", "_test.cljs", "_test.cljd", "_test.bb")):
|
if name.startswith("test_") and name.endswith(".py"):
|
||||||
return True
|
|
||||||
if name.endswith(
|
|
||||||
(
|
|
||||||
".test.ts",
|
|
||||||
".spec.ts",
|
|
||||||
".test.tsx",
|
|
||||||
".spec.tsx",
|
|
||||||
".test.mts",
|
|
||||||
".spec.mts",
|
|
||||||
".test.cts",
|
|
||||||
".spec.cts",
|
|
||||||
)
|
|
||||||
):
|
|
||||||
return True
|
|
||||||
if name == "conftest.py":
|
|
||||||
return True
|
|
||||||
if name.endswith("_test.py") or (name.startswith("test_") and name.endswith(".py")):
|
|
||||||
return True
|
return True
|
||||||
return any(part in TEST_DIRS for part in file_path.parts)
|
return any(part in TEST_DIRS for part in file_path.parts)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from dryer.discover import iter_source_files, language_of
|
||||||
from dryer.extract import entries_in_source
|
from dryer.extract import entries_in_source
|
||||||
from dryer.scan import find_duplicates, scan_files
|
from dryer.scan import find_duplicates, scan_files
|
||||||
|
|
||||||
@@ -296,6 +297,16 @@ def test_swiftui_views_match_when_only_the_data_changes(tmp_path):
|
|||||||
assert _scored(tmp_path, RECEIPT, LABEL_VIEW) < 1.0
|
assert _scored(tmp_path, RECEIPT, LABEL_VIEW) < 1.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_swift_package_skips_its_tests(tmp_path):
|
||||||
|
body = "func alpha() -> Int {\n return 1\n}\n"
|
||||||
|
write_source(tmp_path, "Sources/App.swift", body)
|
||||||
|
write_source(tmp_path, "Tests/AppTests.swift", body)
|
||||||
|
write_source(tmp_path, "Sources/HiddenTests.swift", body)
|
||||||
|
relative = [path.relative_to(tmp_path).as_posix() for path in iter_source_files([tmp_path])]
|
||||||
|
assert language_of("Sources/App.swift") == "swift"
|
||||||
|
assert relative == ["Sources/App.swift"]
|
||||||
|
|
||||||
|
|
||||||
def test_a_top_level_swift_closure_matches_its_renamed_copy(tmp_path):
|
def test_a_top_level_swift_closure_matches_its_renamed_copy(tmp_path):
|
||||||
left = """\
|
left = """\
|
||||||
let alpha = { (xs: [Int]) -> [Int] in
|
let alpha = { (xs: [Int]) -> [Int] in
|
||||||
|
|||||||
Reference in New Issue
Block a user