Skip to content

Commit d3ba96f

Browse files
authored
Remove workaroundIssue87 (#431)
1 parent 34ad3b0 commit d3ba96f

File tree

7 files changed

+60
-59
lines changed

7 files changed

+60
-59
lines changed

Sources/OpenSwiftUITestsSupport/Integration/PlatformHostingControllerHelper.swift

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import UIKit
99
import AppKit
1010
#endif
1111

12-
extension PlatformHostingController {
12+
extension PlatformViewController {
1313
package func triggerLayout() {
1414
#if os(iOS)
1515
let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
@@ -29,18 +29,4 @@ extension PlatformHostingController {
2929
#endif
3030
}
3131
}
32-
33-
// FIXME: A workaround to bypass the Issue #87
34-
package func workaroundIssue87(_ vc: PlatformViewController) {
35-
// #if OPENSWIFTUI
36-
// TODO: Use swift-test exist test feature to detect the crash instead or sliently workaroun it
37-
CrashWorkaround.shared.objects.append(vc)
38-
// #endif
39-
}
40-
41-
private final class CrashWorkaround {
42-
private init() {}
43-
static let shared = CrashWorkaround()
44-
var objects: [Any?] = []
45-
}
4632
#endif

Tests/OpenSwiftUICompatibilityTests/Data/State/StateTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ struct StateTests {
2424
}
2525
}
2626
}
27+
var vc: PlatformViewController!
2728
await confirmation { @MainActor confirmation in
28-
let vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation))
29+
vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation))
2930
vc.triggerLayout()
30-
workaroundIssue87(vc)
3131
}
32+
withExtendedLifetime(vc) {}
3233
}
3334
}
3435
#endif

Tests/OpenSwiftUICompatibilityTests/Integration/PlatformHostingControllerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct PlatformHostingControllerTests {
2323
}
2424
let vc = PlatformHostingController(rootView: ContentView())
2525
vc.triggerLayout()
26-
workaroundIssue87(vc)
26+
withExtendedLifetime(vc) {}
2727
}
2828

2929
@Test(
@@ -42,7 +42,7 @@ struct PlatformHostingControllerTests {
4242
}
4343
let vc = PlatformHostingController(rootView: ContentView())
4444
vc.triggerLayout()
45-
workaroundIssue87(vc)
45+
withExtendedLifetime(vc) {}
4646
}
4747
}
4848
#endif

Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/AppearanceActionModifierCompatibilityTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ struct AppearanceActionModifierCompatibilityTests {
2222
}
2323
}
2424
}
25+
var vc: PlatformViewController!
2526
await confirmation { @MainActor confirmation in
26-
let vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation))
27+
vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation))
2728
vc.triggerLayout()
28-
workaroundIssue87(vc)
2929
}
30+
withExtendedLifetime(vc) {}
3031
}
3132

3233
@Test
@@ -55,14 +56,13 @@ struct AppearanceActionModifierCompatibilityTests {
5556
}
5657
let vc = PlatformHostingController(rootView: ContentView())
5758
vc.triggerLayout()
58-
workaroundIssue87(vc)
5959
#expect(Helper.result.hasPrefix("A"))
6060
var timeout = 5
6161
while !Helper.result.hasPrefix("AAD"), timeout > 0 {
6262
try await Task.sleep(for: .seconds(1))
6363
timeout -= 1
6464
}
65-
#expect(Helper.result.hasPrefix("AAD"))
65+
withExtendedLifetime(vc) {}
6666
}
6767
}
6868
#endif

Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/ValueActionModifierCompatibilityTests.swift

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,21 @@ struct ValueActionModifierCompatibilityTests {
4040
}
4141
}
4242

43+
var vc: PlatformViewController!
4344
await confirmation(expectedCount: 2) { @MainActor confirmation in
4445
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
45-
let vc = PlatformHostingController(
46+
vc = PlatformHostingController(
4647
rootView: ContentView(
4748
confirmation: confirmation,
4849
continuation: continuation
4950
)
5051
)
5152
vc.triggerLayout()
52-
workaroundIssue87(vc)
5353
}
5454
}
55-
#expect(Helper.results == [1, 2])
55+
withExtendedLifetime(vc) {
56+
#expect(Helper.results == [1, 2])
57+
}
5658
}
5759

5860
// MARK: - onChange with two parameters (oldValue, newValue)
@@ -88,20 +90,22 @@ struct ValueActionModifierCompatibilityTests {
8890
}
8991
}
9092

93+
var vc: PlatformViewController!
9194
await confirmation(expectedCount: 2) { @MainActor confirmation in
9295
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
93-
let vc = PlatformHostingController(
96+
vc = PlatformHostingController(
9497
rootView: ContentView(
9598
confirmation: confirmation,
9699
continuation: continuation
97100
)
98101
)
99102
vc.triggerLayout()
100-
workaroundIssue87(vc)
101103
}
102104
}
103-
#expect(Helper.oldValues == [0, 1])
104-
#expect(Helper.newValues == [1, 2])
105+
withExtendedLifetime(vc) {
106+
#expect(Helper.oldValues == [0, 1])
107+
#expect(Helper.newValues == [1, 2])
108+
}
105109
}
106110

107111
// MARK: - onChange with zero parameters
@@ -128,18 +132,19 @@ struct ValueActionModifierCompatibilityTests {
128132
}
129133
}
130134

135+
var vc: PlatformViewController!
131136
await confirmation(expectedCount: 2) { @MainActor confirmation in
132137
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
133-
let vc = PlatformHostingController(
138+
vc = PlatformHostingController(
134139
rootView: ContentView(
135140
confirmation: confirmation,
136141
continuation: continuation
137142
)
138143
)
139144
vc.triggerLayout()
140-
workaroundIssue87(vc)
141145
}
142146
}
147+
withExtendedLifetime(vc) {}
143148
}
144149

145150
// MARK: - onChange with initial parameter
@@ -175,20 +180,22 @@ struct ValueActionModifierCompatibilityTests {
175180
}
176181
}
177182

183+
var vc: PlatformViewController!
178184
await confirmation(expectedCount: 3) { @MainActor confirmation in
179185
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
180-
let vc = PlatformHostingController(
186+
vc = PlatformHostingController(
181187
rootView: ContentView(
182188
confirmation: confirmation,
183189
continuation: continuation
184190
)
185191
)
186192
vc.triggerLayout()
187-
workaroundIssue87(vc)
188193
}
189194
}
190-
#expect(Helper.oldValues == [0, 0, 1])
191-
#expect(Helper.newValues == [0, 1, 2])
195+
withExtendedLifetime(vc) {
196+
#expect(Helper.oldValues == [0, 0, 1])
197+
#expect(Helper.newValues == [0, 1, 2])
198+
}
192199
}
193200

194201
@Test
@@ -205,10 +212,10 @@ struct ValueActionModifierCompatibilityTests {
205212
}
206213
}
207214

215+
var vc: PlatformViewController!
208216
await confirmation { @MainActor confirmation in
209-
let vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation))
217+
vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation))
210218
vc.triggerLayout()
211-
workaroundIssue87(vc)
212219
}
213220
}
214221

@@ -247,20 +254,22 @@ struct ValueActionModifierCompatibilityTests {
247254
}
248255
}
249256
}
257+
var vc: PlatformViewController!
250258
await confirmation(expectedCount: 2) { @MainActor confirmation in
251259
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
252-
let vc = PlatformHostingController(
260+
vc = PlatformHostingController(
253261
rootView: ContentView(
254262
confirmation: confirmation,
255263
continuation: continuation
256264
)
257265
)
258266
vc.triggerLayout()
259-
workaroundIssue87(vc)
260267
}
261268
}
262-
#expect(Helper.lastOldValue == 1)
263-
#expect(Helper.lastNewValue == 2)
269+
withExtendedLifetime(vc) {
270+
#expect(Helper.lastOldValue == 1)
271+
#expect(Helper.lastNewValue == 2)
272+
}
264273
}
265274

266275
// MARK: - String value changes
@@ -292,20 +301,21 @@ struct ValueActionModifierCompatibilityTests {
292301
}
293302
}
294303
}
304+
var vc: PlatformViewController!
295305
await confirmation(expectedCount: 2) { @MainActor confirmation in
296306
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
297-
let vc = PlatformHostingController(
307+
vc = PlatformHostingController(
298308
rootView: ContentView(
299309
confirmation: confirmation,
300310
continuation: continuation
301311
)
302312
)
303313
vc.triggerLayout()
304-
workaroundIssue87(vc)
305314
}
306315
}
307-
308-
#expect(Helper.lastValue == "final")
316+
withExtendedLifetime(vc) {
317+
#expect(Helper.lastValue == "final")
318+
}
309319
}
310320

311321
// MARK: - Boolean value changes
@@ -340,20 +350,21 @@ struct ValueActionModifierCompatibilityTests {
340350
}
341351
}
342352
}
353+
var vc: PlatformViewController!
343354
await confirmation(expectedCount: 3) { @MainActor confirmation in
344355
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
345-
let vc = PlatformHostingController(
356+
vc = PlatformHostingController(
346357
rootView: ContentView(
347358
confirmation: confirmation,
348359
continuation: continuation
349360
)
350361
)
351362
vc.triggerLayout()
352-
workaroundIssue87(vc)
353363
}
354364
}
355-
356-
#expect(Helper.toggleCount == 3)
365+
withExtendedLifetime(vc) {
366+
#expect(Helper.toggleCount == 3)
367+
}
357368
}
358369
}
359370
#endif

Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct ChangedBodyPropertyTests {
3838
}
3939
let vc = PlatformHostingController(rootView: ContentView())
4040
vc.triggerLayout()
41-
workaroundIssue87(vc)
4241
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.")
42+
withExtendedLifetime(vc) {}
4343
}
4444

4545
#if !OPENSWIFTUI
@@ -56,8 +56,8 @@ struct ChangedBodyPropertyTests {
5656
}
5757
let vc = PlatformHostingController(rootView: ContentView())
5858
vc.triggerLayout()
59-
workaroundIssue87(vc)
6059
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.")
60+
withExtendedLifetime(vc) {}
6161
}
6262

6363
#if !OPENSWIFTUI
@@ -74,8 +74,8 @@ struct ChangedBodyPropertyTests {
7474
}
7575
let vc = PlatformHostingController(rootView: ContentView())
7676
vc.triggerLayout()
77-
workaroundIssue87(vc)
7877
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed.")
78+
withExtendedLifetime(vc) {}
7979
}
8080
}
8181
#endif

Tests/OpenSwiftUICompatibilityTests/View/EquatableViewTests.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,19 @@ struct EquatableViewTests {
102102
#elseif os(macOS)
103103
let expectedCount = 1 ... 3 // FIXME: Not expected, local 3 while CI 1 or 2 :(
104104
#endif
105+
var vc: PlatformViewController!
105106
await confirmation(expectedCount: expectedCount) { @MainActor confirmation in
106107
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
107-
let vc = PlatformHostingController(
108+
vc = PlatformHostingController(
108109
rootView: NonEquatableNumberViewWrapper(
109110
confirmation: confirmation,
110111
continuation: continuation
111112
)
112113
)
113114
vc.triggerLayout()
114-
workaroundIssue87(vc)
115115
}
116116
}
117+
withExtendedLifetime(vc) {}
117118
}
118119

119120
@Test
@@ -123,18 +124,19 @@ struct EquatableViewTests {
123124
#elseif os(macOS)
124125
let expectedCount = 1 ... 3 // FIXME: Not expected, local 2 while CI 1 or 2 :(
125126
#endif
127+
var vc: PlatformViewController!
126128
await confirmation(expectedCount: expectedCount) { @MainActor confirmation in
127129
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
128-
let vc = PlatformHostingController(
130+
vc = PlatformHostingController(
129131
rootView: EquatableNumberViewWrapper(
130132
confirmation: confirmation,
131133
continuation: continuation
132134
)
133135
)
134136
vc.triggerLayout()
135-
workaroundIssue87(vc)
136137
}
137138
}
139+
withExtendedLifetime(vc) {}
138140
}
139141

140142
#if OPENSWIFTUI
@@ -169,18 +171,19 @@ struct EquatableViewTests {
169171

170172
@Test
171173
func equatableProxy() async throws {
174+
var vc: PlatformViewController!
172175
await confirmation(expectedCount: 1) { @MainActor confirmation in
173176
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
174-
let vc = PlatformHostingController(
177+
vc = PlatformHostingController(
175178
rootView: EquatableProxyNumberViewWrapper(
176179
confirmation: confirmation,
177180
continuation: continuation
178181
)
179182
)
180183
vc.triggerLayout()
181-
workaroundIssue87(vc)
182184
}
183185
}
186+
withExtendedLifetime(vc) {}
184187
}
185188
#endif
186189
}

0 commit comments

Comments
 (0)