Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct PlatformHostingControllerTests {
}
let vc = PlatformHostingController(rootView: ContentView())
vc.triggerLayout()
workaroundIssue87(vc)
withExtendedLifetime(vc) {}
}

@Test(
Expand All @@ -42,7 +42,7 @@ struct PlatformHostingControllerTests {
}
let vc = PlatformHostingController(rootView: ContentView())
vc.triggerLayout()
workaroundIssue87(vc)
withExtendedLifetime(vc) {}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ struct ValueActionModifierCompatibilityTests {
}
}

var vc: PlatformViewController!
await confirmation(expectedCount: 2) { @MainActor confirmation in
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) 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)
Expand Down Expand Up @@ -88,20 +90,22 @@ struct ValueActionModifierCompatibilityTests {
}
}

var vc: PlatformViewController!
await confirmation(expectedCount: 2) { @MainActor confirmation in
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) 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
Expand All @@ -128,18 +132,19 @@ struct ValueActionModifierCompatibilityTests {
}
}

var vc: PlatformViewController!
await confirmation(expectedCount: 2) { @MainActor confirmation in
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) in
let vc = PlatformHostingController(
vc = PlatformHostingController(
rootView: ContentView(
confirmation: confirmation,
continuation: continuation
)
)
vc.triggerLayout()
workaroundIssue87(vc)
}
}
withExtendedLifetime(vc) {}
}

// MARK: - onChange with initial parameter
Expand Down Expand Up @@ -175,20 +180,22 @@ struct ValueActionModifierCompatibilityTests {
}
}

var vc: PlatformViewController!
await confirmation(expectedCount: 3) { @MainActor confirmation in
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) 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
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -247,20 +254,22 @@ struct ValueActionModifierCompatibilityTests {
}
}
}
var vc: PlatformViewController!
await confirmation(expectedCount: 2) { @MainActor confirmation in
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) 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
Expand Down Expand Up @@ -292,20 +301,21 @@ struct ValueActionModifierCompatibilityTests {
}
}
}
var vc: PlatformViewController!
await confirmation(expectedCount: 2) { @MainActor confirmation in
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) 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
Expand Down Expand Up @@ -340,20 +350,21 @@ struct ValueActionModifierCompatibilityTests {
}
}
}
var vc: PlatformViewController!
await confirmation(expectedCount: 3) { @MainActor confirmation in
await withUnsafeContinuation { (continuation: UnsafeContinuation<Void, Never>) 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void, Never>) in
let vc = PlatformHostingController(
vc = PlatformHostingController(
rootView: NonEquatableNumberViewWrapper(
confirmation: confirmation,
continuation: continuation
)
)
vc.triggerLayout()
workaroundIssue87(vc)
}
}
withExtendedLifetime(vc) {}
}

@Test
Expand All @@ -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<Void, Never>) in
let vc = PlatformHostingController(
vc = PlatformHostingController(
rootView: EquatableNumberViewWrapper(
confirmation: confirmation,
continuation: continuation
)
)
vc.triggerLayout()
workaroundIssue87(vc)
}
}
withExtendedLifetime(vc) {}
}

#if OPENSWIFTUI
Expand Down Expand Up @@ -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<Void, Never>) in
let vc = PlatformHostingController(
vc = PlatformHostingController(
rootView: EquatableProxyNumberViewWrapper(
confirmation: confirmation,
continuation: continuation
)
)
vc.triggerLayout()
workaroundIssue87(vc)
}
}
withExtendedLifetime(vc) {}
}
#endif
}
Expand Down
Loading