Skip to content

Commit 262a5b4

Browse files
finestructurestephencelismbrandonw
authored
Add Swift 6.0 to Linux test matrix (#303)
* Add Swift 6.0 to Linux test matrix * wip * wip * debug * Revert "debug" This reverts commit 7c2278b. * Reapply "debug" This reverts commit 43c5eab. * wip * wip --------- Co-authored-by: Stephen Celis <[email protected]> Co-authored-by: Brandon Williams <[email protected]>
1 parent 29cbfe8 commit 262a5b4

File tree

5 files changed

+63
-42
lines changed

5 files changed

+63
-42
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
matrix:
6060
swift:
6161
- '5.10'
62+
- '6.0'
6263
name: Ubuntu (Swift ${{ matrix.swift }})
6364
runs-on: ubuntu-latest
6465
container: swift:${{ matrix.swift }}

Package.resolved

Lines changed: 26 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Dependencies/DependencyValues.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public struct DependencyValues: Sendable {
149149
.takeUnretainedValue()
150150
else { return }
151151
let testCaseWillStartBlock: @convention(block) (AnyObject) -> Void = { _ in
152-
DependencyValues._current.cachedValues.cached = [:]
152+
DependencyValues._current.cachedValues.resetCache()
153153
}
154154
let testCaseWillStartImp = imp_implementationWithBlock(testCaseWillStartBlock)
155155
class_addMethod(
@@ -167,7 +167,7 @@ public struct DependencyValues: Sendable {
167167
if isTesting {
168168
XCTestObservationCenter.shared.addTestObserver(
169169
TestObserver {
170-
DependencyValues._current.cachedValues.cached = [:]
170+
DependencyValues._current.cachedValues.resetCache()
171171
}
172172
)
173173
}
@@ -191,7 +191,7 @@ public struct DependencyValues: Sendable {
191191
}
192192
#endif
193193
pRegisterTestObserver?({
194-
DependencyValues._current.cachedValues.cached = [:]
194+
DependencyValues._current.cachedValues.resetCache()
195195
})
196196
#endif
197197
}
@@ -286,6 +286,8 @@ public struct DependencyValues: Sendable {
286286
reportIssue("Ignoring dependencies prepared in preview app entry point")
287287
return
288288
}
289+
cachedValues.lock.lock()
290+
defer { cachedValues.lock.unlock() }
289291
let cacheKey = CachedValues.CacheKey(id: TypeIdentifier(key), context: context)
290292
guard !cachedValues.cached.keys.contains(cacheKey) else {
291293
if cachedValues.cached[cacheKey]?.preparationID != DependencyValues.preparationID {
@@ -405,7 +407,7 @@ public struct DependencyValues: Sendable {
405407
message: "'resetCache' is no longer necessary for most (unparameterized) '@Test' cases"
406408
)
407409
public func resetCache() {
408-
cachedValues.cached = [:]
410+
cachedValues.resetCache()
409411
}
410412
}
411413

@@ -478,9 +480,15 @@ public final class CachedValues: @unchecked Sendable {
478480
let preparationID: UUID?
479481
}
480482

481-
private let lock = NSRecursiveLock()
483+
public let lock = NSRecursiveLock()
482484
public var cached = [CacheKey: CachedValue]()
483485

486+
public func resetCache() {
487+
lock.lock()
488+
defer { lock.unlock() }
489+
cached = [:]
490+
}
491+
484492
func value<Key: TestDependencyKey>(
485493
for key: Key.Type,
486494
context: DependencyContext,

Tests/DependenciesTests/CacheTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ final class CachedValueTests: XCTestCase {
55
override func tearDown() {
66
super.tearDown()
77
CacheLocals.$skipFailure.withValue(true) {
8-
DependencyValues._current.cachedValues.cached = [:]
8+
DependencyValues._current.cachedValues.resetCache()
99
}
1010
}
1111

Tests/DependenciesTests/DependencyValuesTests.swift

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -437,30 +437,33 @@ final class DependencyValuesTests: XCTestCase {
437437
self.wait(for: [expectation], timeout: 1)
438438
}
439439

440-
@MainActor
441-
func testEscapingInFeatureModel_InstanceVariablePropagated() async {
442-
let expectation = self.expectation(description: "escape")
443-
440+
// TODO: Remove this condition when Linux CI is updated to a more recent Swift 6.
441+
#if !os(Linux) || compiler(<6)
444442
@MainActor
445-
class FeatureModel /*: ObservableObject*/ {
446-
@Dependency(\.fullDependency) var fullDependency
447-
func doSomething(expectation: XCTestExpectation) {
448-
DispatchQueue.main.async {
449-
XCTAssertEqual(self.fullDependency.value, 42)
450-
expectation.fulfill()
443+
func testEscapingInFeatureModel_InstanceVariablePropagated() async {
444+
let expectation = self.expectation(description: "escape")
445+
446+
@MainActor
447+
class FeatureModel /*: ObservableObject*/ {
448+
@Dependency(\.fullDependency) var fullDependency
449+
func doSomething(expectation: XCTestExpectation) {
450+
DispatchQueue.main.async {
451+
XCTAssertEqual(self.fullDependency.value, 42)
452+
expectation.fulfill()
453+
}
451454
}
452455
}
453-
}
454456

455-
let model = withDependencies {
456-
$0.fullDependency.value = 42
457-
} operation: {
458-
FeatureModel()
459-
}
457+
let model = withDependencies {
458+
$0.fullDependency.value = 42
459+
} operation: {
460+
FeatureModel()
461+
}
460462

461-
model.doSomething(expectation: expectation)
462-
await fulfillment(of: [expectation], timeout: 1)
463-
}
463+
model.doSomething(expectation: expectation)
464+
await fulfillment(of: [expectation], timeout: 1)
465+
}
466+
#endif
464467

465468
func testEscapingInFeatureModel_NotPropagated() async {
466469
let expectation = self.expectation(description: "escape")

0 commit comments

Comments
 (0)