Skip to content

Commit af2eae7

Browse files
authored
Update TestApp (#218)
* Update TestApp * Update Test and add TestIntents * Update Benchmark * Add TestHost * Update PerformanceTest
1 parent 04d021a commit af2eae7

File tree

19 files changed

+450
-81
lines changed

19 files changed

+450
-81
lines changed

Sources/OpenSwiftUI/App/LegacyApp.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
//
22
// LegacyApp.swift
3-
// OpenSwiftUI
3+
// OpenSwiftUICore
44
//
5-
// Audited for iOS 15.5
5+
// Audited for iOS 18.0
66
// Status: Complete
7-
// ID: F8F4CFB3FB453F4ECC15C05B76BCD1E4
7+
// ID: F8F4CFB3FB453F4ECC15C05B76BCD1E4 (SwiftUI)
88

99
public enum __App {}
1010

11+
@available(*, unavailable)
12+
extension __App: Sendable {}
13+
1114
extension __App {
1215
public static func run(_ rootView: some View) -> Never {
1316
runApp(ShoeboxAdaptor(rootView: rootView))

Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIGraphicsView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class _UIGraphicsView: UIView {
1919
}
2020

2121
override func _shouldAnimateProperty(withKey key: String) -> Bool {
22-
if layer.hasBeenCommitted() {
22+
if layer.hasBeenCommitted {
2323
super._shouldAnimateProperty(withKey: key)
2424
} else {
2525
false

Sources/OpenSwiftUI/Test/_PerformanceTest.swift renamed to Sources/OpenSwiftUI/Test/PerformanceTest.swift

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
//
2-
// _PerformanceTest.swift
2+
// PerformanceTest.swift
33
// OpenSwiftUI
44
//
5-
// Audited for iOS 15.5
5+
// Audited for iOS 18.0
66
// Status: WIP
77

88
#if os(iOS)
99
import UIKit
1010
#elseif os(macOS)
1111
import AppKit
1212
#endif
13-
1413
import OpenSwiftUI_SPI
1514

1615
public protocol _PerformanceTest: _Test {
1716
var name: String { get }
18-
func runTest(host: _BenchmarkHost, options: [AnyHashable: Any])
17+
func runTest(host: any _BenchmarkHost, options: [AnyHashable: Any])
1918
}
2019

2120
extension __App {
@@ -24,12 +23,6 @@ extension __App {
2423
}
2524
}
2625

27-
extension _TestApp {
28-
public func runPerformanceTests(_ tests: [_PerformanceTest]) -> Never {
29-
preconditionFailure("TODO")
30-
}
31-
}
32-
3326
extension _BenchmarkHost {
3427
public func _started(test: _PerformanceTest) {
3528
#if os(iOS)

Sources/OpenSwiftUI/Test/TestApp.swift

+23-30
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,40 @@
22
// TestApp.swift
33
// OpenSwiftUI
44
//
5-
// Audited for iOS 15.5
5+
// Audited for iOS 18.0
66
// Status: WIP
7-
// ID: A519B5B95CA8FF4E3445832668F0B2D2
87

9-
@_spi(Testing)
10-
import OpenSwiftUICore
8+
public import OpenSwiftUICore
9+
import Foundation
1110

12-
public struct _TestApp {
13-
public init() {
14-
preconditionFailure("TODO")
15-
}
11+
extension _TestApp {
1612
public func run() -> Never {
13+
let semanticsIndex = CommandLine.arguments.lastIndex(of: "--semantics")
14+
if let semanticsIndex,
15+
semanticsIndex + 1 != CommandLine.arguments.count {
16+
setSemantics(CommandLine.arguments[semanticsIndex + 1])
17+
} else {
18+
setSemantics("lastest")
19+
}
20+
#if canImport(Darwin)
21+
CFPreferencesSetAppValue("AppleLanguages" as NSString, ["en"] as NSArray, kCFPreferencesCurrentApplication)
22+
// CTClearFontFallbacksCache()
23+
#endif
24+
Color.Resolved.legacyInterpolation = true
25+
let rootView = RootView()
1726
preconditionFailure("TODO")
1827
}
1928
}
2029

2130
extension _TestApp {
22-
struct RootView: View {
23-
@State
24-
var state: StateType
25-
26-
init() {
27-
preconditionFailure("TODO")
28-
}
29-
30-
var body: some View {
31-
state.testView
32-
preconditionFailure("TODO")
33-
}
31+
public func runBenchmarks(_ benchmarks: [_Benchmark]) -> Never {
32+
let _ = RootView()
33+
preconditionFailure("TODO")
3434
}
35-
3635
}
3736

38-
extension _TestApp.RootView {
39-
struct StateType {
40-
var id: Int
41-
var testView: AnyView
42-
43-
mutating func setTestView<V: View>(_ view: V) {
44-
id += 1
45-
testView = AnyView(view.testID(id))
46-
}
37+
extension _TestApp {
38+
public func runPerformanceTests(_ tests: [_PerformanceTest]) -> Never {
39+
preconditionFailure("TODO")
4740
}
4841
}

Sources/OpenSwiftUI/Test/_Benchmark.swift

-10
This file was deleted.

Sources/OpenSwiftUI/Test/_Test.swift

-9
This file was deleted.

Sources/OpenSwiftUICore/Semantic/Semantics.swift

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ package enum SemanticRequirement {
4747

4848
extension Semantics {
4949
package static var forced: Forced = Forced()
50+
5051
package func test<R>(as keyPath: WritableKeyPath<Forced, Semantics?> = \.sdk, _ body: () throws -> R) rethrows -> R {
5152
let value = Semantics.forced[keyPath: keyPath]
5253
Semantics.forced[keyPath: keyPath] = self
@@ -57,7 +58,9 @@ extension Semantics {
5758
extension Semantics {
5859
package struct Forced {
5960
package var sdk: Semantics?
61+
6062
package var deploymentTarget: Semantics?
63+
6164
package init() {
6265
if dyld_program_sdk_at_least(dyld_build_version_t(semantics: firstRelease)) {
6366
sdk = nil

Sources/OpenSwiftUI/Test/_BenchmarkHost.swift renamed to Sources/OpenSwiftUICore/Test/Benchmark.swift

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
//
2-
// _BenchmarkHost.swift
3-
// OpenSwiftUI
2+
// Benchmark.swift
3+
// OpenSwiftUICore
44
//
5-
// Audited for iOS 15.5
6-
// Status: Complete
7-
// ID: 3E629D505F0A70F29ACFC010AA42C6E0
5+
// Audited for iOS 18.0
6+
// Status: WIP
7+
// ID: 3E629D505F0A70F29ACFC010AA42C6E0 (SwiftUI)
8+
// ID: 5BCCF82F8606CD0B3127FDEEA7C13601 (SwiftUICore)
89

910
public import Foundation
10-
1111
#if canImport(QuartzCore)
1212
import QuartzCore
1313
#endif
1414

15-
private let enableProfiler = EnvironmentHelper.bool(for: "OPENSWIFTUI_PROFILE_BENCHMARKS")
16-
1715
public protocol _BenchmarkHost: AnyObject {
1816
func _renderForTest(interval: Double)
1917
func _renderAsyncForTest(interval: Double) -> Bool
2018
func _performScrollTest(startOffset: CGFloat, iterations: Int, delta: CGFloat, length: CGFloat, completion: (() -> Void)?)
2119
}
2220

21+
public protocol _Benchmark: _Test {
22+
func measure(host: _BenchmarkHost) -> [Double]
23+
}
24+
25+
package var enableProfiler = EnvironmentHelper.bool(for: "OPENSWIFTUI_PROFILE_BENCHMARKS")
26+
27+
package var enableTracer = EnvironmentHelper.bool(for: "OPENSWIFTUI_TRACE_BENCHMARKS")
28+
2329
extension _BenchmarkHost {
2430
public func _renderAsyncForTest(interval _: Double) -> Bool {
2531
false
2632
}
27-
33+
2834
public func _performScrollTest(startOffset _: CGFloat, iterations _: Int, delta _: CGFloat, length _: CGFloat, completion _: (() -> Void)?) {}
2935

3036
public func measureAction(action: () -> Void) -> Double {
37+
// WIP: trace support
3138
#if canImport(QuartzCore)
3239
let begin = CACurrentMediaTime()
3340
if enableProfiler,
@@ -45,17 +52,17 @@ extension _BenchmarkHost {
4552
preconditionFailure("Unsupported Platfrom")
4653
#endif
4754
}
48-
55+
4956
public func measureRender(interval: Double = 1.0 / 60.0) -> Double {
5057
measureAction {
5158
_renderForTest(interval: interval)
5259
}
5360
}
54-
61+
5562
public func measureRenders(seconds: Double) -> [Double] {
5663
measureRenders(duration: seconds)
5764
}
58-
65+
5966
public func measureRenders(duration: Double) -> [Double] {
6067
let minutes = duration / 60.0
6168
let value = Int(minutes.rounded(.towardZero)) + 1
@@ -67,3 +74,15 @@ extension _BenchmarkHost {
6774
return results
6875
}
6976
}
77+
78+
package func summarize(_ measurements: [(any _Benchmark, [Double])]) -> String {
79+
preconditionFailure("TODO")
80+
}
81+
82+
package func write(_ measurements: [(any _Benchmark, [Double])], to path: String) throws {
83+
preconditionFailure("TODO")
84+
}
85+
86+
package func log(_ measurements: [(any _Benchmark, [Double])]) {
87+
preconditionFailure("TODO")
88+
}

0 commit comments

Comments
 (0)