@@ -7,122 +7,121 @@ import XCTest
7
7
8
8
// `@MainActor` introduces issues gathering tests on Linux
9
9
#if !os(Linux)
10
- @MainActor
11
- final class EffectRunTests : XCTestCase {
12
- func testRun( ) async {
13
- struct State : Equatable { }
14
- enum Action : Equatable { case tapped, response }
15
- let reducer = Reduce < State , Action > { state, action in
16
- switch action {
17
- case . tapped:
18
- return . run { send in await send ( . response) }
19
- case . response:
20
- return . none
21
- }
10
+ @MainActor
11
+ final class EffectRunTests : XCTestCase {
12
+ func testRun( ) async {
13
+ struct State : Equatable { }
14
+ enum Action : Equatable { case tapped, response }
15
+ let reducer = Reduce < State , Action > { state, action in
16
+ switch action {
17
+ case . tapped:
18
+ return . run { send in await send ( . response) }
19
+ case . response:
20
+ return . none
22
21
}
23
- let store = TestStore ( initialState: State ( ) , reducer: reducer)
24
- await store. send ( . tapped)
25
- await store. receive ( . response)
26
22
}
23
+ let store = TestStore ( initialState: State ( ) , reducer: reducer)
24
+ await store. send ( . tapped)
25
+ await store. receive ( . response)
26
+ }
27
27
28
- func testRunCatch( ) async {
29
- struct State : Equatable { }
30
- enum Action : Equatable { case tapped, response }
31
- let reducer = Reduce < State , Action > { state, action in
32
- switch action {
33
- case . tapped:
34
- return . run { _ in
35
- struct Failure : Error { }
36
- throw Failure ( )
37
- } catch: { @Sendable _, send in // NB: Explicit '@Sendable' required in 5.5.2
38
- await send ( . response)
39
- }
40
- case . response:
41
- return . none
28
+ func testRunCatch( ) async {
29
+ struct State : Equatable { }
30
+ enum Action : Equatable { case tapped, response }
31
+ let reducer = Reduce < State , Action > { state, action in
32
+ switch action {
33
+ case . tapped:
34
+ return . run { _ in
35
+ struct Failure : Error { }
36
+ throw Failure ( )
37
+ } catch: { @Sendable _, send in // NB: Explicit '@Sendable' required in 5.5.2
38
+ await send ( . response)
42
39
}
40
+ case . response:
41
+ return . none
43
42
}
44
- let store = TestStore ( initialState: State ( ) , reducer: reducer)
45
- await store. send ( . tapped)
46
- await store. receive ( . response)
47
43
}
44
+ let store = TestStore ( initialState: State ( ) , reducer: reducer)
45
+ await store. send ( . tapped)
46
+ await store. receive ( . response)
47
+ }
48
48
49
49
// `XCTExpectFailure` is not supported on Linux
50
50
#if DEBUG && !os(Linux)
51
- func testRunUnhandledFailure( ) async {
52
- var line : UInt !
53
- XCTExpectFailure ( nil , enabled: nil , strict: nil ) {
54
- $0. compactDescription == """
55
- An " EffectTask.run " returned from \
56
- " ComposableArchitectureTests/EffectRunTests.swift: \( line+ 1 ) " threw an unhandled error. …
51
+ func testRunUnhandledFailure( ) async {
52
+ var line : UInt !
53
+ XCTExpectFailure ( nil , enabled: nil , strict: nil ) {
54
+ $0. compactDescription == """
55
+ An " EffectTask.run " returned from " \( #fileID) : \( line+ 1 ) " threw an unhandled error. …
57
56
58
- EffectRunTests.Failure()
57
+ EffectRunTests.Failure()
59
58
60
- All non-cancellation errors must be explicitly handled via the " catch " parameter on \
61
- " EffectTask.run " , or via a " do " block.
62
- """
63
- }
64
- struct State : Equatable { }
65
- enum Action : Equatable { case tapped, response }
66
- let reducer = Reduce < State , Action > { state, action in
67
- switch action {
68
- case . tapped:
69
- line = #line
70
- return . run { send in
71
- struct Failure : Error { }
72
- throw Failure ( )
73
- }
74
- case . response:
75
- return . none
76
- }
77
- }
78
- let store = TestStore ( initialState: State ( ) , reducer: reducer)
79
- // NB: We wait a long time here because XCTest failures take a long time to generate
80
- await store. send ( . tapped) . finish ( timeout: 5 * NSEC_PER_SEC)
59
+ All non-cancellation errors must be explicitly handled via the " catch " parameter on \
60
+ " EffectTask.run " , or via a " do " block.
61
+ """
81
62
}
82
- #endif
83
-
84
- func testRunCancellation( ) async {
85
- enum CancelID { }
86
63
struct State : Equatable { }
87
64
enum Action : Equatable { case tapped, response }
88
65
let reducer = Reduce < State , Action > { state, action in
89
66
switch action {
90
67
case . tapped:
68
+ line = #line
91
69
return . run { send in
92
- Task . cancel ( id: CancelID . self)
93
- try Task . checkCancellation ( )
94
- await send ( . response)
70
+ struct Failure : Error { }
71
+ throw Failure ( )
95
72
}
96
- . cancellable ( id: CancelID . self)
97
73
case . response:
98
74
return . none
99
75
}
100
76
}
101
77
let store = TestStore ( initialState: State ( ) , reducer: reducer)
102
- await store. send ( . tapped) . finish ( )
78
+ // NB: We wait a long time here because XCTest failures take a long time to generate
79
+ await store. send ( . tapped) . finish ( timeout: 5 * NSEC_PER_SEC)
103
80
}
81
+ #endif
104
82
105
- func testRunCancellationCatch( ) async {
106
- enum CancelID { }
107
- struct State : Equatable { }
108
- enum Action : Equatable { case tapped, responseA, responseB }
109
- let reducer = Reduce < State , Action > { state, action in
110
- switch action {
111
- case . tapped:
112
- return . run { send in
113
- Task . cancel ( id: CancelID . self)
114
- try Task . checkCancellation ( )
115
- await send ( . responseA)
116
- } catch: { @Sendable _, send in // NB: Explicit '@Sendable' required in 5.5.2
117
- await send ( . responseB)
118
- }
119
- . cancellable ( id: CancelID . self)
120
- case . responseA, . responseB:
121
- return . none
83
+ func testRunCancellation( ) async {
84
+ enum CancelID { }
85
+ struct State : Equatable { }
86
+ enum Action : Equatable { case tapped, response }
87
+ let reducer = Reduce < State , Action > { state, action in
88
+ switch action {
89
+ case . tapped:
90
+ return . run { send in
91
+ Task . cancel ( id: CancelID . self)
92
+ try Task . checkCancellation ( )
93
+ await send ( . response)
122
94
}
95
+ . cancellable ( id: CancelID . self)
96
+ case . response:
97
+ return . none
98
+ }
99
+ }
100
+ let store = TestStore ( initialState: State ( ) , reducer: reducer)
101
+ await store. send ( . tapped) . finish ( )
102
+ }
103
+
104
+ func testRunCancellationCatch( ) async {
105
+ enum CancelID { }
106
+ struct State : Equatable { }
107
+ enum Action : Equatable { case tapped, responseA, responseB }
108
+ let reducer = Reduce < State , Action > { state, action in
109
+ switch action {
110
+ case . tapped:
111
+ return . run { send in
112
+ Task . cancel ( id: CancelID . self)
113
+ try Task . checkCancellation ( )
114
+ await send ( . responseA)
115
+ } catch: { @Sendable _, send in // NB: Explicit '@Sendable' required in 5.5.2
116
+ await send ( . responseB)
117
+ }
118
+ . cancellable ( id: CancelID . self)
119
+ case . responseA, . responseB:
120
+ return . none
123
121
}
124
- let store = TestStore ( initialState: State ( ) , reducer: reducer)
125
- await store. send ( . tapped) . finish ( )
126
122
}
123
+ let store = TestStore ( initialState: State ( ) , reducer: reducer)
124
+ await store. send ( . tapped) . finish ( )
127
125
}
126
+ }
128
127
#endif
0 commit comments