Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimble 14: Fix broken tests in swift 6 #1169

Open
wants to merge 5 commits into
base: nimble-13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions .github/workflows/ci-swiftpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,12 @@ on:
- "*"

jobs:
swiftpm_darwin_monterey:
swiftpm_darwin_sonoma:
name: SwiftPM, Darwin, Xcode ${{ matrix.xcode }}
runs-on: macos-12
runs-on: macos-14
strategy:
matrix:
xcode: ["14.0.1", "14.1", "14.2"]
env:
DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode }}.app"
steps:
- uses: actions/checkout@v4
- run: ./test swiftpm

swiftpm_darwin_ventura:
name: SwiftPM, Darwin, Xcode ${{ matrix.xcode }}
runs-on: macos-13
strategy:
matrix:
xcode: ["14.3.1"]
xcode: ["15.0.1", "15.1", "15.2"]
env:
DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode }}.app"
steps:
Expand All @@ -41,8 +29,9 @@ jobs:
strategy:
matrix:
container:
- swift:5.7
- swift:5.8
- swift:5.9
- swift:5.10
- swift:6.0
# - swiftlang/swift:nightly
fail-fast: false
container: ${{ matrix.container }}
Expand Down
26 changes: 5 additions & 21 deletions .github/workflows/ci-xcode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,12 @@ on:
- "*"

jobs:
xcode_monterey:
xcode_sonoma:
name: Xcode ${{ matrix.xcode }} (Xcode Project)
runs-on: macos-12
runs-on: macos-14
strategy:
matrix:
xcode: ["14.0.1", "14.1", "14.2"]
fail-fast: false
env:
DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode }}.app"
steps:
- uses: actions/checkout@v4
- run: ./test macos
- run: ./test ios
- run: ./test tvos
- run: ./test watchos

xcode_ventura:
name: Xcode ${{ matrix.xcode }} (Xcode Project)
runs-on: macos-13
strategy:
matrix:
xcode: ["14.3.1"]
xcode: ["15.0.1", "15.1", "15.2"]
fail-fast: false
env:
DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode }}.app"
Expand All @@ -45,10 +29,10 @@ jobs:

xcode_spm:
name: Xcode ${{ matrix.xcode }} (Swift Package)
runs-on: macos-12
runs-on: macos-14
strategy:
matrix:
xcode: ["14.0.1"]
xcode: ["15.0.1", "15.1", "15.2"]
fail-fast: false
env:
DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode }}.app"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cocoapods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
cocoapods:
name: CocoaPods Lint
runs-on: macos-12
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:

jobs:
build-documentation:
runs-on: ubuntu-latest
runs-on: macos-14
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ on:

jobs:
carthage_archive:
name: Darwin, Xcode 14.0
runs-on: macos-12
name: Darwin, Xcode 15.0
runs-on: macos-14
strategy:
matrix:
xcode: ["14.0.1"]
xcode: ["15.0.1"]
env:
DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode }}.app"
steps:
Expand Down
4 changes: 4 additions & 0 deletions Nimble.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
898F28B025D9F4C30052B8D0 /* AlwaysFailMatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898F28AF25D9F4C30052B8D0 /* AlwaysFailMatcher.swift */; };
899441EF2902EE4B00C1FAF9 /* AsyncAwaitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 899441EE2902EE4B00C1FAF9 /* AsyncAwaitTest.swift */; };
899441F82902EF2500C1FAF9 /* DSL+AsyncAwait.swift in Sources */ = {isa = PBXBuildFile; fileRef = 899441F32902EF0900C1FAF9 /* DSL+AsyncAwait.swift */; };
8998C1082CBD9980009A3E1C /* BeLogical+Conformances.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8998C1072CBD9980009A3E1C /* BeLogical+Conformances.swift */; };
89B8C60F2C6476A6001F12D3 /* Negation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89B8C60E2C6476A6001F12D3 /* Negation.swift */; };
89B8C6112C6478F2001F12D3 /* NegationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89B8C6102C6478F2001F12D3 /* NegationTest.swift */; };
89C297CC2A911CDA002A143F /* AsyncTimerSequenceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89C297CB2A911CDA002A143F /* AsyncTimerSequenceTest.swift */; };
Expand Down Expand Up @@ -336,6 +337,7 @@
898F28AF25D9F4C30052B8D0 /* AlwaysFailMatcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlwaysFailMatcher.swift; sourceTree = "<group>"; };
899441EE2902EE4B00C1FAF9 /* AsyncAwaitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncAwaitTest.swift; sourceTree = "<group>"; };
899441F32902EF0900C1FAF9 /* DSL+AsyncAwait.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DSL+AsyncAwait.swift"; sourceTree = "<group>"; };
8998C1072CBD9980009A3E1C /* BeLogical+Conformances.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BeLogical+Conformances.swift"; sourceTree = "<group>"; };
89B8C60E2C6476A6001F12D3 /* Negation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Negation.swift; sourceTree = "<group>"; };
89B8C6102C6478F2001F12D3 /* NegationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NegationTest.swift; sourceTree = "<group>"; };
89C297CB2A911CDA002A143F /* AsyncTimerSequenceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncTimerSequenceTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -595,6 +597,7 @@
1FD8CD151968AB07008ED995 /* BeLessThan.swift */,
1FD8CD161968AB07008ED995 /* BeLessThanOrEqual.swift */,
1FD8CD171968AB07008ED995 /* BeLogical.swift */,
8998C1072CBD9980009A3E1C /* BeLogical+Conformances.swift */,
1FD8CD181968AB07008ED995 /* BeNil.swift */,
106112BC2251DFE7000A5848 /* BeResult.swift */,
1F91DD301C74BF61002C309F /* BeVoid.swift */,
Expand Down Expand Up @@ -900,6 +903,7 @@
7A0A26231E7F52360092A34E /* ToSucceed.swift in Sources */,
89F5E0862908E655001F9377 /* Polling+AsyncAwait.swift in Sources */,
897F84F42BA922B500BF354B /* NSLocking+Nimble.swift in Sources */,
8998C1082CBD9980009A3E1C /* BeLogical+Conformances.swift in Sources */,
899441F82902EF2500C1FAF9 /* DSL+AsyncAwait.swift in Sources */,
1FD8CD491968AB07008ED995 /* BeGreaterThanOrEqualTo.swift in Sources */,
1FE661571E6574E30035F243 /* ExpectationMessage.swift in Sources */,
Expand Down
10 changes: 8 additions & 2 deletions Sources/Nimble/AsyncExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ private final class MemoizedClosure<T: Sendable>: Sendable {
}

private let lock = NSRecursiveLock()
#if swift(>=5.10)
nonisolated(unsafe) private var _state = State.notStarted
nonisolated(unsafe) private var _continuations = [CheckedContinuation<T, Error>]()
nonisolated(unsafe) private var _task: Task<Void, Never>?
#else
private var _state = State.notStarted
private var _continuations = [CheckedContinuation<T, Error>]()
private var _task: Task<Void, Never>?
#endif

let closure: @Sendable () async throws -> T

Expand All @@ -25,9 +31,9 @@ private final class MemoizedClosure<T: Sendable>: Sendable {

@Sendable func callAsFunction(_ withoutCaching: Bool) async throws -> T {
if withoutCaching {
try await closure()
return try await closure()
} else {
try await withCheckedThrowingContinuation { continuation in
return try await withCheckedThrowingContinuation { continuation in
lock.withLock {
switch _state {
case .notStarted:
Expand Down
4 changes: 4 additions & 0 deletions Sources/Nimble/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import Foundation

private final class MemoizedValue<T>: Sendable {
private let lock = NSRecursiveLock()
#if swift(>=5.10)
nonisolated(unsafe) private var cache: T? = nil
#else
private var cache: T? = nil
#endif
private let closure: @Sendable () throws -> T

init(_ closure: @escaping @Sendable () throws -> T) {
Expand Down
150 changes: 150 additions & 0 deletions Sources/Nimble/Matchers/BeLogical+Conformances.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import Foundation

#if swift(>=6)
extension Int8: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int8Value
}
}

extension UInt8: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint8Value
}
}

extension Int16: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int16Value
}
}

extension UInt16: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint16Value
}
}

extension Int32: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int32Value
}
}

extension UInt32: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint32Value
}
}

extension Int64: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int64Value
}
}

extension UInt64: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint64Value
}
}

extension Float: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).floatValue
}
}

extension Double: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).doubleValue
}
}

extension Int: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).intValue
}
}

extension UInt: @retroactive ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uintValue
}
}

#else

extension Int8: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int8Value
}
}

extension UInt8: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint8Value
}
}

extension Int16: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int16Value
}
}

extension UInt16: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint16Value
}
}

extension Int32: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int32Value
}
}

extension UInt32: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint32Value
}
}

extension Int64: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).int64Value
}
}

extension UInt64: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uint64Value
}
}

extension Float: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).floatValue
}
}

extension Double: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).doubleValue
}
}

extension Int: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).intValue
}
}

extension UInt: ExpressibleByBooleanLiteral {
public init(booleanLiteral value: Bool) {
self = NSNumber(value: value).uintValue
}
}

#endif
Loading
Loading