Skip to content

Commit 1d5d709

Browse files
authored
Finish FoundationInternationalization swift-testing migration (#1402)
1 parent 3ead71f commit 1d5d709

File tree

4 files changed

+861
-824
lines changed

4 files changed

+861
-824
lines changed

Tests/FoundationEssentialsTests/ProcessInfoTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ private struct ProcessInfoTests {
159159

160160
@Test func processName() {
161161
#if FOUNDATION_FRAMEWORK
162-
let targetName = "TestHost"
162+
let targetNames = ["TestHost"]
163163
#elseif os(Linux) || os(Windows) || os(Android) || os(FreeBSD)
164-
let targetName = "swift-foundationPackageTests.xctest"
164+
let targetNames = ["swift-foundationPackageTests.xctest"]
165165
#else
166-
let targetName = "swiftpm-testing-helper"
166+
let targetNames = ["swiftpm-testing-helper", "xctest"]
167167
#endif
168168
let processInfo = ProcessInfo.processInfo
169169
let originalProcessName = processInfo.processName
170-
#expect(originalProcessName == targetName)
170+
#expect(targetNames.contains(originalProcessName))
171171

172172
// Try assigning a new process name.
173173
let newProcessName = "TestProcessName"

Tests/FoundationInternationalizationTests/Formatting/ListFormatStyleTests.swift

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
66
//
77
//===----------------------------------------------------------------------===//
8-
//
9-
// RUN: %target-run-simple-swift
10-
// REQUIRES: executable_test
11-
// REQUIRES: objc_interop
128

13-
#if canImport(TestSupport)
14-
import TestSupport
15-
#endif
9+
import Testing
1610

1711
#if canImport(FoundationInternationalization)
1812
@testable import FoundationEssentials
@@ -23,68 +17,69 @@ import TestSupport
2317
@testable import Foundation
2418
#endif
2519

26-
class ListFormatStyleTests : XCTestCase {
27-
func test_orList() {
20+
@Suite("ListFormatStyle")
21+
private struct ListFormatStyleTests {
22+
@Test func orList() {
2823
var style: ListFormatStyle<StringStyle, [String]> = .list(type: .or, width: .standard)
2924
style.locale = Locale(identifier: "en_US")
3025

31-
XCTAssertEqual(["one", "two"].formatted(style), "one or two")
32-
XCTAssertEqual(["one", "two", "three"].formatted(style), "one, two, or three")
26+
#expect(["one", "two"].formatted(style) == "one or two")
27+
#expect(["one", "two", "three"].formatted(style) == "one, two, or three")
3328
}
3429

35-
func test_andList() {
30+
@Test func andList() {
3631
var style: ListFormatStyle<StringStyle, [String]> = .list(type: .and, width: .standard)
3732
style.locale = Locale(identifier: "en_US")
3833

39-
XCTAssertEqual(["one", "two"].formatted(style), "one and two")
40-
XCTAssertEqual(["one", "two", "three"].formatted(style), "one, two, and three")
34+
#expect(["one", "two"].formatted(style) == "one and two")
35+
#expect(["one", "two", "three"].formatted(style) == "one, two, and three")
4136
}
4237

43-
func test_narrowList() {
38+
@Test func narrowList() {
4439
var style: ListFormatStyle<StringStyle, [String]> = .list(type: .and, width: .narrow)
4540
style.locale = Locale(identifier: "en_US")
4641

47-
XCTAssertEqual(["one", "two"].formatted(style), "one, two")
48-
XCTAssertEqual(["one", "two", "three"].formatted(style), "one, two, three")
42+
#expect(["one", "two"].formatted(style) == "one, two")
43+
#expect(["one", "two", "three"].formatted(style) == "one, two, three")
4944
}
5045

51-
func test_shortList() {
46+
@Test func shortList() {
5247
var style: ListFormatStyle<StringStyle, [String]> = .list(type: .and, width: .short)
5348
style.locale = Locale(identifier: "en_US")
5449

55-
XCTAssertEqual(["one", "two"].formatted(style), "one & two")
56-
XCTAssertEqual(["one", "two", "three"].formatted(style), "one, two, & three")
50+
#expect(["one", "two"].formatted(style) == "one & two")
51+
#expect(["one", "two", "three"].formatted(style) == "one, two, & three")
5752
}
5853

59-
#if FOUNDATION_FRAMEWORK // FIXME: rdar://104091257
60-
func test_leadingDotSyntax() {
54+
@Test func leadingDotSyntax() {
6155
let _ = ["one", "two"].formatted(.list(type: .and))
6256
let _ = ["one", "two"].formatted()
6357
let _ = [1, 2].formatted(.list(memberStyle: .number, type: .or, width: .standard))
6458
}
65-
#endif
6659

67-
func testAutoupdatingCurrentChangesFormatResults() {
68-
let locale = Locale.autoupdatingCurrent
69-
let list = ["one", "two", "three", "four"]
70-
71-
// Get a formatted result from es-ES
72-
var prefs = LocalePreferences()
73-
prefs.languages = ["es-ES"]
74-
prefs.locale = "es_ES"
75-
LocaleCache.cache.resetCurrent(to: prefs)
76-
let formattedSpanish = list.formatted(.list(type: .and).locale(locale))
77-
78-
// Get a formatted result from en-US
79-
prefs.languages = ["en-US"]
80-
prefs.locale = "en_US"
81-
LocaleCache.cache.resetCurrent(to: prefs)
82-
let formattedEnglish = list.formatted(.list(type: .and).locale(locale))
83-
84-
// Reset to current preferences before any possibility of failing this test
85-
LocaleCache.cache.reset()
86-
87-
// No matter what 'current' was before this test was run, formattedSpanish and formattedEnglish should be different.
88-
XCTAssertNotEqual(formattedSpanish, formattedEnglish)
60+
@Test func autoupdatingCurrentChangesFormatResults() async {
61+
await usingCurrentInternationalizationPreferences {
62+
let locale = Locale.autoupdatingCurrent
63+
let list = ["one", "two", "three", "four"]
64+
65+
// Get a formatted result from es-ES
66+
var prefs = LocalePreferences()
67+
prefs.languages = ["es-ES"]
68+
prefs.locale = "es_ES"
69+
LocaleCache.cache.resetCurrent(to: prefs)
70+
let formattedSpanish = list.formatted(.list(type: .and).locale(locale))
71+
72+
// Get a formatted result from en-US
73+
prefs.languages = ["en-US"]
74+
prefs.locale = "en_US"
75+
LocaleCache.cache.resetCurrent(to: prefs)
76+
let formattedEnglish = list.formatted(.list(type: .and).locale(locale))
77+
78+
// Reset to current preferences before any possibility of failing this test
79+
LocaleCache.cache.reset()
80+
81+
// No matter what 'current' was before this test was run, formattedSpanish and formattedEnglish should be different.
82+
#expect(formattedSpanish != formattedEnglish)
83+
}
8984
}
9085
}

0 commit comments

Comments
 (0)