Skip to content
Merged
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
10 changes: 5 additions & 5 deletions Sources/DependenciesTestSupport/TestTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
/// - value: A dependency value to override for the test.
public static func dependency<Value>(
_ keyPath: WritableKeyPath<DependencyValues, Value> & Sendable,
_ value: sending Value
_ value: @autoclosure @escaping @Sendable () -> Value
) -> Self {
Self { [uncheckedValue = UncheckedSendable(value)] in
$0[keyPath: keyPath] = uncheckedValue.wrappedValue
Self {
$0[keyPath: keyPath] = value()
}
}

Expand Down Expand Up @@ -79,9 +79,9 @@
/// - keyPath: A key path to a dependency value.
/// - value: A dependency value to override for the test.
public static func dependency<Value: TestDependencyKey>(
_ value: Value
_ value: @autoclosure @escaping @Sendable () -> Value
) -> Self where Value == Value.Value {
Self { $0[Value.self] = value }
Self { $0[Value.self] = value() }
}

/// A trait that overrides a test's or suite's dependencies.
Expand Down
32 changes: 32 additions & 0 deletions Tests/DependenciesTests/TestTraitTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#if canImport(Testing)
import Dependencies
import DependenciesTestSupport
import Foundation
import Testing

@Suite(.dependency(\.uuid, .incrementing))
struct TestTraitTests {
@Dependency(\.uuid) var uuid

@Test func statefulDependency1() async throws {
for index in 0...100 {
#expect(uuid() == UUID(index))
try await Task.sleep(for: .milliseconds(1))
}
}

@Test func statefulDependency2() async throws {
for index in 0...100 {
#expect(uuid() == UUID(index))
try await Task.sleep(for: .milliseconds(1))
}
}

@Test func statefulDependency3() async throws {
for index in 0...100 {
#expect(uuid() == UUID(index))
try await Task.sleep(for: .milliseconds(1))
}
}
}
#endif