From 07d5617ab2cf13e19190a3b2fc965ecbb9bb8453 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 18 Jun 2024 08:03:14 -0700 Subject: [PATCH] Swift Language Support: Drop <5.9, Add 6.0 (#84) * Swift 6 Language Mode * wip * wip * wip * wip * wip * wip * wip * wip --- .github/workflows/ci.yml | 50 ++++++++----------- Makefile | 24 --------- Package.swift | 2 +- Package@swift-6.0.swift | 31 ++++++++++++ .../Internal/RuntimeWarnings.swift | 15 ++++-- .../XCTestDynamicOverlay/Unimplemented.swift | 2 +- .../XCTExpectFailure.swift | 4 +- .../CurrentTestCaseTests.swift | 2 +- .../GeneratePlaceholderTests.swift | 6 ++- .../TestHelpers.swift | 12 ++--- 10 files changed, 78 insertions(+), 70 deletions(-) create mode 100644 Package@swift-6.0.swift diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 478fcba1..a756a5f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,20 +14,31 @@ concurrency: jobs: build: - name: MacOS - runs-on: macOS-latest + name: macOS + runs-on: macos-14 steps: - uses: actions/checkout@v4 + - name: Select Xcode + run: sudo xcode-select -s /Applications/Xcode_15.4.app - name: Run tests run: make test - ubuntu: - name: Ubuntu + linux: + strategy: + matrix: + swift: + - '5.10' + name: Ubuntu (Swift ${{ matrix.swift }}) runs-on: ubuntu-latest + container: swift:${{ matrix.swift }} steps: - - uses: actions/checkout@v4 - - name: Run tests - run: make test-linux + - uses: actions/checkout@v4 + - name: Install dependencies + run: apt-get update && apt-get install -y build-essential libcurl4-openssl-dev + - name: Run tests + run: make test + - name: Build for static-stdlib + run: make build-for-static-stdlib wasm: name: Wasm @@ -54,31 +65,10 @@ jobs: steps: - uses: compnerd/gha-setup-swift@main with: - branch: swift-5.8.1-release - tag: 5.8.1-RELEASE + branch: swift-5.10-release + tag: 5.10-RELEASE - uses: actions/checkout@v4 - name: Build run: swift build -c ${{ matrix.config }} - name: Run tests (debug only) - # There is an issue that exists in the 5.8.1 toolchain - # which fails on release configuration testing, but - # this issue is fixed 5.9 so we can remove the if once - # that is generally available. - if: ${{ matrix.config == 'debug' }} run: swift test - - static-stdlib: - name: Static standard library - strategy: - matrix: - os: [ubuntu-20.04] - runs-on: ${{ matrix.os }} - steps: - - uses: swift-actions/setup-swift@v1 - with: - swift-version: '5.8.0' - - name: Install dependencies - run: sudo apt-get install -y libcurl4-openssl-dev - - uses: actions/checkout@v4 - - name: Build for static-stdlib - run: make build-for-static-stdlib diff --git a/Makefile b/Makefile index 397a32ae..c7b698f4 100644 --- a/Makefile +++ b/Makefile @@ -14,30 +14,6 @@ test-debug: test: test-debug @swift test -c release -test-linux: test-debug - -test-linux: test - -test-linux-docker: - @docker run \ - --rm \ - -v "$(PWD):$(PWD)" \ - -w "$(PWD)" \ - swift:5.6.2-focal \ - bash -c "apt-get update && apt-get install make && make test" - -test-linux-static-stdlib: - @docker run \ - -v "$(PWD):$(PWD)" \ - -w "$(PWD)" \ - swift:5.6.2-focal \ - bash -c "swift build -c debug -Xswiftc -static-stdlib" - @docker run \ - -v "$(PWD):$(PWD)" \ - -w "$(PWD)" \ - swift:5.6.2-focal \ - bash -c "swift build -c release -Xswiftc -static-stdlib" - build-for-static-stdlib: @swift build -c debug --static-swift-stdlib @swift build -c release --static-swift-stdlib diff --git a/Package.swift b/Package.swift index d3658fcf..9c6f8c96 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.7 +// swift-tools-version: 5.9 import PackageDescription diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift new file mode 100644 index 00000000..84c70172 --- /dev/null +++ b/Package@swift-6.0.swift @@ -0,0 +1,31 @@ +// swift-tools-version: 6.0 + +import PackageDescription + +let package = Package( + name: "xctest-dynamic-overlay", + platforms: [ + .iOS(.v13), + .macOS(.v10_15), + .tvOS(.v13), + .watchOS(.v6), + ], + products: [ + .library(name: "XCTestDynamicOverlay", targets: ["XCTestDynamicOverlay"]) + ], + targets: [ + .target(name: "XCTestDynamicOverlay"), + .testTarget( + name: "XCTestDynamicOverlayTests", + dependencies: ["XCTestDynamicOverlay"] + ), + ], + swiftLanguageVersions: [.v6] +) + +#if !os(Windows) + // Add the documentation compiler plugin if possible + package.dependencies.append( + .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0") + ) +#endif diff --git a/Sources/XCTestDynamicOverlay/Internal/RuntimeWarnings.swift b/Sources/XCTestDynamicOverlay/Internal/RuntimeWarnings.swift index aaacd710..c66e033b 100644 --- a/Sources/XCTestDynamicOverlay/Internal/RuntimeWarnings.swift +++ b/Sources/XCTestDynamicOverlay/Internal/RuntimeWarnings.swift @@ -11,7 +11,7 @@ func runtimeWarn( #if DEBUG && canImport(os) os_log( .fault, - dso: dso, + dso: dso.wrappedValue, log: OSLog(subsystem: "com.apple.runtime-issues", category: "XCTestDynamicOverlay"), "%@", message() @@ -29,7 +29,7 @@ func runtimeWarn( // // Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc @usableFromInline - let dso = { () -> UnsafeMutableRawPointer in + let dso = UncheckedSendable({ () -> UnsafeMutableRawPointer in let count = _dyld_image_count() for i in 0..: @unchecked Sendable { + @usableFromInline + var wrappedValue: Value + init(_ value: Value) { + self.wrappedValue = value + } + } #endif diff --git a/Sources/XCTestDynamicOverlay/Unimplemented.swift b/Sources/XCTestDynamicOverlay/Unimplemented.swift index 9c22545c..9477e4d3 100644 --- a/Sources/XCTestDynamicOverlay/Unimplemented.swift +++ b/Sources/XCTestDynamicOverlay/Unimplemented.swift @@ -1487,7 +1487,7 @@ func _fail(_ description: String, _ parameters: Any?, fileID: StaticString, line Defined at: \(fileID):\(line) """ - if let parameters = parameters { + if let parameters { var parametersDescription = "" debugPrint(parameters, terminator: "", to: ¶metersDescription) debugDescription.append( diff --git a/Sources/XCTestDynamicOverlay/XCTExpectFailure.swift b/Sources/XCTestDynamicOverlay/XCTExpectFailure.swift index 839f0af4..389328ee 100644 --- a/Sources/XCTestDynamicOverlay/XCTExpectFailure.swift +++ b/Sources/XCTestDynamicOverlay/XCTExpectFailure.swift @@ -40,7 +40,7 @@ import Foundation return try failingBlock() } - if let issueMatcher = issueMatcher { + if let issueMatcher { let issueMatcher: @convention(block) (AnyObject) -> Bool = { issue in issueMatcher(_XCTIssue(issue)) } @@ -96,7 +96,7 @@ import Foundation return } - if let issueMatcher = issueMatcher { + if let issueMatcher { let issueMatcher: @convention(block) (AnyObject) -> Bool = { issue in issueMatcher(_XCTIssue(issue)) } diff --git a/Tests/XCTestDynamicOverlayTests/CurrentTestCaseTests.swift b/Tests/XCTestDynamicOverlayTests/CurrentTestCaseTests.swift index afa142da..2c6334ba 100644 --- a/Tests/XCTestDynamicOverlayTests/CurrentTestCaseTests.swift +++ b/Tests/XCTestDynamicOverlayTests/CurrentTestCaseTests.swift @@ -1,4 +1,4 @@ @_spi(CurrentTestCase) import XCTestDynamicOverlay // Make sure XCTCurrentTestCase is visible to SPI. -private let currentTestCase = XCTCurrentTestCase +@MainActor private let currentTestCase = XCTCurrentTestCase diff --git a/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift b/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift index 2dac2b0a..81bf605c 100644 --- a/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift +++ b/Tests/XCTestDynamicOverlayTests/GeneratePlaceholderTests.swift @@ -33,9 +33,11 @@ XCTFail("Stream should be finished") } - let throwingStream: () -> AsyncThrowingStream = unimplemented("throwingStream") + let throwingStream: @Sendable () -> AsyncThrowingStream = unimplemented( + "throwingStream" + ) let result = await Task { - try await XCTExpectFailure(failingBlock: throwingStream).first(where: { _ in true }) + try await XCTExpectFailure { throwingStream() }.first(where: { _ in true }) }.result XCTAssertThrowsError(try result.get()) { XCTAssertTrue($0 is CancellationError) } diff --git a/Tests/XCTestDynamicOverlayTests/TestHelpers.swift b/Tests/XCTestDynamicOverlayTests/TestHelpers.swift index 2d6df0d1..07106f51 100644 --- a/Tests/XCTestDynamicOverlayTests/TestHelpers.swift +++ b/Tests/XCTestDynamicOverlayTests/TestHelpers.swift @@ -95,12 +95,12 @@ struct Client { struct User { let id: UUID } -let f00: () -> Int = unimplemented("f00", placeholder: 42) -let f01: (String) -> Int = unimplemented("f01", placeholder: 42) -let f02: (String, Int) -> Int = unimplemented("f02", placeholder: 42) -let f03: (String, Int, Double) -> Int = unimplemented("f03", placeholder: 42) -let f04: (String, Int, Double, [Int]) -> Int = unimplemented("f04", placeholder: 42) -let f05: (String, Int, Double, [Int], User) -> Int = unimplemented("f05", placeholder: 42) +@MainActor let f00: () -> Int = unimplemented("f00", placeholder: 42) +@MainActor let f01: (String) -> Int = unimplemented("f01", placeholder: 42) +@MainActor let f02: (String, Int) -> Int = unimplemented("f02", placeholder: 42) +@MainActor let f03: (String, Int, Double) -> Int = unimplemented("f03", placeholder: 42) +@MainActor let f04: (String, Int, Double, [Int]) -> Int = unimplemented("f04", placeholder: 42) +@MainActor let f05: (String, Int, Double, [Int], User) -> Int = unimplemented("f05", placeholder: 42) private struct Autoclosing { init(