|
2 | 2 | // ChangedBodyPropertyTests.swift
|
3 | 3 | // OpenSwiftUICompatibilityTests
|
4 | 4 |
|
| 5 | +#if canImport(Darwin) && !OPENSWIFTUI_SWIFT_LOG |
5 | 6 | import Testing
|
| 7 | +import OSLog |
6 | 8 |
|
7 | 9 | #if os(iOS)
|
8 | 10 | import UIKit
|
9 | 11 | #endif
|
10 | 12 |
|
11 | 13 | @MainActor
|
12 | 14 | struct ChangedBodyPropertyTests {
|
13 |
| - @available(iOS 15, *) |
| 15 | + @available(iOS 15, macOS 12, *) |
| 16 | + private func verifyLog(expected: String) throws { |
| 17 | + let store = try OSLogStore(scope: .currentProcessIdentifier) |
| 18 | + let position = store.position(timeIntervalSinceLatestBoot: 0) |
| 19 | + let entries = try store |
| 20 | + .getEntries(at: position) // getEntries's with and at param is not respected on iOS, so I have to use last then. |
| 21 | + .compactMap { $0 as? OSLogEntryLog } |
| 22 | + #if OPENSWIFTUI_COMPATIBILITY_TEST |
| 23 | + .filter { $0.subsystem == "com.apple.SwiftUI" && $0.category == "Changed Body Properties" } |
| 24 | + #else |
| 25 | + .filter { $0.subsystem == "org.OpenSwiftUIProject.OpenSwiftUI" && $0.category == "Changed Body Properties" } |
| 26 | + #endif |
| 27 | + .map { $0.composedMessage } |
| 28 | + #expect(entries.last == expected) |
| 29 | + } |
| 30 | + |
| 31 | + #if OPENSWIFTUI_COMPATIBILITY_TEST |
| 32 | + @available(iOS 17.1, macOS 14.1, *) |
| 33 | + #else |
| 34 | + @available(iOS 15, macOS 12, *) |
| 35 | + #endif |
14 | 36 | @Test
|
15 | 37 | func zeroPropertyView() throws {
|
16 | 38 | struct ContentView: View {
|
17 | 39 | var body: some View {
|
18 |
| - let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self changed. |
| 40 | + let _ = Self._logChanges() |
19 | 41 | AnyView(EmptyView())
|
20 | 42 | }
|
21 | 43 | }
|
22 | 44 | #if os(iOS)
|
23 | 45 | let vc = UIHostingController(rootView: ContentView())
|
24 | 46 | vc.triggerLayout()
|
25 | 47 | workaroundIssue87(vc)
|
| 48 | + try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.") |
26 | 49 | #endif
|
27 | 50 | }
|
28 | 51 |
|
29 |
| - @available(iOS 15, *) |
| 52 | + #if OPENSWIFTUI_COMPATIBILITY_TEST |
| 53 | + @available(iOS 17.1, macOS 14.1, *) |
| 54 | + #else |
| 55 | + @available(iOS 15, macOS 12, *) |
| 56 | + #endif |
30 | 57 | @Test
|
31 | 58 | func propertyView() throws {
|
32 | 59 | struct ContentView: View {
|
33 | 60 | var name = ""
|
34 | 61 | var body: some View {
|
35 |
| - let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self changed. |
| 62 | + let _ = Self._logChanges() |
36 | 63 | AnyView(EmptyView())
|
37 | 64 | }
|
38 | 65 | }
|
39 | 66 | #if os(iOS)
|
40 | 67 | let vc = UIHostingController(rootView: ContentView())
|
41 | 68 | vc.triggerLayout()
|
42 | 69 | workaroundIssue87(vc)
|
| 70 | + try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.") |
43 | 71 | #endif
|
44 | 72 | }
|
45 | 73 |
|
46 |
| - @available(iOS 15, *) |
| 74 | + #if OPENSWIFTUI_COMPATIBILITY_TEST |
| 75 | + @available(iOS 17.1, macOS 14.1, *) |
| 76 | + #else |
| 77 | + @available(iOS 15, macOS 12, *) |
| 78 | + #endif |
47 | 79 | @Test
|
48 | 80 | func statePropertyView() throws {
|
49 | 81 | struct ContentView: View {
|
50 | 82 | @State var name = ""
|
51 | 83 | var body: some View {
|
52 |
| - let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed. |
| 84 | + let _ = Self._logChanges() |
53 | 85 | AnyView(EmptyView())
|
54 | 86 | }
|
55 | 87 | }
|
56 | 88 | #if os(iOS)
|
57 | 89 | let vc = UIHostingController(rootView: ContentView())
|
58 | 90 | vc.triggerLayout()
|
59 | 91 | workaroundIssue87(vc)
|
| 92 | + try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed.") |
60 | 93 | #endif
|
61 | 94 | }
|
62 | 95 | }
|
| 96 | +#endif |
0 commit comments