Skip to content

Commit 8048004

Browse files
committed
Document the test hacks more clearly
1 parent fac8822 commit 8048004

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

test/stdlib/SwiftObjectNSObject.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ func TestEquatableHash(_ e: AnyObject)
124124
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
125125
// Legacy behavior: Equatable in Swift => ObjC hashes with identity
126126
TestSwiftObjectNSObjectDefaultHashValue(e)
127-
let msg = "Obj-C `-hash` ... type `SwiftObjectNSObject.\(type(of: e))` ... Equatable but not Hashable\n"
128-
fputs(msg, stderr)
127+
fakeEquatableWarning(e)
129128
#else
130129
// New behavior: These should have a constant hash value
131130
TestSwiftObjectNSObjectHashValue(e, 1)
@@ -143,11 +142,19 @@ func TestNonEquatableHash(_ e: AnyObject)
143142
// CHECK-NEXT: d ##SwiftObjectNSObject.D##
144143
// CHECK-NEXT: S ##{{.*}}SwiftObject##
145144
146-
// Full message is longer, but this is the essential part...
145+
// Verify that the runtime emits the warning that we expected...
147146
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftObjectNSObject.E` {{.*}} Equatable but not Hashable
148147
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftObjectNSObject.E1` {{.*}} Equatable but not Hashable
149148
// CHECK-NEXT: Obj-C `-hash` {{.*}} type `SwiftObjectNSObject.E2` {{.*}} Equatable but not Hashable
150149
150+
// If we're checking legacy behavior or unsupported platform, then
151+
// the warning above won't be emitted. This function emits a fake
152+
// message that will satisfy the checks above in such cases.
153+
func fakeEquatableWarning(e: AnyObject) {
154+
let msg = "Obj-C `-hash` ... type `SwiftObjectNSObject.\(type(of: e))` ... Equatable but not Hashable\n"
155+
fputs(msg, stderr)
156+
}
157+
151158
// Temporarily disable this test on older OSes until we have time to
152159
// look into why it's failing there. rdar://problem/47870743
153160
if #available(OSX 10.12, iOS 10.0, *) {
@@ -213,7 +220,7 @@ if #available(OSX 10.12, iOS 10.0, *) {
213220
fputs("c ##SwiftObjectNSObject.C##\n", stderr)
214221
fputs("d ##SwiftObjectNSObject.D##\n", stderr)
215222
fputs("S ##Swift._SwiftObject##\n", stderr)
216-
fputs("Obj-C `-hash` ... type `SwiftObjectNSObject.E` ... Equatable but not Hashable", stderr)
217-
fputs("Obj-C `-hash` ... type `SwiftObjectNSObject.E1` ... Equatable but not Hashable", stderr)
218-
fputs("Obj-C `-hash` ... type `SwiftObjectNSObject.E2` ... Equatable but not Hashable", stderr)
223+
fakeEquatableWarning(E(i:1))
224+
fakeEquatableWarning(E1(i:1))
225+
fakeEquatableWarning(E2(i:1))
219226
}

0 commit comments

Comments
 (0)