Skip to content

Commit e596e1f

Browse files
authored
Merge pull request #19702 from jrose-apple/who-remembers-mavericks
[test] Tweak some tests so that they run consistently on OS X 10.9
2 parents c858372 + 21fe402 commit e596e1f

File tree

7 files changed

+67
-23
lines changed

7 files changed

+67
-23
lines changed

โ€Žtest/Interpreter/SDK/class_getImageName.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ testSuite.test("KVO/ObjC") {
115115
}
116116

117117
testSuite.test("dynamic") {
118-
let newClass: AnyClass = objc_allocateClassPair(/*superclass*/nil,
118+
let newClass: AnyClass = objc_allocateClassPair(/*superclass*/NSObject.self,
119119
"CompletelyDynamic",
120120
/*extraBytes*/0)!
121121
objc_registerClassPair(newClass)

โ€Žtest/Interpreter/SDK/objc_bridge_cast.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,16 @@ func testValueToObjectBridgingInSwitch() {
254254
}
255255
}
256256

257-
#if arch(i386) || arch(arm)
258-
#else
259-
// Small strings should be immortal
260-
autoreleasepool {
261-
let string = "hello"
262-
let nsString = string as NSString
263-
objc_setAssociatedObject(
264-
nsString, &ImmortalCanaryAssocObjectHandle, ImmortalCanary(),
265-
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
257+
#if !(arch(i386) || arch(arm))
258+
// Small strings should be immortal on new enough 64-bit Apple platforms.
259+
if #available(macOS 10.10, *) {
260+
autoreleasepool {
261+
let string = "hello"
262+
let nsString = string as NSString
263+
objc_setAssociatedObject(
264+
nsString, &ImmortalCanaryAssocObjectHandle, ImmortalCanary(),
265+
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
266+
}
266267
}
267268
#endif // 64-bit
268269
print("Done")

โ€Žtest/Interpreter/SDK/objc_swift_getObjectType.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ extension P {
3131
class O: NSObject, P { }
3232
var o = O()
3333
let obase: NSObject = o
34-
print(String(cString: object_getClassName(o)))
34+
print(NSStringFromClass(object_getClass(o)!))
3535
_ = (o as P).anyP
3636
_ = (obase as! P).anyP
37-
// CHECK: main.O
37+
// CHECK: {{^}}main.O{{$}}
3838

3939
// ... and KVO's artificial subclass thereof
4040
o.addObserver(NSObject(), forKeyPath: "xxx", options: [.new], context: nil)
41-
print(String(cString: object_getClassName(o)))
41+
print(NSStringFromClass(object_getClass(o)!))
4242
_ = (o as P).anyP
4343
_ = (obase as! P).anyP
4444
// CHECK-NEXT: NSKVONotifying_main.O
@@ -47,14 +47,14 @@ _ = (obase as! P).anyP
4747
extension NSLock: P { }
4848
var l = NSLock()
4949
let lbase: NSObject = l
50-
print(String(cString: object_getClassName(l)))
50+
print(NSStringFromClass(object_getClass(l)!))
5151
_ = (l as P).anyP
5252
_ = (lbase as! P).anyP
5353
// CHECK-NEXT: NSLock
5454

5555
// ... and KVO's artificial subclass thereof
5656
l.addObserver(NSObject(), forKeyPath: "xxx", options: [.new], context: nil)
57-
print(String(cString: object_getClassName(l)))
57+
print(NSStringFromClass(object_getClass(l)!))
5858
_ = (l as P).anyP
5959
_ = (lbase as! P).anyP
6060
// CHECK-NEXT: NSKVONotifying_NSLock

โ€Žtest/stdlib/CodableTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,30 @@ class TestCodable : TestCodableSuper {
442442
lazy var indexSetValues: [Int : IndexSet] = [
443443
#line : IndexSet(),
444444
#line : IndexSet(integer: 42),
445+
]
446+
lazy var indexSetMaxValues: [Int : IndexSet] = [
445447
#line : IndexSet(integersIn: 0 ..< Int.max)
446448
]
447449

448450
func test_IndexSet_JSON() {
449451
for (testLine, indexSet) in indexSetValues {
450452
expectRoundTripEqualityThroughJSON(for: indexSet, lineNumber: testLine)
451453
}
454+
if #available(macOS 10.10, iOS 8, *) {
455+
// Mac OS X 10.9 and iOS 7 weren't able to round-trip Int.max in JSON.
456+
for (testLine, indexSet) in indexSetMaxValues {
457+
expectRoundTripEqualityThroughJSON(for: indexSet, lineNumber: testLine)
458+
}
459+
}
452460
}
453461

454462
func test_IndexSet_Plist() {
455463
for (testLine, indexSet) in indexSetValues {
456464
expectRoundTripEqualityThroughPlist(for: indexSet, lineNumber: testLine)
457465
}
466+
for (testLine, indexSet) in indexSetMaxValues {
467+
expectRoundTripEqualityThroughPlist(for: indexSet, lineNumber: testLine)
468+
}
458469
}
459470

460471
// MARK: - Locale
@@ -506,6 +517,9 @@ class TestCodable : TestCodableSuper {
506517
// MARK: - NSRange
507518
lazy var nsrangeValues: [Int : NSRange] = [
508519
#line : NSRange(),
520+
#line : NSRange(location: 5, length: 20),
521+
]
522+
lazy var nsrangeMaxValues: [Int : NSRange] = [
509523
#line : NSRange(location: 0, length: Int.max),
510524
#line : NSRange(location: NSNotFound, length: 0),
511525
]
@@ -514,12 +528,21 @@ class TestCodable : TestCodableSuper {
514528
for (testLine, range) in nsrangeValues {
515529
expectRoundTripEqualityThroughJSON(for: range, lineNumber: testLine)
516530
}
531+
if #available(macOS 10.10, iOS 8, *) {
532+
// Mac OS X 10.9 and iOS 7 weren't able to round-trip Int.max in JSON.
533+
for (testLine, range) in nsrangeMaxValues {
534+
expectRoundTripEqualityThroughJSON(for: range, lineNumber: testLine)
535+
}
536+
}
517537
}
518538

519539
func test_NSRange_Plist() {
520540
for (testLine, range) in nsrangeValues {
521541
expectRoundTripEqualityThroughPlist(for: range, lineNumber: testLine)
522542
}
543+
for (testLine, range) in nsrangeMaxValues {
544+
expectRoundTripEqualityThroughPlist(for: range, lineNumber: testLine)
545+
}
523546
}
524547

525548
// MARK: - PersonNameComponents

โ€Žtest/stdlib/NSSlowString.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ tests.test("Iterator") {
5757
expectEqualSequence(opaque.utf8.reversed(), native.utf8.reversed())
5858
}
5959

60-
tests.test("Unicode 9 grapheme breaking") {
60+
tests.test("Unicode 9 grapheme breaking")
61+
.xfail(.osxMinor(10, 9, reason: "Mac OS X 10.9 has an old version of ICU"))
62+
.xfail(.iOSMajor(7, reason: "iOS 7 has an old version of ICU"))
63+
.code {
6164

6265
// Test string lengths that correspond to smaller than our fixed size code
6366
// unit buffer, larger than it, and exactly it.
@@ -69,7 +72,11 @@ tests.test("Unicode 9 grapheme breaking") {
6972
check(strJustRight as String, expectedCount: 5, expectedCodeUnitCount: 16)
7073
}
7174

72-
tests.test("Zalgo") {
75+
tests.test("Zalgo")
76+
.xfail(.osxMinor(10, 9, reason: "Mac OS X 10.9 has an old version of ICU"))
77+
.xfail(.iOSMajor(7, reason: "iOS 7 has an old version of ICU"))
78+
.code {
79+
7380
// Check that we handle absurdly long graphemes
7481
var zalgo = "a๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆc"
7582
for combo in 0x300...0x36f {

โ€Žtest/stdlib/TestCalendar.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ class TestCalendar : TestCalendarSuper {
182182

183183
expectEqual(Date(timeIntervalSince1970: 1468652400.0), c.startOfDay(for: d))
184184

185-
expectEqual(.orderedSame, c.compare(d, to: d + 10, toGranularity: .minute))
185+
if #available(iOS 8, macOS 10.10, *) {
186+
// Mac OS X 10.9 and iOS 7 had a bug in NSCalendar for hour, minute, and second granularities.
187+
expectEqual(.orderedSame, c.compare(d, to: d + 10, toGranularity: .minute))
188+
}
186189

187190
expectFalse(c.isDate(d, equalTo: d + 10, toGranularity: .second))
188191
expectTrue(c.isDate(d, equalTo: d + 10, toGranularity: .day))

โ€Žtest/stdlib/subString.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ SubstringTests.test("Equality") {
2929
expectEqual("fg" as String, s.suffix(2))
3030

3131
#if _runtime(_ObjC)
32-
let emoji: String = s + "๐Ÿ˜„๐Ÿ‘๐Ÿฝ๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ™ˆ" + "๐Ÿ˜ก๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡จ๐Ÿ‡ฆ๐Ÿ‡ฎ๐Ÿ‡ณ"
3332
expectTrue(s == s[...])
3433
expectTrue(s[...] == s)
3534
expectTrue(s.dropFirst(2) != s)
@@ -43,18 +42,29 @@ SubstringTests.test("Equality") {
4342
expectNotEqual(s.dropLast(2), s.dropLast(1))
4443
expectEqual(s.dropFirst(1), s.dropFirst(1))
4544
expectTrue(s != s[...].dropFirst(1))
45+
#endif
46+
47+
// equatable conformance
48+
expectTrue("one,two,three".split(separator: ",").contains("two"))
49+
expectTrue("one,two,three".split(separator: ",") == ["one","two","three"])
50+
}
51+
52+
#if _runtime(_ObjC)
53+
SubstringTests.test("Equality/Emoji")
54+
.xfail(.osxMinor(10, 9, reason: "Mac OS X 10.9 has an old ICU"))
55+
.xfail(.iOSMajor(7, reason: "iOS 7 has an old ICU"))
56+
.code {
57+
let s = "abcdefg"
58+
let emoji: String = s + "๐Ÿ˜„๐Ÿ‘๐Ÿฝ๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ™ˆ" + "๐Ÿ˜ก๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡จ๐Ÿ‡ฆ๐Ÿ‡ฎ๐Ÿ‡ณ"
4659
let i = emoji.firstIndex(of: "๐Ÿ˜„")!
4760
expectEqual("๐Ÿ˜„๐Ÿ‘๐Ÿฝ" as String, emoji[i...].prefix(2))
4861
expectTrue("๐Ÿ˜„๐Ÿ‘๐Ÿฝ๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ™ˆ๐Ÿ˜ก๐Ÿ‡ง๐Ÿ‡ช" as String == emoji[i...].dropLast(2))
4962
expectTrue("๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ™ˆ๐Ÿ˜ก๐Ÿ‡ง๐Ÿ‡ช" as String == emoji[i...].dropLast(2).dropFirst(2))
5063
expectTrue(s as String != emoji[i...].dropLast(2).dropFirst(2))
5164
expectEqualSequence("๐Ÿ˜„๐Ÿ‘๐Ÿฝ๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ™ˆ๐Ÿ˜ก๐Ÿ‡ง๐Ÿ‡ช" as String, emoji[i...].dropLast(2))
5265
expectEqualSequence("๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ๐Ÿ™ˆ๐Ÿ˜ก๐Ÿ‡ง๐Ÿ‡ช" as String, emoji[i...].dropLast(2).dropFirst(2))
53-
#endif
54-
// equatable conformance
55-
expectTrue("one,two,three".split(separator: ",").contains("two"))
56-
expectTrue("one,two,three".split(separator: ",") == ["one","two","three"])
5766
}
67+
#endif
5868

5969
SubstringTests.test("Comparison") {
6070
var s = "abc"

0 commit comments

Comments
ย (0)