diff --git a/Sources/OpenSwiftUITestsSupport/Integration/PlatformHostingControllerHelper.swift b/Sources/OpenSwiftUITestsSupport/Integration/PlatformHostingControllerHelper.swift index ed9450b9d..4836e404c 100644 --- a/Sources/OpenSwiftUITestsSupport/Integration/PlatformHostingControllerHelper.swift +++ b/Sources/OpenSwiftUITestsSupport/Integration/PlatformHostingControllerHelper.swift @@ -9,7 +9,7 @@ import UIKit import AppKit #endif -extension PlatformHostingController { +extension PlatformViewController { package func triggerLayout() { #if os(iOS) let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) @@ -29,18 +29,4 @@ extension PlatformHostingController { #endif } } - -// FIXME: A workaround to bypass the Issue #87 -package func workaroundIssue87(_ vc: PlatformViewController) { -// #if OPENSWIFTUI - // TODO: Use swift-test exist test feature to detect the crash instead or sliently workaroun it - CrashWorkaround.shared.objects.append(vc) -// #endif -} - -private final class CrashWorkaround { - private init() {} - static let shared = CrashWorkaround() - var objects: [Any?] = [] -} #endif diff --git a/Tests/OpenSwiftUICompatibilityTests/Data/State/StateTests.swift b/Tests/OpenSwiftUICompatibilityTests/Data/State/StateTests.swift index 7313726bd..df43fa059 100644 --- a/Tests/OpenSwiftUICompatibilityTests/Data/State/StateTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/Data/State/StateTests.swift @@ -24,11 +24,12 @@ struct StateTests { } } } + var vc: PlatformViewController! await confirmation { @MainActor confirmation in - let vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation)) + vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation)) vc.triggerLayout() - workaroundIssue87(vc) } + withExtendedLifetime(vc) {} } } #endif diff --git a/Tests/OpenSwiftUICompatibilityTests/Integration/PlatformHostingControllerTests.swift b/Tests/OpenSwiftUICompatibilityTests/Integration/PlatformHostingControllerTests.swift index 0901b37df..3fbde0c60 100644 --- a/Tests/OpenSwiftUICompatibilityTests/Integration/PlatformHostingControllerTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/Integration/PlatformHostingControllerTests.swift @@ -23,7 +23,7 @@ struct PlatformHostingControllerTests { } let vc = PlatformHostingController(rootView: ContentView()) vc.triggerLayout() - workaroundIssue87(vc) + withExtendedLifetime(vc) {} } @Test( @@ -42,7 +42,7 @@ struct PlatformHostingControllerTests { } let vc = PlatformHostingController(rootView: ContentView()) vc.triggerLayout() - workaroundIssue87(vc) + withExtendedLifetime(vc) {} } } #endif diff --git a/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/AppearanceActionModifierCompatibilityTests.swift b/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/AppearanceActionModifierCompatibilityTests.swift index c8cab9ae5..ee0d3f235 100644 --- a/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/AppearanceActionModifierCompatibilityTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/AppearanceActionModifierCompatibilityTests.swift @@ -22,11 +22,12 @@ struct AppearanceActionModifierCompatibilityTests { } } } + var vc: PlatformViewController! await confirmation { @MainActor confirmation in - let vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation)) + vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation)) vc.triggerLayout() - workaroundIssue87(vc) } + withExtendedLifetime(vc) {} } @Test @@ -55,14 +56,13 @@ struct AppearanceActionModifierCompatibilityTests { } let vc = PlatformHostingController(rootView: ContentView()) vc.triggerLayout() - workaroundIssue87(vc) #expect(Helper.result.hasPrefix("A")) var timeout = 5 while !Helper.result.hasPrefix("AAD"), timeout > 0 { try await Task.sleep(for: .seconds(1)) timeout -= 1 } - #expect(Helper.result.hasPrefix("AAD")) + withExtendedLifetime(vc) {} } } #endif diff --git a/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/ValueActionModifierCompatibilityTests.swift b/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/ValueActionModifierCompatibilityTests.swift index 9be209bfb..2eb55ef92 100644 --- a/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/ValueActionModifierCompatibilityTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/Modifier/ViewModifier/ValueActionModifierCompatibilityTests.swift @@ -40,19 +40,21 @@ struct ValueActionModifierCompatibilityTests { } } + var vc: PlatformViewController! await confirmation(expectedCount: 2) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: ContentView( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } - #expect(Helper.results == [1, 2]) + withExtendedLifetime(vc) { + #expect(Helper.results == [1, 2]) + } } // MARK: - onChange with two parameters (oldValue, newValue) @@ -88,20 +90,22 @@ struct ValueActionModifierCompatibilityTests { } } + var vc: PlatformViewController! await confirmation(expectedCount: 2) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: ContentView( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } - #expect(Helper.oldValues == [0, 1]) - #expect(Helper.newValues == [1, 2]) + withExtendedLifetime(vc) { + #expect(Helper.oldValues == [0, 1]) + #expect(Helper.newValues == [1, 2]) + } } // MARK: - onChange with zero parameters @@ -128,18 +132,19 @@ struct ValueActionModifierCompatibilityTests { } } + var vc: PlatformViewController! await confirmation(expectedCount: 2) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: ContentView( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } + withExtendedLifetime(vc) {} } // MARK: - onChange with initial parameter @@ -175,20 +180,22 @@ struct ValueActionModifierCompatibilityTests { } } + var vc: PlatformViewController! await confirmation(expectedCount: 3) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: ContentView( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } - #expect(Helper.oldValues == [0, 0, 1]) - #expect(Helper.newValues == [0, 1, 2]) + withExtendedLifetime(vc) { + #expect(Helper.oldValues == [0, 0, 1]) + #expect(Helper.newValues == [0, 1, 2]) + } } @Test @@ -205,10 +212,10 @@ struct ValueActionModifierCompatibilityTests { } } + var vc: PlatformViewController! await confirmation { @MainActor confirmation in - let vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation)) + vc = PlatformHostingController(rootView: ContentView(confirmation: confirmation)) vc.triggerLayout() - workaroundIssue87(vc) } } @@ -247,20 +254,22 @@ struct ValueActionModifierCompatibilityTests { } } } + var vc: PlatformViewController! await confirmation(expectedCount: 2) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: ContentView( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } - #expect(Helper.lastOldValue == 1) - #expect(Helper.lastNewValue == 2) + withExtendedLifetime(vc) { + #expect(Helper.lastOldValue == 1) + #expect(Helper.lastNewValue == 2) + } } // MARK: - String value changes @@ -292,20 +301,21 @@ struct ValueActionModifierCompatibilityTests { } } } + var vc: PlatformViewController! await confirmation(expectedCount: 2) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: ContentView( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } - - #expect(Helper.lastValue == "final") + withExtendedLifetime(vc) { + #expect(Helper.lastValue == "final") + } } // MARK: - Boolean value changes @@ -340,20 +350,21 @@ struct ValueActionModifierCompatibilityTests { } } } + var vc: PlatformViewController! await confirmation(expectedCount: 3) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: ContentView( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } - - #expect(Helper.toggleCount == 3) + withExtendedLifetime(vc) { + #expect(Helper.toggleCount == 3) + } } } #endif diff --git a/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift b/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift index 8047f6685..6c3a33e59 100644 --- a/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift @@ -38,8 +38,8 @@ struct ChangedBodyPropertyTests { } let vc = PlatformHostingController(rootView: ContentView()) vc.triggerLayout() - workaroundIssue87(vc) try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.") + withExtendedLifetime(vc) {} } #if !OPENSWIFTUI @@ -56,8 +56,8 @@ struct ChangedBodyPropertyTests { } let vc = PlatformHostingController(rootView: ContentView()) vc.triggerLayout() - workaroundIssue87(vc) try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.") + withExtendedLifetime(vc) {} } #if !OPENSWIFTUI @@ -74,8 +74,8 @@ struct ChangedBodyPropertyTests { } let vc = PlatformHostingController(rootView: ContentView()) vc.triggerLayout() - workaroundIssue87(vc) try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed.") + withExtendedLifetime(vc) {} } } #endif diff --git a/Tests/OpenSwiftUICompatibilityTests/View/EquatableViewTests.swift b/Tests/OpenSwiftUICompatibilityTests/View/EquatableViewTests.swift index 1016664de..ddb3f7a8a 100644 --- a/Tests/OpenSwiftUICompatibilityTests/View/EquatableViewTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/View/EquatableViewTests.swift @@ -102,18 +102,19 @@ struct EquatableViewTests { #elseif os(macOS) let expectedCount = 1 ... 3 // FIXME: Not expected, local 3 while CI 1 or 2 :( #endif + var vc: PlatformViewController! await confirmation(expectedCount: expectedCount) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: NonEquatableNumberViewWrapper( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } + withExtendedLifetime(vc) {} } @Test @@ -123,18 +124,19 @@ struct EquatableViewTests { #elseif os(macOS) let expectedCount = 1 ... 3 // FIXME: Not expected, local 2 while CI 1 or 2 :( #endif + var vc: PlatformViewController! await confirmation(expectedCount: expectedCount) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: EquatableNumberViewWrapper( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } + withExtendedLifetime(vc) {} } #if OPENSWIFTUI @@ -169,18 +171,19 @@ struct EquatableViewTests { @Test func equatableProxy() async throws { + var vc: PlatformViewController! await confirmation(expectedCount: 1) { @MainActor confirmation in await withUnsafeContinuation { (continuation: UnsafeContinuation) in - let vc = PlatformHostingController( + vc = PlatformHostingController( rootView: EquatableProxyNumberViewWrapper( confirmation: confirmation, continuation: continuation ) ) vc.triggerLayout() - workaroundIssue87(vc) } } + withExtendedLifetime(vc) {} } #endif }