Skip to content

Commit

Permalink
So much main actor
Browse files Browse the repository at this point in the history
  • Loading branch information
NickEntin committed Aug 29, 2024
1 parent 27fb23f commit b375010
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
18 changes: 11 additions & 7 deletions Example/ParalayoutSnapshotTests/SnapshotTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//

import SnapshotTesting
@preconcurrency import SnapshotTesting
import XCTest

class SnapshotTestCase: XCTestCase {
Expand All @@ -31,6 +31,7 @@ class SnapshotTestCase: XCTestCase {

// MARK: - Public Methods

@MainActor
func matchesCurrentDevice() -> Bool {
let device = UIDevice.current
let screen = UIScreen.main
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions ParalayoutTests/PixelRoundingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ParalayoutTests/ViewDistributionBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down

0 comments on commit b375010

Please sign in to comment.