Skip to content

Commit 6e9aa37

Browse files
committed
Fix EnvironmentValuesTest on iOS 18
1 parent f2f7b5f commit 6e9aa37

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

.github/workflows/ios.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,10 @@ jobs:
3434
xcode-version: ${{ matrix.xcode-version }}
3535
- name: Swift version
3636
run: swift --version
37-
- name: Build in release mode
38-
run: |
39-
xcodebuild build \
40-
-scheme OpenSwiftUI \
41-
-configuration Debug \
42-
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
43-
-skipMacroValidation \
44-
-skipPackagePluginValidation
4537
- name: Build and run tests in debug mode
4638
run: |
4739
xcodebuild test \
48-
-scheme OpenSwiftUI \
40+
-scheme OpenSwiftUITests \
4941
-configuration Debug \
5042
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
5143
-skipMacroValidation \

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var sharedSwiftSettings: [SwiftSetting] = [
7272
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
7373
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
7474
.swiftLanguageMode(.v5),
75+
.enableUpcomingFeature("BareSlashRegexLiterals"),
7576
]
7677

7778
if releaseVersion >= 2021 {

[email protected]

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var sharedSwiftSettings: [SwiftSetting] = [
6868
.enableExperimentalFeature("AccessLevelOnImport"),
6969
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
7070
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
71+
.enableUpcomingFeature("BareSlashRegexLiterals"),
7172
]
7273

7374
if releaseVersion >= 2021 {

Tests/OpenSwiftUICompatibilityTests/Data/Environment/EnvironmentValuesTest.swift

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,52 @@ struct EnvironmentValuesTest {
4545
return
4646
}
4747
#endif
48+
func compareDictDescription(result: String, initial: String, expectNew: String) {
49+
#if canImport(Darwin)
50+
guard #available(iOS 16.0, macOS 13.0, *) else {
51+
#expect(result == expectNew)
52+
return
53+
}
54+
guard initial != "[]" else {
55+
#expect(result == expectNew)
56+
return
57+
}
58+
guard let expectNewContent = expectNew.wholeMatch(of: /\[(.*)\]/)?.output.1 else {
59+
Issue.record("Non empty string and does not contain [] in expectNew")
60+
return
61+
}
62+
if expectNewContent.isEmpty {
63+
#expect(result == initial)
64+
} else {
65+
let expectResult = "[\(expectNewContent), " + initial.dropFirst()
66+
#expect(result == expectResult)
67+
}
68+
#else
69+
#expect(result == expectNew)
70+
#endif
71+
}
72+
4873
var env = EnvironmentValues()
49-
#expect(env.description == "[]")
74+
75+
let initialDescription = env.description
76+
if #unavailable(iOS 18, macOS 15) {
77+
#expect(env.description == "[]")
78+
}
5079

5180
var bool = env[BoolKey.self]
5281
#expect(bool == BoolKey.defaultValue)
53-
#expect(env.description == "[]")
82+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[]")
5483

5584
env[BoolKey.self] = bool
56-
#expect(env.description == "[\(BoolKey.name) = \(bool)]")
85+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool)]")
5786

5887
env[BoolKey.self] = !bool
5988
bool = env[BoolKey.self]
6089
#expect(bool == !BoolKey.defaultValue)
61-
#expect(env.description == "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
90+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
6291

6392
let value = 1
6493
env[IntKey.self] = value
65-
#expect(env.description == "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
94+
compareDictDescription(result: env.description, initial: initialDescription, expectNew: "[\(IntKey.name) = \(value), \(BoolKey.name) = \(bool), \(BoolKey.name) = \(BoolKey.defaultValue)]")
6695
}
6796
}

0 commit comments

Comments
 (0)