Skip to content

Commit

Permalink
Fix Main Actor warnings (#113)
Browse files Browse the repository at this point in the history
The XCTestCase is not a Main Actor, inheriting it and adding the
MainActor property wrapper will cause the error after Swift 6
  • Loading branch information
CalvinChangCC authored Apr 16, 2024
2 parents 8fb4b8f + b6b8378 commit 4198742
Show file tree
Hide file tree
Showing 46 changed files with 782 additions and 491 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
@testable import SectionKit
import XCTest

@MainActor
internal final class CollectionViewContextExtensionsTests: XCTestCase {
// MARK: - dequeueReusableCell
final class CollectionViewContextExtensionsTests: XCTestCase {
private var context: MockCollectionViewContext!

internal func testDequeueReusableCellForIndexPathWithImplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableCell")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
@MainActor
override func setUp() {
super.setUp()
context = MockCollectionViewContext(
collectionView: UICollectionView(
frame: .zero,
collectionViewLayout: UICollectionViewFlowLayout()
),
errorHandler: MockErrorHandler()
)
}

override func tearDown() {
context = nil
super.tearDown()
}

// MARK: - dequeueReusableCell

@MainActor
func testDequeueReusableCellForIndexPathWithImplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableCell")
context._dequeueReusableCell = { cellType, indexPath in
XCTAssert(cellType === MockCollectionViewCell.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -21,12 +36,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {
waitForExpectations(timeout: 1)
}

internal func testDequeueReusableCellForSectionIndexPathWithExplicitType() {
@MainActor
func testDequeueReusableCellForSectionIndexPathWithExplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableCell")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableCell = { cellType, indexPath in
XCTAssert(cellType === MockCollectionViewCell.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -37,12 +49,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {
waitForExpectations(timeout: 1)
}

internal func testDequeueReusableCellForSectionIndexPathWithImplicitType() {
@MainActor
func testDequeueReusableCellForSectionIndexPathWithImplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableCell")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableCell = { cellType, indexPath in
XCTAssert(cellType === MockCollectionViewCell.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -55,12 +64,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {

// MARK: - dequeueReusableHeaderView

internal func testDequeueReusableHeaderViewForIndexPathWithImplicitType() {
@MainActor
func testDequeueReusableHeaderViewForIndexPathWithImplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableHeaderView")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableHeaderView = { cellType, indexPath in
XCTAssert(cellType === MockCollectionReusableView.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -71,12 +77,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {
waitForExpectations(timeout: 1)
}

internal func testDequeueReusableHeaderViewForSectionIndexPathWithExplicitType() {
@MainActor
func testDequeueReusableHeaderViewForSectionIndexPathWithExplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableHeaderView")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableHeaderView = { cellType, indexPath in
XCTAssert(cellType === MockCollectionReusableView.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -87,12 +90,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {
waitForExpectations(timeout: 1)
}

internal func testDequeueReusableHeaderViewForSectionIndexPathWithImplicitType() {
@MainActor
func testDequeueReusableHeaderViewForSectionIndexPathWithImplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableHeaderView")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableHeaderView = { cellType, indexPath in
XCTAssert(cellType === MockCollectionReusableView.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -105,12 +105,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {

// MARK: - dequeueReusableFooterView

internal func testDequeueReusableFooterViewForIndexPathWithImplicitType() {
@MainActor
func testDequeueReusableFooterViewForIndexPathWithImplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableFooterView")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableFooterView = { cellType, indexPath in
XCTAssert(cellType === MockCollectionReusableView.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -121,12 +118,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {
waitForExpectations(timeout: 1)
}

internal func testDequeueReusableFooterViewForSectionIndexPathWithExplicitType() {
@MainActor
func testDequeueReusableFooterViewForSectionIndexPathWithExplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableFooterView")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableFooterView = { cellType, indexPath in
XCTAssert(cellType === MockCollectionReusableView.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand All @@ -137,12 +131,9 @@ internal final class CollectionViewContextExtensionsTests: XCTestCase {
waitForExpectations(timeout: 1)
}

internal func testDequeueReusableFooterViewForSectionIndexPathWithImplicitType() {
@MainActor
func testDequeueReusableFooterViewForSectionIndexPathWithImplicitType() {
let testExpectation = expectation(description: "Should invoke dequeueReusableFooterView")
let context = MockCollectionViewContext(
collectionView: UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()),
errorHandler: MockErrorHandler()
)
context._dequeueReusableFooterView = { cellType, indexPath in
XCTAssert(cellType === MockCollectionReusableView.self)
XCTAssertEqual(indexPath, IndexPath(item: 0, section: 0))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@testable import SectionKit
import XCTest

@MainActor
internal final class CollectionViewContextSizeTests: XCTestCase {
internal func testContainerSize() {
final class CollectionViewContextSizeTests: XCTestCase {
@MainActor
func testContainerSize() {
let rect = CGRect(x: 1, y: 2, width: 4, height: 8)
let collectionView = UICollectionView(frame: rect, collectionViewLayout: UICollectionViewFlowLayout())
let context = MainCollectionViewContext(
Expand All @@ -14,7 +14,8 @@ internal final class CollectionViewContextSizeTests: XCTestCase {
XCTAssertEqual(context.containerSize, rect.size)
}

internal func testCustomContainerInset() {
@MainActor
func testCustomContainerInset() {
let insets = UIEdgeInsets(top: 1, left: 2, bottom: 4, right: 8)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
collectionView.contentInset = insets
Expand All @@ -26,7 +27,8 @@ internal final class CollectionViewContextSizeTests: XCTestCase {
XCTAssertEqual(context.customContainerInset, insets)
}

internal func testAdjustedContainerInset() {
@MainActor
func testAdjustedContainerInset() {
let insets = UIEdgeInsets(top: 1, left: 2, bottom: 4, right: 8)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
collectionView.contentInset = insets
Expand All @@ -38,7 +40,8 @@ internal final class CollectionViewContextSizeTests: XCTestCase {
XCTAssertEqual(context.adjustedContainerInset, insets)
}

internal func testInsetContainerSize() {
@MainActor
func testInsetContainerSize() {
let rect = CGRect(x: 16, y: 32, width: 64, height: 128)
let insets = UIEdgeInsets(top: 1, left: 2, bottom: 4, right: 8)
let collectionView = UICollectionView(frame: rect, collectionViewLayout: UICollectionViewFlowLayout())
Expand Down
Loading

0 comments on commit 4198742

Please sign in to comment.