Skip to content

Commit

Permalink
Add Unit Test case for _logChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Apr 27, 2024
1 parent 9e43b85 commit dfbc9d1
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/compatibility_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
compatibility_tests_macos:
name: Execute compatibility tests
name: Execute compatibility tests for macOS
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [main]

jobs:
wasmer_test:
wasm_test:
name: Execute tests on WASM
strategy:
fail-fast: false
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,95 @@
// ChangedBodyPropertyTests.swift
// OpenSwiftUICompatibilityTests

#if canImport(Darwin) && !OPENSWIFTUI_SWIFT_LOG
import Testing
import OSLog

#if os(iOS)
import UIKit
#endif

@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())
}
}
#if os(iOS)
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())
}
}
#if os(iOS)
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())
}
}
#if os(iOS)
let vc = UIHostingController(rootView: ContentView())
vc.triggerLayout()
workaroundIssue87(vc)
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self, @identity, _name changed.")
#endif
}
}
#endif

0 comments on commit dfbc9d1

Please sign in to comment.