From 6e9aa3745875904fd9bb6520e9e0a63a08c37ad6 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 17 Sep 2024 22:51:36 +0800 Subject: [PATCH] Fix EnvironmentValuesTest on iOS 18 --- .github/workflows/ios.yml | 10 +---- Package.swift | 1 + Package@swift-5.10.swift | 1 + .../Environment/EnvironmentValuesTest.swift | 39 ++++++++++++++++--- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 7f1e380d..fd2dfc7e 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -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 \ diff --git a/Package.swift b/Package.swift index 33bd9482..f58cae1d 100644 --- a/Package.swift +++ b/Package.swift @@ -72,6 +72,7 @@ var sharedSwiftSettings: [SwiftSetting] = [ .define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"), .define("OPENSWIFTUI_RELEASE_\(releaseVersion)"), .swiftLanguageMode(.v5), + .enableUpcomingFeature("BareSlashRegexLiterals"), ] if releaseVersion >= 2021 { diff --git a/Package@swift-5.10.swift b/Package@swift-5.10.swift index 5a180d89..69238931 100644 --- a/Package@swift-5.10.swift +++ b/Package@swift-5.10.swift @@ -68,6 +68,7 @@ var sharedSwiftSettings: [SwiftSetting] = [ .enableExperimentalFeature("AccessLevelOnImport"), .define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"), .define("OPENSWIFTUI_RELEASE_\(releaseVersion)"), + .enableUpcomingFeature("BareSlashRegexLiterals"), ] if releaseVersion >= 2021 { diff --git a/Tests/OpenSwiftUICompatibilityTests/Data/Environment/EnvironmentValuesTest.swift b/Tests/OpenSwiftUICompatibilityTests/Data/Environment/EnvironmentValuesTest.swift index aa530451..5a8fbea0 100644 --- a/Tests/OpenSwiftUICompatibilityTests/Data/Environment/EnvironmentValuesTest.swift +++ b/Tests/OpenSwiftUICompatibilityTests/Data/Environment/EnvironmentValuesTest.swift @@ -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)]") } }