Skip to content

[test] Tweak some tests so that they run consistently on OS X 10.9 #19702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/Interpreter/SDK/class_getImageName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ testSuite.test("KVO/ObjC") {
}

testSuite.test("dynamic") {
let newClass: AnyClass = objc_allocateClassPair(/*superclass*/nil,
let newClass: AnyClass = objc_allocateClassPair(/*superclass*/NSObject.self,
"CompletelyDynamic",
/*extraBytes*/0)!
objc_registerClassPair(newClass)
Expand Down
19 changes: 10 additions & 9 deletions test/Interpreter/SDK/objc_bridge_cast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,16 @@ func testValueToObjectBridgingInSwitch() {
}
}

#if arch(i386) || arch(arm)
#else
// Small strings should be immortal
autoreleasepool {
let string = "hello"
let nsString = string as NSString
objc_setAssociatedObject(
nsString, &ImmortalCanaryAssocObjectHandle, ImmortalCanary(),
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
#if !(arch(i386) || arch(arm))
// Small strings should be immortal on new enough 64-bit Apple platforms.
if #available(macOS 10.10, *) {
autoreleasepool {
let string = "hello"
let nsString = string as NSString
objc_setAssociatedObject(
nsString, &ImmortalCanaryAssocObjectHandle, ImmortalCanary(),
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
#endif // 64-bit
print("Done")
Expand Down
10 changes: 5 additions & 5 deletions test/Interpreter/SDK/objc_swift_getObjectType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ extension P {
class O: NSObject, P { }
var o = O()
let obase: NSObject = o
print(String(cString: object_getClassName(o)))
print(NSStringFromClass(object_getClass(o)!))
_ = (o as P).anyP
_ = (obase as! P).anyP
// CHECK: main.O
// CHECK: {{^}}main.O{{$}}

// ... and KVO's artificial subclass thereof
o.addObserver(NSObject(), forKeyPath: "xxx", options: [.new], context: nil)
print(String(cString: object_getClassName(o)))
print(NSStringFromClass(object_getClass(o)!))
_ = (o as P).anyP
_ = (obase as! P).anyP
// CHECK-NEXT: NSKVONotifying_main.O
Expand All @@ -47,14 +47,14 @@ _ = (obase as! P).anyP
extension NSLock: P { }
var l = NSLock()
let lbase: NSObject = l
print(String(cString: object_getClassName(l)))
print(NSStringFromClass(object_getClass(l)!))
_ = (l as P).anyP
_ = (lbase as! P).anyP
// CHECK-NEXT: NSLock

// ... and KVO's artificial subclass thereof
l.addObserver(NSObject(), forKeyPath: "xxx", options: [.new], context: nil)
print(String(cString: object_getClassName(l)))
print(NSStringFromClass(object_getClass(l)!))
_ = (l as P).anyP
_ = (lbase as! P).anyP
// CHECK-NEXT: NSKVONotifying_NSLock
23 changes: 23 additions & 0 deletions test/stdlib/CodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -442,19 +442,30 @@ class TestCodable : TestCodableSuper {
lazy var indexSetValues: [Int : IndexSet] = [
#line : IndexSet(),
#line : IndexSet(integer: 42),
]
lazy var indexSetMaxValues: [Int : IndexSet] = [
#line : IndexSet(integersIn: 0 ..< Int.max)
]

func test_IndexSet_JSON() {
for (testLine, indexSet) in indexSetValues {
expectRoundTripEqualityThroughJSON(for: indexSet, lineNumber: testLine)
}
if #available(macOS 10.10, iOS 8, *) {
// Mac OS X 10.9 and iOS 7 weren't able to round-trip Int.max in JSON.
for (testLine, indexSet) in indexSetMaxValues {
expectRoundTripEqualityThroughJSON(for: indexSet, lineNumber: testLine)
}
}
}

func test_IndexSet_Plist() {
for (testLine, indexSet) in indexSetValues {
expectRoundTripEqualityThroughPlist(for: indexSet, lineNumber: testLine)
}
for (testLine, indexSet) in indexSetMaxValues {
expectRoundTripEqualityThroughPlist(for: indexSet, lineNumber: testLine)
}
}

// MARK: - Locale
Expand Down Expand Up @@ -506,6 +517,9 @@ class TestCodable : TestCodableSuper {
// MARK: - NSRange
lazy var nsrangeValues: [Int : NSRange] = [
#line : NSRange(),
#line : NSRange(location: 5, length: 20),
]
lazy var nsrangeMaxValues: [Int : NSRange] = [
#line : NSRange(location: 0, length: Int.max),
#line : NSRange(location: NSNotFound, length: 0),
]
Expand All @@ -514,12 +528,21 @@ class TestCodable : TestCodableSuper {
for (testLine, range) in nsrangeValues {
expectRoundTripEqualityThroughJSON(for: range, lineNumber: testLine)
}
if #available(macOS 10.10, iOS 8, *) {
// Mac OS X 10.9 and iOS 7 weren't able to round-trip Int.max in JSON.
for (testLine, range) in nsrangeMaxValues {
expectRoundTripEqualityThroughJSON(for: range, lineNumber: testLine)
}
}
}

func test_NSRange_Plist() {
for (testLine, range) in nsrangeValues {
expectRoundTripEqualityThroughPlist(for: range, lineNumber: testLine)
}
for (testLine, range) in nsrangeMaxValues {
expectRoundTripEqualityThroughPlist(for: range, lineNumber: testLine)
}
}

// MARK: - PersonNameComponents
Expand Down
11 changes: 9 additions & 2 deletions test/stdlib/NSSlowString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ tests.test("Iterator") {
expectEqualSequence(opaque.utf8.reversed(), native.utf8.reversed())
}

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

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

tests.test("Zalgo") {
tests.test("Zalgo")
.xfail(.osxMinor(10, 9, reason: "Mac OS X 10.9 has an old version of ICU"))
.xfail(.iOSMajor(7, reason: "iOS 7 has an old version of ICU"))
.code {

// Check that we handle absurdly long graphemes
var zalgo = "a👩‍👩‍👧‍👦c"
for combo in 0x300...0x36f {
Expand Down
5 changes: 4 additions & 1 deletion test/stdlib/TestCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ class TestCalendar : TestCalendarSuper {

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

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

expectFalse(c.isDate(d, equalTo: d + 10, toGranularity: .second))
expectTrue(c.isDate(d, equalTo: d + 10, toGranularity: .day))
Expand Down
20 changes: 15 additions & 5 deletions test/stdlib/subString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ SubstringTests.test("Equality") {
expectEqual("fg" as String, s.suffix(2))

#if _runtime(_ObjC)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why all these substring tests are guarded under _runtime(_ObjC). Is that a mistake, @milseman?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason would be if they exercised grapheme breaking that the oldest Ubuntu LTS didn't support

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(in which case availability would be a better tool for this)

let emoji: String = s + "😄👍🏽🇫🇷👩‍👩‍👧‍👦🙈" + "😡🇧🇪🇨🇦🇮🇳"
expectTrue(s == s[...])
expectTrue(s[...] == s)
expectTrue(s.dropFirst(2) != s)
Expand All @@ -43,18 +42,29 @@ SubstringTests.test("Equality") {
expectNotEqual(s.dropLast(2), s.dropLast(1))
expectEqual(s.dropFirst(1), s.dropFirst(1))
expectTrue(s != s[...].dropFirst(1))
#endif

// equatable conformance
expectTrue("one,two,three".split(separator: ",").contains("two"))
expectTrue("one,two,three".split(separator: ",") == ["one","two","three"])
}

#if _runtime(_ObjC)
SubstringTests.test("Equality/Emoji")
.xfail(.osxMinor(10, 9, reason: "Mac OS X 10.9 has an old ICU"))
.xfail(.iOSMajor(7, reason: "iOS 7 has an old ICU"))
.code {
let s = "abcdefg"
let emoji: String = s + "😄👍🏽🇫🇷👩‍👩‍👧‍👦🙈" + "😡🇧🇪🇨🇦🇮🇳"
let i = emoji.firstIndex(of: "😄")!
expectEqual("😄👍🏽" as String, emoji[i...].prefix(2))
expectTrue("😄👍🏽🇫🇷👩‍👩‍👧‍👦🙈😡🇧🇪" as String == emoji[i...].dropLast(2))
expectTrue("🇫🇷👩‍👩‍👧‍👦🙈😡🇧🇪" as String == emoji[i...].dropLast(2).dropFirst(2))
expectTrue(s as String != emoji[i...].dropLast(2).dropFirst(2))
expectEqualSequence("😄👍🏽🇫🇷👩‍👩‍👧‍👦🙈😡🇧🇪" as String, emoji[i...].dropLast(2))
expectEqualSequence("🇫🇷👩‍👩‍👧‍👦🙈😡🇧🇪" as String, emoji[i...].dropLast(2).dropFirst(2))
#endif
// equatable conformance
expectTrue("one,two,three".split(separator: ",").contains("two"))
expectTrue("one,two,three".split(separator: ",") == ["one","two","three"])
}
#endif

SubstringTests.test("Comparison") {
var s = "abc"
Expand Down