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