Skip to content

Move the remaining tests to Swift Testing - #227

Merged
swhitty merged 2 commits into
mainfrom
claude/swift-testing-migration-a8c46a
Nov 17, 2026
Merged

swhitty merged 2 commits into
mainfrom
claude/swift-testing-migration-a8c46a

Conversation

@swhitty

@swhitty swhitty commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Moves every remaining test to Swift Testing. The repo now has no XCTest.

  • git grep -l "import XCTest" finds nothing.
  • @Suite( only appears as @Suite(.serialized) on LogTests.
  • Every @Test sits inside an implicit struct suite; there are no free-standing tests.

Conversions

Converted 38 XCTestCase classes in SwiftDraw/Tests: LayerTree (18), Renderer (14), Utilities (4), CommandLine (2) and Formatter (2). Each is now a plain struct with @Test functions named for the behaviour, without the test prefix.

XCTest Swift Testing
XCTAssertEqual(…, accuracy:) #expect(a.isApproximately(b, tolerance:)), a new shared helper in Utilities/FloatingPoint+Approximately.swift
XCTAssertThrowsError #expect(throws:). The CommandLine argument and configuration tests check for CommandLine.Error.invalid. The SF Symbol tests use the returned error to check its message.
XCTUnwrap try #require
XCTFail Issue.record
XCTAssertNoThrow a plain try in a throws test
file/line helper parameters sourceLocation: SourceLocation = #_sourceLocation

Near-duplicate tests and loops became @Test(arguments:) in 25 places. Every tuple argument array has an explicit element type for Swift 6.2. Examples:

  • the CommandLine invalid-argument and invalid-configuration cases
  • the CoordinateFormatter precision tables
  • the SF Symbol clip bounds and stroke-scale parsing
  • invalid dasharrays
  • PNG and JPEG pattern tiles

Some tests that are near-duplicates were left as they are, because their argument types aren't Sendable. These are public CommandLine enums and package DOM enums. Making them Sendable would mean changing library sources.

Other changes:

  • MockRenderer.swift and LayerTree.TextPathTests.swift no longer import XCTest.

  • 13 display-name-only @Suite("…") attributes were removed from DOM/Tests.

  • AGENTS.md "Writing tests" now says:

    • Swift Testing only
    • implicit struct suites
    • @Suite only for traits
    • use the isApproximately helper
    • parallelism and @MainActor guidance

    The sentence about older XCTest suites is gone.

Parallelism and main thread

  • @Suite(.serialized): none added. No converted suite touches the shared filter cache, the SVG cache, CoreText font registration, the log sink, temporary files or static mutable state. The static var fixtures are computed properties, and every test builds its own renderer, bitmap and layers.
  • @MainActor: CGPaintFallbackTests and CGPatternTests. Both draw an NSImage into a bitmap made current with NSGraphicsContext.current.
  • @MainActor removed: the one on the old testShapeRect in Renderer.CoreGraphicsTypesTests. It only builds a CGPath.

The existing #if canImport(CoreGraphics) / AppKit / UIKit guards are kept. CGPath+SegmentTests now imports CoreText explicitly, since XCTest used to pull it in.

Test counts

Before After
XCTest methods 309 0
Swift Testing tests, SwiftDraw 785 1060 (the 309 XCTest methods became 275 @Test functions)
Swift Testing tests, DOM 442 442

The count drops by 34 because duplicates became argument cases; no coverage was removed.

Verification

  • swift test on macOS passed 10 times in a row.
  • ./container-run-tests.sh (Swift 6.4, Linux) passes.
  • SWIFT_VERSION=6.2 ./container-run-tests.sh passes, with 1257 tests. 6.2 rejected tx: 5 + 10 - 20 inside #expect until it moved into a typed local.
  • swift format lint --strict --recursive . is clean.

🤖 Generated with Claude Code

Suites are implicit structs; @suite is kept only where it sets a trait.
Converts the 38 XCTestCase classes in SwiftDraw/Tests (309 test methods)
to implicit struct suites with @test, using @test(arguments:) where tests
were near-duplicates. Adds FloatingPoint.isApproximately(_:tolerance:)
for the former XCTAssertEqual(_:_:accuracy:) checks.

AGENTS.md now documents Swift Testing only, implicit struct suites and
@suite only for traits.
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.59895% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.39%. Comparing base (746e237) to head (fdf23e4).

Files with missing lines Patch % Lines
...Tests/LayerTree/LayerTree.Builder.LayerTests.swift 71.42% 8 Missing ⚠️
...wiftDraw/Tests/Utilities/CGPath+SegmentTests.swift 71.42% 4 Missing ⚠️
...wiftDraw/Tests/LayerTree/LayerTree.DashTests.swift 95.45% 2 Missing ⚠️
...ts/LayerTree/LayerTree.CommandGeneratorTests.swift 98.11% 1 Missing ⚠️
...ftDraw/Tests/Renderer/Renderer.SFSymbolTests.swift 98.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #227      +/-   ##
==========================================
- Coverage   95.49%   95.39%   -0.11%     
==========================================
  Files         296      297       +1     
  Lines       35029    34541     -488     
==========================================
- Hits        33451    32949     -502     
- Misses       1578     1592      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@swhitty
swhitty merged commit ad1eb8c into main Nov 17, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant