diff --git a/Package.swift b/Package.swift index 491da38..8a1b338 100644 --- a/Package.swift +++ b/Package.swift @@ -39,7 +39,6 @@ let package = Package( if isDevelop { package.dependencies.append(contentsOf: [ - .package(url: "https://github.com/apple/swift-testing", exact: "0.3.0"), .package(url: "https://github.com/Alamofire/Alamofire.git", from: "5.10.0"), ]) if isObjcAvailable { @@ -53,7 +52,6 @@ if isDevelop { name: "StubNetworkKitTests", dependencies: [ "StubNetworkKit", - .product(name: "Testing", package: "swift-testing"), "Alamofire", ], resources: [.copy("_Fixtures")] @@ -63,6 +61,14 @@ if isDevelop { "APIKit", ]) } + #if compiler(<6.0) + package.dependencies.append(contentsOf: [ + .package(url: "https://github.com/apple/swift-testing", exact: "0.3.0"), + ]) + testTarget.dependencies.append(contentsOf: [ + .product(name: "Testing", package: "swift-testing"), + ]) + #endif package.targets.append(testTarget) if isObjcAvailable { diff --git a/Sources/StubNetworkKit/StubURLProtocol.swift b/Sources/StubNetworkKit/StubURLProtocol.swift index 27337fa..28068da 100644 --- a/Sources/StubNetworkKit/StubURLProtocol.swift +++ b/Sources/StubNetworkKit/StubURLProtocol.swift @@ -11,6 +11,8 @@ final class StubURLProtocol: URLProtocol { private(set) static var stubs: [Stub] = [] #endif + private static let lock = NSLock() + override static func canInit(with request: URLRequest) -> Bool { true } @@ -58,10 +60,14 @@ final class StubURLProtocol: URLProtocol { extension StubURLProtocol { static func register(_ stub: Stub) { + lock.lock() + defer { lock.unlock() } stubs.append(stub) } static func reset() { + lock.lock() + defer { lock.unlock() } stubs = [] } } diff --git a/TestPlan.xctestplan b/TestPlan.xctestplan index b39a742..1b0ae2f 100644 --- a/TestPlan.xctestplan +++ b/TestPlan.xctestplan @@ -11,7 +11,6 @@ "defaultOptions" : { "maximumTestRepetitions" : 3, "nsZombieEnabled" : true, - "repeatInNewRunnerProcess" : true, "testRepetitionMode" : "retryOnFailure", "testTimeoutsEnabled" : true }, diff --git a/Tests/StubNetworkKitTests/Examples/StubNetworkKitTests_SwiftTesting.swift b/Tests/StubNetworkKitTests/Examples/StubNetworkKitTests_SwiftTesting.swift index e0f40f1..5fb7952 100644 --- a/Tests/StubNetworkKitTests/Examples/StubNetworkKitTests_SwiftTesting.swift +++ b/Tests/StubNetworkKitTests/Examples/StubNetworkKitTests_SwiftTesting.swift @@ -5,7 +5,11 @@ import FoundationNetworking import Testing import StubNetworkKit +#if compiler(<6.0) @Suite +#else +@Suite(.serialized) +#endif final class StubNetworkKitTests_SwiftTesting { init() { StubNetworking.option(printDebugLog: true,