From dfbc9d115c89c5d0ca1b5f20e9af26faa5efd094 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 28 Apr 2024 01:38:00 +0800 Subject: [PATCH] Add Unit Test case for _logChanges --- .github/workflows/compatibility_tests.yml | 44 +++++++++++++++++- .github/workflows/wasm.yml | 2 +- README.md | 7 +-- .../View/Debug/ChangedBodyPropertyTests.swift | 46 ++++++++++++++++--- 4 files changed, 88 insertions(+), 11 deletions(-) diff --git a/.github/workflows/compatibility_tests.yml b/.github/workflows/compatibility_tests.yml index 191d27b7..bc2d5eac 100644 --- a/.github/workflows/compatibility_tests.yml +++ b/.github/workflows/compatibility_tests.yml @@ -8,7 +8,7 @@ on: jobs: compatibility_tests_macos: - name: Execute compatibility tests + name: Execute compatibility tests for macOS strategy: fail-fast: false matrix: @@ -41,3 +41,45 @@ jobs: --build-path .build-compatibility-test-debug env: OPENSWIFTUI_COMPATIBILITY_TEST: 1 + compatibility_tests_ios: + name: Execute compatibility tests for iOS + strategy: + fail-fast: false + matrix: + include: + - os: macos-14 + xcode-version: "15.3" # Swift 5.10 + runs-on: ${{ matrix.os }} + env: + OPENSWIFTUI_WERROR: 1 + OPENSWIFTUI_SWIFT_TESTING: 1 + OPENGRAPH_ATTRIBUTEGRAPH: 1 + OPENSWIFTUI_SWIFT_LOG: 0 + steps: + - uses: actions/checkout@v4 + - name: Setup Xcode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: ${{ matrix.xcode-version }} + - name: Swift version + run: swift --version + - name: Run compatibility tests on OpenSwiftUI + iOS + run: | + xcodebuild test \ + -scheme OpenSwiftUI \ + -configuration Debug \ + -destination "platform=iOS-Simulator" \ + -skipMacroValidation \ + -skipPackagePluginValidation + env: + OPENSWIFTUI_COMPATIBILITY_TEST: 0 + - name: Run compatibility tests on SwiftUI + iOS + run: | + xcodebuild test \ + -scheme OpenSwiftUI \ + -configuration Debug \ + -destination "platform=iOS-Simulator" \ + -skipMacroValidation \ + -skipPackagePluginValidation + env: + OPENSWIFTUI_COMPATIBILITY_TEST: 1 \ No newline at end of file diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index efc61dbf..1aaeb799 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -7,7 +7,7 @@ on: branches: [main] jobs: - wasmer_test: + wasm_test: name: Execute tests on WASM strategy: fail-fast: false diff --git a/README.md b/README.md index 97888228..a2732fc2 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,12 @@ for various platforms: | **Platform** | **CI Status** | **Support Status** | Build | Test | Deploy | |-|:-|-|-|-|-| -| **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] | ✅ | ✅ | ✅ | +| **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) | | | | | +| **macOS** | [![macOS](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/macos.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/macos.yml) | ⭐️⭐️⭐️ *[^1] | ✅ | ✅ | ✅ | | **iOS** | [![iOS](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ios.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ios.yml) | ⭐️⭐️⭐️⭐️ *[^2] | ✅ | ✅ | ✅ | | **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] | ✅ | ✅ | ❌ | -| **Wasm** | [![Ubuntu](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/ubuntu.yml) | ⭐️ *[^4] | ✅ | ❌ | ❌ | -| **Windows** | | Not supported yet | ❌ | ❌ | ❌ | +| **Wasm** | [![Ubuntu](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/wasm.yml/badge.svg)](https://github.com/OpenSwiftUIProject/OpenSwiftUI/actions/workflows/wasm.yml) | ⭐️ *[^4] | ✅ | ❌ | ❌ | +| **Windows** | None | Not supported yet | ❌ | ❌ | ❌ | [^1]: AppKit and other UI framework backend is not intergrated yet. diff --git a/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift b/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift index b478ed78..8ab4152b 100644 --- a/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/View/Debug/ChangedBodyPropertyTests.swift @@ -2,7 +2,9 @@ // ChangedBodyPropertyTests.swift // OpenSwiftUICompatibilityTests +#if canImport(Darwin) && !OPENSWIFTUI_SWIFT_LOG import Testing +import OSLog #if os(iOS) import UIKit @@ -10,12 +12,32 @@ import UIKit @MainActor struct ChangedBodyPropertyTests { - @available(iOS 15, *) + @available(iOS 15, macOS 12, *) + private func verifyLog(expected: String) throws { + let store = try OSLogStore(scope: .currentProcessIdentifier) + let position = store.position(timeIntervalSinceLatestBoot: 0) + let entries = try store + .getEntries(at: position) // getEntries's with and at param is not respected on iOS, so I have to use last then. + .compactMap { $0 as? OSLogEntryLog } + #if OPENSWIFTUI_COMPATIBILITY_TEST + .filter { $0.subsystem == "com.apple.SwiftUI" && $0.category == "Changed Body Properties" } + #else + .filter { $0.subsystem == "org.OpenSwiftUIProject.OpenSwiftUI" && $0.category == "Changed Body Properties" } + #endif + .map { $0.composedMessage } + #expect(entries.last == expected) + } + + #if OPENSWIFTUI_COMPATIBILITY_TEST + @available(iOS 17.1, macOS 14.1, *) + #else + @available(iOS 15, macOS 12, *) + #endif @Test func zeroPropertyView() throws { struct ContentView: View { var body: some View { - let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self changed. + let _ = Self._logChanges() AnyView(EmptyView()) } } @@ -23,16 +45,21 @@ struct ChangedBodyPropertyTests { let vc = UIHostingController(rootView: ContentView()) vc.triggerLayout() workaroundIssue87(vc) + try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.") #endif } - @available(iOS 15, *) + #if OPENSWIFTUI_COMPATIBILITY_TEST + @available(iOS 17.1, macOS 14.1, *) + #else + @available(iOS 15, macOS 12, *) + #endif @Test func propertyView() throws { struct ContentView: View { var name = "" var body: some View { - let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self changed. + let _ = Self._logChanges() AnyView(EmptyView()) } } @@ -40,16 +67,21 @@ struct ChangedBodyPropertyTests { let vc = UIHostingController(rootView: ContentView()) vc.triggerLayout() workaroundIssue87(vc) + try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.") #endif } - @available(iOS 15, *) + #if OPENSWIFTUI_COMPATIBILITY_TEST + @available(iOS 17.1, macOS 14.1, *) + #else + @available(iOS 15, macOS 12, *) + #endif @Test func statePropertyView() throws { struct ContentView: View { @State var name = "" var body: some View { - let _ = Self._printChanges() // ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed. + let _ = Self._logChanges() AnyView(EmptyView()) } } @@ -57,6 +89,8 @@ struct ChangedBodyPropertyTests { let vc = UIHostingController(rootView: ContentView()) vc.triggerLayout() workaroundIssue87(vc) + try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed.") #endif } } +#endif