diff --git a/Example/ParalayoutSnapshotTests/SnapshotTestCase.swift b/Example/ParalayoutSnapshotTests/SnapshotTestCase.swift index 211220a..26623c8 100644 --- a/Example/ParalayoutSnapshotTests/SnapshotTestCase.swift +++ b/Example/ParalayoutSnapshotTests/SnapshotTestCase.swift @@ -14,7 +14,7 @@ // limitations under the License. // -import SnapshotTesting +@preconcurrency import SnapshotTesting import XCTest class SnapshotTestCase: XCTestCase { @@ -31,6 +31,7 @@ class SnapshotTestCase: XCTestCase { // MARK: - Public Methods + @MainActor func matchesCurrentDevice() -> Bool { let device = UIDevice.current let screen = UIScreen.main @@ -56,18 +57,21 @@ class SnapshotTestCase: XCTestCase { // MARK: - XCTestCase - override class func setUp() { - super.setUp() + override func setUp() async throws { + try await super.setUp() - guard SnapshotTestCase.testedDevices.contains(where: { $0.matchesCurrentDevice() }) else { - fatalError("Attempting to run tests on a device for which we have not collected test data") - } + await Task { @MainActor in + guard SnapshotTestCase.testedDevices.contains(where: { $0.matchesCurrentDevice() }) else { + fatalError("Attempting to run tests on a device for which we have not collected test data") + } - isRecording = false + isRecording = false + }.value } // MARK: - Public Methods + @MainActor func nameForSnapshot(with parameters: [String?]) -> String { let size = UIScreen.main.bounds.size let scale = UIScreen.main.scale diff --git a/Example/ParalayoutSnapshotTests/ViewDistributionSnapshotTests.swift b/Example/ParalayoutSnapshotTests/ViewDistributionSnapshotTests.swift index 7a63b0e..fd2f9f7 100644 --- a/Example/ParalayoutSnapshotTests/ViewDistributionSnapshotTests.swift +++ b/Example/ParalayoutSnapshotTests/ViewDistributionSnapshotTests.swift @@ -19,6 +19,7 @@ import SnapshotTesting final class ViewDistributionSnapshotTests: SnapshotTestCase { + @MainActor func testDistribution() { let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200)) containerView.backgroundColor = .white @@ -45,6 +46,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase { assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: ["vertical"])) } + @MainActor func testDistributionIgnoresTransform() { let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200)) containerView.backgroundColor = .white @@ -72,6 +74,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase { assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: [])) } + @MainActor func testDistributionUsingCapInsets() { let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 80)) containerView.backgroundColor = .white @@ -104,6 +107,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase { assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: [])) } + @MainActor func testHorizontalDistributionFollowsLayoutDirection() { let view = HorizontalDistributionView(frame: CGRect(x: 0, y: 0, width: 160, height: 60)) diff --git a/Example/ParalayoutSnapshotTests/ViewSpreadingSnapshotTests.swift b/Example/ParalayoutSnapshotTests/ViewSpreadingSnapshotTests.swift index 6c03698..b86c8c8 100644 --- a/Example/ParalayoutSnapshotTests/ViewSpreadingSnapshotTests.swift +++ b/Example/ParalayoutSnapshotTests/ViewSpreadingSnapshotTests.swift @@ -19,6 +19,7 @@ import SnapshotTesting final class ViewSpeadingSnapshotTests: SnapshotTestCase { + @MainActor func testHorizontallySpreadSubviews() { let container = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 100)) container.backgroundColor = .white @@ -92,6 +93,7 @@ final class ViewSpeadingSnapshotTests: SnapshotTestCase { verifySnapshot(margin: 40, inRect: CGRect(x: 20, y: 10, width: 300, height: 50)) } + @MainActor func testVerticallySpreadSubviews() { let container = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 100)) container.backgroundColor = .white diff --git a/ParalayoutTests/PixelRoundingTests.swift b/ParalayoutTests/PixelRoundingTests.swift index 7f2e43f..357fcac 100644 --- a/ParalayoutTests/PixelRoundingTests.swift +++ b/ParalayoutTests/PixelRoundingTests.swift @@ -30,11 +30,12 @@ final class PixelRoundingTests: XCTestCase { // MARK: - XCTest - @MainActor - override func setUp() { - super.setUp() + override func setUp() async throws { + try await super.setUp() - Samples.window.addSubview(Samples.view) + await Task { @MainActor in + Samples.window.addSubview(Samples.view) + }.value } // MARK: - Tests - Pixel Rounding diff --git a/ParalayoutTests/ViewDistributionBuilderTests.swift b/ParalayoutTests/ViewDistributionBuilderTests.swift index 1353ec7..8937188 100644 --- a/ParalayoutTests/ViewDistributionBuilderTests.swift +++ b/ParalayoutTests/ViewDistributionBuilderTests.swift @@ -201,6 +201,7 @@ final class ViewDistributionBuilderTests: XCTestCase { #endif extension ViewDistributionItem: Equatable { + nonisolated public static func == (lhs: ViewDistributionItem, rhs: ViewDistributionItem) -> Bool { switch (lhs, rhs) { case let (.view(lhsView, lhsEdgeInsets), .view(rhsView, rhsEdgeInsets)):