Skip to content

Commit

Permalink
Add Swift 6.0 to Linux test matrix (#303)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Feb 25, 2025
1 parent 29cbfe8 commit 262a5b4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 42 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
matrix:
swift:
- '5.10'
- '6.0'
name: Ubuntu (Swift ${{ matrix.swift }})
runs-on: ubuntu-latest
container: swift:${{ matrix.swift }}
Expand Down
43 changes: 26 additions & 17 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
{
"originHash" : "46c7c52f0c1617cc1d5bc47663541c21a6e6734ddf2ad859bf5bf5bc207fa8f4",
"originHash" : "b0e46c8707f648cbd1d708418b9df17059d230dae6d9892053bdfb8d1d11715b",
"pins" : [
{
"identity" : "combine-schedulers",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "9fa31f4403da54855f1e2aeaeff478f4f0e40b13",
"version" : "1.0.2"
"revision" : "5928286acce13def418ec36d05a001a9641086f2",
"version" : "1.0.3"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "b9b24b69e2adda099a1fa381cda1eeec272d5b53",
"version" : "1.0.5"
"revision" : "cc46202b53476d64e824e0b6612da09d84ffde8e",
"version" : "1.0.6"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
"state" : {
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
"version" : "1.1.0"
"revision" : "82a4ae7170d98d8538ec77238b7eb8e7199ef2e8",
"version" : "1.3.1"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1",
"version" : "1.3.3"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "2eb22993b3dfd0c0d32729b357c8dabb6cd44680",
"version" : "1.4.2"
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
"version" : "1.4.3"
}
},
{
Expand All @@ -51,35 +60,35 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "20c1a8f3b624fb5d1503eadcaa84743050c350f4",
"version" : "0.5.2"
"revision" : "0b80a098d4805a21c412b65f01ffde7b01aab2fa",
"version" : "0.6.0"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
"version" : "1.17.4"
"revision" : "b2d4cb30735f4fbc3a01963a9c658336dd21e9ba",
"version" : "1.18.1"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
"version" : "600.0.0"
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "770f990d3e4eececb57ac04a6076e22f8c97daeb",
"version" : "1.4.2"
"revision" : "39de59b2d47f7ef3ca88a039dff3084688fe27f4",
"version" : "1.5.2"
}
}
],
Expand Down
18 changes: 13 additions & 5 deletions Sources/Dependencies/DependencyValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public struct DependencyValues: Sendable {
.takeUnretainedValue()
else { return }
let testCaseWillStartBlock: @convention(block) (AnyObject) -> Void = { _ in
DependencyValues._current.cachedValues.cached = [:]
DependencyValues._current.cachedValues.resetCache()
}
let testCaseWillStartImp = imp_implementationWithBlock(testCaseWillStartBlock)
class_addMethod(
Expand All @@ -167,7 +167,7 @@ public struct DependencyValues: Sendable {
if isTesting {
XCTestObservationCenter.shared.addTestObserver(
TestObserver {
DependencyValues._current.cachedValues.cached = [:]
DependencyValues._current.cachedValues.resetCache()
}
)
}
Expand All @@ -191,7 +191,7 @@ public struct DependencyValues: Sendable {
}
#endif
pRegisterTestObserver?({
DependencyValues._current.cachedValues.cached = [:]
DependencyValues._current.cachedValues.resetCache()
})
#endif
}
Expand Down Expand Up @@ -286,6 +286,8 @@ public struct DependencyValues: Sendable {
reportIssue("Ignoring dependencies prepared in preview app entry point")
return
}
cachedValues.lock.lock()
defer { cachedValues.lock.unlock() }
let cacheKey = CachedValues.CacheKey(id: TypeIdentifier(key), context: context)
guard !cachedValues.cached.keys.contains(cacheKey) else {
if cachedValues.cached[cacheKey]?.preparationID != DependencyValues.preparationID {
Expand Down Expand Up @@ -405,7 +407,7 @@ public struct DependencyValues: Sendable {
message: "'resetCache' is no longer necessary for most (unparameterized) '@Test' cases"
)
public func resetCache() {
cachedValues.cached = [:]
cachedValues.resetCache()
}
}

Expand Down Expand Up @@ -478,9 +480,15 @@ public final class CachedValues: @unchecked Sendable {
let preparationID: UUID?
}

private let lock = NSRecursiveLock()
public let lock = NSRecursiveLock()
public var cached = [CacheKey: CachedValue]()

public func resetCache() {
lock.lock()
defer { lock.unlock() }
cached = [:]
}

func value<Key: TestDependencyKey>(
for key: Key.Type,
context: DependencyContext,
Expand Down
2 changes: 1 addition & 1 deletion Tests/DependenciesTests/CacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ final class CachedValueTests: XCTestCase {
override func tearDown() {
super.tearDown()
CacheLocals.$skipFailure.withValue(true) {
DependencyValues._current.cachedValues.cached = [:]
DependencyValues._current.cachedValues.resetCache()
}
}

Expand Down
41 changes: 22 additions & 19 deletions Tests/DependenciesTests/DependencyValuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,30 +437,33 @@ final class DependencyValuesTests: XCTestCase {
self.wait(for: [expectation], timeout: 1)
}

@MainActor
func testEscapingInFeatureModel_InstanceVariablePropagated() async {
let expectation = self.expectation(description: "escape")

// TODO: Remove this condition when Linux CI is updated to a more recent Swift 6.
#if !os(Linux) || compiler(<6)
@MainActor
class FeatureModel /*: ObservableObject*/ {
@Dependency(\.fullDependency) var fullDependency
func doSomething(expectation: XCTestExpectation) {
DispatchQueue.main.async {
XCTAssertEqual(self.fullDependency.value, 42)
expectation.fulfill()
func testEscapingInFeatureModel_InstanceVariablePropagated() async {
let expectation = self.expectation(description: "escape")

@MainActor
class FeatureModel /*: ObservableObject*/ {
@Dependency(\.fullDependency) var fullDependency
func doSomething(expectation: XCTestExpectation) {
DispatchQueue.main.async {
XCTAssertEqual(self.fullDependency.value, 42)
expectation.fulfill()
}
}
}
}

let model = withDependencies {
$0.fullDependency.value = 42
} operation: {
FeatureModel()
}
let model = withDependencies {
$0.fullDependency.value = 42
} operation: {
FeatureModel()
}

model.doSomething(expectation: expectation)
await fulfillment(of: [expectation], timeout: 1)
}
model.doSomething(expectation: expectation)
await fulfillment(of: [expectation], timeout: 1)
}
#endif

func testEscapingInFeatureModel_NotPropagated() async {
let expectation = self.expectation(description: "escape")
Expand Down

0 comments on commit 262a5b4

Please sign in to comment.