File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed
Sources/DependenciesTestSupport Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change 43
43
/// - value: A dependency value to override for the test.
44
44
public static func dependency< Value> (
45
45
_ keyPath: WritableKeyPath < DependencyValues , Value > & Sendable ,
46
- _ value: sending Value
46
+ _ value: @autoclosure @escaping @ Sendable ( ) -> Value
47
47
) -> Self {
48
- Self { [ uncheckedValue = UncheckedSendable ( value ) ] in
49
- $0 [ keyPath: keyPath] = uncheckedValue . wrappedValue
48
+ Self {
49
+ $0 [ keyPath: keyPath] = value ( )
50
50
}
51
51
}
52
52
79
79
/// - keyPath: A key path to a dependency value.
80
80
/// - value: A dependency value to override for the test.
81
81
public static func dependency< Value: TestDependencyKey > (
82
- _ value: Value
82
+ _ value: @autoclosure @escaping @ Sendable ( ) -> Value
83
83
) -> Self where Value == Value . Value {
84
- Self { $0 [ Value . self] = value }
84
+ Self { $0 [ Value . self] = value ( ) }
85
85
}
86
86
87
87
/// A trait that overrides a test's or suite's dependencies.
Original file line number Diff line number Diff line change
1
+ #if canImport(Testing)
2
+ import Dependencies
3
+ import DependenciesTestSupport
4
+ import Foundation
5
+ import Testing
6
+
7
+ @Suite ( . dependency( \. uuid, . incrementing) )
8
+ struct TestTraitTests {
9
+ @Dependency ( \. uuid) var uuid
10
+
11
+ @Test func statefulDependency1( ) async throws {
12
+ for index in 0 ... 100 {
13
+ #expect( uuid ( ) == UUID ( index) )
14
+ try await Task . sleep ( for: . milliseconds( 1 ) )
15
+ }
16
+ }
17
+
18
+ @Test func statefulDependency2( ) async throws {
19
+ for index in 0 ... 100 {
20
+ #expect( uuid ( ) == UUID ( index) )
21
+ try await Task . sleep ( for: . milliseconds( 1 ) )
22
+ }
23
+ }
24
+
25
+ @Test func statefulDependency3( ) async throws {
26
+ for index in 0 ... 100 {
27
+ #expect( uuid ( ) == UUID ( index) )
28
+ try await Task . sleep ( for: . milliseconds( 1 ) )
29
+ }
30
+ }
31
+ }
32
+ #endif
You can’t perform that action at this time.
0 commit comments