Skip to content

Commit 6c173fe

Browse files
committed
Fix up tests to deal with varying behaviors
1 parent b3ed7ae commit 6c173fe

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

test/stdlib/Inputs/SwiftValueNSObject/SwiftValueNSObject.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ void TestSwiftValueNSObjectNotEquals(id e1, id e2)
102102

103103
void TestSwiftValueNSObjectHashValue(id e, NSUInteger hashValue)
104104
{
105-
printf("NSObjectProtocol.hash: Expect [%s hashValue] == %lu\n",
105+
printf("NSObjectProtocol.hash: Expect [%s hashValue] == %lu, Got %lu\n",
106106
[[e description] UTF8String],
107-
(unsigned long)hashValue);
107+
(unsigned long)hashValue,
108+
[e hash]);
108109
expectTrue([e hash] == hashValue);
109110
}
110111

test/stdlib/SwiftValueNSObject.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,14 @@ func TestHashable<T: Hashable>(_ h: T)
9898
// Test Obj-C hashValue for Swift types that are Equatable but not Hashable
9999
func TestEquatableHash<T: Equatable>(_ e: T)
100100
{
101-
// These should have a constant hash value
101+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
102+
// Legacy behavior used the pointer value, which is
103+
// incompatible with user-defined equality.
104+
TestSwiftValueNSObjectDefaultHashValue(e as AnyObject)
105+
#else
106+
// New behavior uses a constant hash value in this case
102107
TestSwiftValueNSObjectHashValue(e as AnyObject, 1)
108+
#endif
103109
}
104110

105111
func TestNonEquatableHash<T>(_ e: T)
@@ -113,10 +119,6 @@ func TestNonEquatableHash<T>(_ e: T)
113119
// CHECK-NEXT: d ##This is D's description##
114120
// CHECK-NEXT: S ##{{.*}}__SwiftValue##
115121

116-
// Full message is longer, but this is the essential part...
117-
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftValueNSObject.E` {{.*}} Equatable but not Hashable
118-
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftValueNSObject.E1` {{.*}} Equatable but not Hashable
119-
120122
// Temporarily disable this test on older OSes until we have time to
121123
// look into why it's failing there. rdar://problem/47870743
122124
if #available(OSX 10.12, iOS 10.0, *) {
@@ -156,6 +158,4 @@ if #available(OSX 10.12, iOS 10.0, *) {
156158
fputs("c ##This is C's debug description##\n", stderr)
157159
fputs("d ##This is D's description##\n", stderr)
158160
fputs("S ##__SwiftValue##\n", stderr)
159-
fputs("Obj-C `-hash` ... type `SwiftValueNSObject.E` ... Equatable but not Hashable", stderr)
160-
fputs("Obj-C `-hash` ... type `SwiftValueNSObject.E1` ... Equatable but not Hashable", stderr)
161161
}

0 commit comments

Comments
 (0)