Skip to content

Commit c1a7160

Browse files
committed
Workarounds added for unrelated bugs on Linux
1 parent 44ae75b commit c1a7160

File tree

1 file changed

+52
-22
lines changed

1 file changed

+52
-22
lines changed

TestFoundation/TestCodable.swift

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,21 @@ class TestCodable : XCTestCase {
306306
}
307307

308308
// MARK: - TimeZone
309-
lazy var timeZoneValues: [TimeZone] = [
310-
TimeZone(identifier: "America/Los_Angeles")!,
311-
TimeZone(identifier: "UTC")!,
312-
TimeZone.current
313-
]
309+
lazy var timeZoneValues: [TimeZone] = {
310+
var values = [
311+
TimeZone(identifier: "America/Los_Angeles")!,
312+
TimeZone(identifier: "UTC")!,
313+
]
314+
315+
#if !os(Linux)
316+
// Disabled due to [SR-5598] bug, which occurs on Linux, and breaks
317+
// TimeZone.current == TimeZone(identifier: TimeZone.current.identifier) equality,
318+
// causing encode -> decode -> compare test to fail.
319+
values.append(TimeZone.current)
320+
#endif
321+
322+
return values
323+
}()
314324

315325
func test_TimeZone_JSON() {
316326
for timeZone in timeZoneValues {
@@ -319,22 +329,34 @@ class TestCodable : XCTestCase {
319329
}
320330

321331
// MARK: - Calendar
322-
lazy var calendarValues: [Calendar] = [
323-
Calendar(identifier: .gregorian),
324-
Calendar(identifier: .buddhist),
325-
Calendar(identifier: .chinese),
326-
Calendar(identifier: .coptic),
327-
Calendar(identifier: .ethiopicAmeteMihret),
328-
Calendar(identifier: .ethiopicAmeteAlem),
329-
Calendar(identifier: .hebrew),
330-
Calendar(identifier: .iso8601),
331-
Calendar(identifier: .indian),
332-
Calendar(identifier: .islamic),
333-
Calendar(identifier: .islamicCivil),
334-
Calendar(identifier: .japanese),
335-
Calendar(identifier: .persian),
336-
Calendar(identifier: .republicOfChina),
337-
]
332+
lazy var calendarValues: [Calendar] = {
333+
var values = [
334+
Calendar(identifier: .gregorian),
335+
Calendar(identifier: .buddhist),
336+
Calendar(identifier: .chinese),
337+
Calendar(identifier: .coptic),
338+
Calendar(identifier: .ethiopicAmeteMihret),
339+
Calendar(identifier: .ethiopicAmeteAlem),
340+
Calendar(identifier: .hebrew),
341+
Calendar(identifier: .iso8601),
342+
Calendar(identifier: .indian),
343+
Calendar(identifier: .islamic),
344+
Calendar(identifier: .islamicCivil),
345+
Calendar(identifier: .japanese),
346+
Calendar(identifier: .persian),
347+
Calendar(identifier: .republicOfChina),
348+
]
349+
350+
#if os(Linux)
351+
// Custom timeZone set to work around [SR-5598] bug, which occurs on Linux, and breaks equality after
352+
// serializing and deserializing TimeZone.current
353+
for index in values.indices {
354+
values[index].timeZone = TimeZone(identifier: "UTC")!
355+
}
356+
#endif
357+
358+
return values
359+
}()
338360

339361
func test_Calendar_JSON() {
340362
for calendar in calendarValues {
@@ -365,7 +387,15 @@ class TestCodable : XCTestCase {
365387
]
366388

367389
func test_DateComponents_JSON() {
368-
let calendar = Calendar(identifier: .gregorian)
390+
#if os(Linux)
391+
var calendar = Calendar(identifier: .gregorian)
392+
// Custom timeZone set to work around [SR-5598] bug, which occurs on Linux, and breaks equality after
393+
// serializing and deserializing TimeZone.current
394+
calendar.timeZone = TimeZone(identifier: "UTC")!
395+
#else
396+
let calendar = Calendar(identifier: .gregorian)
397+
#endif
398+
369399
let components = calendar.dateComponents(dateComponents, from: Date(timeIntervalSince1970: 1501283776))
370400
expectRoundTripEqualityThroughJSON(for: components)
371401
}

0 commit comments

Comments
 (0)