Skip to content

Commit

Permalink
Fix EnvironmentValuesTest on iOS 18
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Sep 17, 2024
1 parent f2f7b5f commit 6e9aa37
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,10 @@ jobs:
xcode-version: ${{ matrix.xcode-version }}
- name: Swift version
run: swift --version
- name: Build in release mode
run: |
xcodebuild build \
-scheme OpenSwiftUI \
-configuration Debug \
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
-skipMacroValidation \
-skipPackagePluginValidation
- name: Build and run tests in debug mode
run: |
xcodebuild test \
-scheme OpenSwiftUI \
-scheme OpenSwiftUITests \
-configuration Debug \
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
-skipMacroValidation \
Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var sharedSwiftSettings: [SwiftSetting] = [
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
.swiftLanguageMode(.v5),
.enableUpcomingFeature("BareSlashRegexLiterals"),
]

if releaseVersion >= 2021 {
Expand Down
1 change: 1 addition & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var sharedSwiftSettings: [SwiftSetting] = [
.enableExperimentalFeature("AccessLevelOnImport"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
.enableUpcomingFeature("BareSlashRegexLiterals"),
]

if releaseVersion >= 2021 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,52 @@ struct EnvironmentValuesTest {
return
}
#endif
func compareDictDescription(result: String, initial: String, expectNew: String) {
#if canImport(Darwin)
guard #available(iOS 16.0, macOS 13.0, *) else {
#expect(result == expectNew)
return
}
guard initial != "[]" else {
#expect(result == expectNew)
return
}
guard let expectNewContent = expectNew.wholeMatch(of: /\[(.*)\]/)?.output.1 else {
Issue.record("Non empty string and does not contain [] in expectNew")
return
}
if expectNewContent.isEmpty {
#expect(result == initial)
} else {
let expectResult = "[\(expectNewContent), " + initial.dropFirst()
#expect(result == expectResult)
}
#else
#expect(result == expectNew)
#endif
}

var env = EnvironmentValues()
#expect(env.description == "[]")

let initialDescription = env.description
if #unavailable(iOS 18, macOS 15) {
#expect(env.description == "[]")
}

var bool = env[BoolKey.self]
#expect(bool == BoolKey.defaultValue)
#expect(env.description == "[]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[]")

env[BoolKey.self] = bool
#expect(env.description == "[\(BoolKey.name) = \(bool)]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool)]")

env[BoolKey.self] = !bool
bool = env[BoolKey.self]
#expect(bool == !BoolKey.defaultValue)
#expect(env.description == "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")

let value = 1
env[IntKey.self] = value
#expect(env.description == "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
}
}

0 comments on commit 6e9aa37

Please sign in to comment.