Skip to content

Commit dfbc9d1

Browse files
committed
Add Unit Test case for _logChanges
1 parent 9e43b85 commit dfbc9d1

File tree

4 files changed

+88
-11
lines changed

4 files changed

+88
-11
lines changed

.github/workflows/compatibility_tests.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
compatibility_tests_macos:
11-
name: Execute compatibility tests
11+
name: Execute compatibility tests for macOS
1212
strategy:
1313
fail-fast: false
1414
matrix:
@@ -41,3 +41,45 @@ jobs:
4141
--build-path .build-compatibility-test-debug
4242
env:
4343
OPENSWIFTUI_COMPATIBILITY_TEST: 1
44+
compatibility_tests_ios:
45+
name: Execute compatibility tests for iOS
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
include:
50+
- os: macos-14
51+
xcode-version: "15.3" # Swift 5.10
52+
runs-on: ${{ matrix.os }}
53+
env:
54+
OPENSWIFTUI_WERROR: 1
55+
OPENSWIFTUI_SWIFT_TESTING: 1
56+
OPENGRAPH_ATTRIBUTEGRAPH: 1
57+
OPENSWIFTUI_SWIFT_LOG: 0
58+
steps:
59+
- uses: actions/checkout@v4
60+
- name: Setup Xcode
61+
uses: maxim-lobanov/setup-xcode@v1
62+
with:
63+
xcode-version: ${{ matrix.xcode-version }}
64+
- name: Swift version
65+
run: swift --version
66+
- name: Run compatibility tests on OpenSwiftUI + iOS
67+
run: |
68+
xcodebuild test \
69+
-scheme OpenSwiftUI \
70+
-configuration Debug \
71+
-destination "platform=iOS-Simulator" \
72+
-skipMacroValidation \
73+
-skipPackagePluginValidation
74+
env:
75+
OPENSWIFTUI_COMPATIBILITY_TEST: 0
76+
- name: Run compatibility tests on SwiftUI + iOS
77+
run: |
78+
xcodebuild test \
79+
-scheme OpenSwiftUI \
80+
-configuration Debug \
81+
-destination "platform=iOS-Simulator" \
82+
-skipMacroValidation \
83+
-skipPackagePluginValidation
84+
env:
85+
OPENSWIFTUI_COMPATIBILITY_TEST: 1

.github/workflows/wasm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [main]
88

99
jobs:
10-
wasmer_test:
10+
wasm_test:
1111
name: Execute tests on WASM
1212
strategy:
1313
fail-fast: false

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ for various platforms:
5151

5252
| **Platform** | **CI Status** | **Support Status** | Build | Test | Deploy |
5353
|-|:-|-|-|-|-|
54-
| **macOS** | [![macOS](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/macos.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/macos.yml) [![Compatibility tests](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/compatibility_tests.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/compatibility_tests.yml) | ⭐️⭐️⭐️ *[^1] ||||
54+
| **SwiftUI Compatibility** | [![Compatibility tests](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/compatibility_tests.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/compatibility_tests.yml) | | | | |
55+
| **macOS** | [![macOS](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/macos.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/macos.yml) | ⭐️⭐️⭐️ *[^1] ||||
5556
| **iOS** | [![iOS](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ios.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ios.yml) | ⭐️⭐️⭐️⭐️ *[^2] ||||
5657
| **Ubuntu 22.04** | [![Ubuntu](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ubuntu.yml) | ⭐️⭐️ *[^3] ||||
57-
| **Wasm** | [![Ubuntu](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ubuntu.yml) | ⭐️ *[^4] ||||
58-
| **Windows** | | Not supported yet ||||
58+
| **Wasm** | [![Ubuntu](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/wasm.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/wasm.yml) | ⭐️ *[^4] ||||
59+
| **Windows** | None | Not supported yet ||||
5960

6061

6162
[^1]: AppKit and other UI framework backend is not intergrated yet.

Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,95 @@
22
// ChangedBodyPropertyTests.swift
33
// OpenSwiftUICompatibilityTests
44

5+
#if canImport(Darwin) && !OPENSWIFTUI_SWIFT_LOG
56
import Testing
7+
import OSLog
68

79
#if os(iOS)
810
import UIKit
911
#endif
1012

1113
@MainActor
1214
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
1436
@Test
1537
func zeroPropertyView() throws {
1638
struct ContentView: View {
1739
var body: some View {
18-
let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self changed.
40+
let _ = Self._logChanges()
1941
AnyView(EmptyView())
2042
}
2143
}
2244
#if os(iOS)
2345
let vc = UIHostingController(rootView: ContentView())
2446
vc.triggerLayout()
2547
workaroundIssue87(vc)
48+
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.")
2649
#endif
2750
}
2851

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
3057
@Test
3158
func propertyView() throws {
3259
struct ContentView: View {
3360
var name = ""
3461
var body: some View {
35-
let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self changed.
62+
let _ = Self._logChanges()
3663
AnyView(EmptyView())
3764
}
3865
}
3966
#if os(iOS)
4067
let vc = UIHostingController(rootView: ContentView())
4168
vc.triggerLayout()
4269
workaroundIssue87(vc)
70+
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.")
4371
#endif
4472
}
4573

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
4779
@Test
4880
func statePropertyView() throws {
4981
struct ContentView: View {
5082
@State var name = ""
5183
var body: some View {
52-
let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed.
84+
let _ = Self._logChanges()
5385
AnyView(EmptyView())
5486
}
5587
}
5688
#if os(iOS)
5789
let vc = UIHostingController(rootView: ContentView())
5890
vc.triggerLayout()
5991
workaroundIssue87(vc)
92+
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed.")
6093
#endif
6194
}
6295
}
96+
#endif

0 commit comments

Comments
 (0)