Skip to content

Commit eefacbc

Browse files
authored
Fix or disable tests around accessing current locale (#1424)
* test individualFields() 155519959 * Disable various failing tests I believe these tests are failing because some other tests are mutating the global cached current locale or calendar. We've identified most tests whose test expectations depend on the current locale. We've addressed them by either specifying a fixed locale on the tests, or guard them inside `usingCurrentInternationalizationPreferences`. But even if a test doesn't assert the result based on the value of the current locale, the test might still cause the cache to be populated concurrently at the time of accessing autoupdating and current locale, and subsequently break tests that expect a given value of the current locale. Disable the tests for now while investigating a proper way to update the tests. These tests pass when building as part of the Darwin SDK, so leave them enabled there. 155476600
1 parent 4b0ee0a commit eefacbc

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Tests/FoundationInternationalizationTests/Formatting/DateFormatStyleTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private struct DateFormatStyleTests {
294294
#expect(date.formatted(style.locale(Locale.localeAsIfCurrent(name: esES, overrides: .init(force24Hour: true)))) == "16:00:00")
295295
}
296296

297-
#if !os(watchOS) // 99504292
297+
#if !os(watchOS) && FOUNDATION_FRAMEWORK // 99504292 && 155484008
298298
@Test func nsICUDateFormatterCache() async throws {
299299
await usingCurrentInternationalizationPreferences {
300300
// This test can only be run with the system set to the en_US language
@@ -408,7 +408,8 @@ private struct DateFormatStyleTests {
408408
var locale: Locale
409409
var format: Date.FormatStyle
410410
func verifyWithFormat(_ date: Date, expected: String, sourceLocation: SourceLocation = #_sourceLocation) {
411-
let fmt = format.locale(locale)
411+
var fmt = format.locale(locale)
412+
fmt.calendar = Calendar(identifier: .gregorian)
412413
let formatted = fmt.format(date)
413414
#expect(formatted == expected, sourceLocation: sourceLocation)
414415
}
@@ -638,7 +639,7 @@ private struct DateAttributedFormatStyleTests {
638639
}
639640

640641
@Test func individualFields() throws {
641-
let baseStyle = Date.FormatStyle(locale: enUSLocale, timeZone: gmtTimeZone)
642+
let baseStyle = Date.FormatStyle(locale: enUSLocale, calendar: Calendar(identifier: .gregorian), timeZone: gmtTimeZone)
642643
// dateFormatter.date(from: "2021-04-12 15:04:32")!
643644
let date = Date(timeIntervalSinceReferenceDate: 639932672.0)
644645
let expectations: [Date.FormatStyle : [Segment]] = [
@@ -1411,6 +1412,7 @@ private struct TestDateStyleDiscreteConformance {
14111412

14121413
let now = date("2023-05-15 08:47:20Z")
14131414

1415+
#if FOUNDATION_FRAMEWORK // 155526268
14141416
assertEvaluation(
14151417
of: .init(date: .complete, time: .complete).secondFraction(.fractional(2)),
14161418
in: (now - 0.1)...(now + 0.1),
@@ -1438,6 +1440,7 @@ private struct TestDateStyleDiscreteConformance {
14381440
"Monday, May 15, 2023 at 8:47:20.10 AM GMT",
14391441
])
14401442

1443+
14411444
assertEvaluation(
14421445
of: .init(date: .complete, time: .complete),
14431446
in: (now - 3)...(now + 3),
@@ -1450,6 +1453,7 @@ private struct TestDateStyleDiscreteConformance {
14501453
"Monday, May 15, 2023 at 8:47:22 AM GMT",
14511454
"Monday, May 15, 2023 at 8:47:23 AM GMT",
14521455
])
1456+
#endif
14531457

14541458
assertEvaluation(
14551459
of: .init().hour(.twoDigits(amPM: .abbreviated)).minute(),

Tests/FoundationInternationalizationTests/Formatting/NumberFormatStyleTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ private struct FormatStylePatternMatchingTests {
18221822
typealias TestCase = (string: String, style: IntegerFormatStyle<Int>, value: Int?)
18231823

18241824
@Test func integerFormatStyle_Consumer() {
1825-
let style: IntegerFormatStyle<Int> = .init()
1825+
let style: IntegerFormatStyle<Int> = .init(locale: Locale(identifier: "en_US"))
18261826
let string = "42,000,000"
18271827

18281828
_verifyMatching(string, formatStyle: style, expectedUpperBound: string.endIndex, expectedValue: 42000000)
@@ -1862,7 +1862,7 @@ private struct FormatStylePatternMatchingTests {
18621862
}
18631863

18641864
@Test func percentFormatStyle_Consumer() {
1865-
let style = IntegerFormatStyle<Int>.Percent()
1865+
let style = IntegerFormatStyle<Int>.Percent(locale: Locale(identifier: "en_US"))
18661866
let string = "42%"
18671867

18681868
_verifyMatching(string, formatStyle: style, expectedUpperBound: string.endIndex, expectedValue: 42)

0 commit comments

Comments
 (0)