Skip to content

[test] Re-add crash tests for getObjects:andKeys:count: #17907

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 1 commit into from
Jul 31, 2018
Merged
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
28 changes: 28 additions & 0 deletions validation-test/stdlib/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3429,6 +3429,12 @@ DictionaryTestSuite.test("BridgedToObjC.Verbatim.getObjects:andKeys:count:") {
}
}

DictionaryTestSuite.test("BridgedToObjC.Verbatim.getObjects:andKeys:count:/InvalidCount") {
expectCrashLater()
let d = getBridgedNSDictionaryOfRefTypesBridgedVerbatim()
checkGetObjectsAndKeys(d, count: -1)
}

//===---
// Dictionary -> NSDictionary bridging tests.
//
Expand Down Expand Up @@ -3534,6 +3540,12 @@ DictionaryTestSuite.test("BridgedToObjC.Custom.getObjects:andKeys:count:") {
}
}

DictionaryTestSuite.test("BridgedToObjC.Custom.getObjects:andKeys:count:/InvalidCount") {
expectCrashLater()
let d = getBridgedNSDictionaryOfKeyValue_ValueTypesCustomBridged()
checkGetObjectsAndKeys(d, count: -1)
}

func getBridgedNSDictionaryOfKey_ValueTypeCustomBridged() -> NSDictionary {
assert(!_isBridgedVerbatimToObjectiveC(TestBridgedKeyTy.self))
assert(_isBridgedVerbatimToObjectiveC(TestObjCValueTy.self))
Expand Down Expand Up @@ -4749,6 +4761,22 @@ DictionaryTestSuite.test("Hashable") {
}

DictionaryTestSuite.setUp {
#if _runtime(_ObjC)
// Exercise ARC's autoreleased return value optimization in Foundation.
//
// On some platforms, when a new process is started, the optimization is
// expected to fail the first time it is used in each linked
// dylib. StdlibUnittest takes care of warming up ARC for the stdlib
// (libswiftCore.dylib), but for this particular test we also need to do it
// for Foundation, or there will be spurious leaks reported for tests
// immediately following a crash test.
Copy link
Contributor

Choose a reason for hiding this comment

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

😱

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, maybe StdlibUnittest should do this instead, for every test. However, the relevant file doesn't import Foundation, and I hesitate to add the import there, for fear of even more unintended consequences.

//
// <rdar://problem/42069800> stdlib tests: expectCrashLater() interferes with
// counting autoreleased live objects
let d = NSDictionary(objects: [1 as NSNumber], forKeys: [1 as NSNumber])
_ = d.object(forKey: 1 as NSNumber)
#endif

resetLeaksOfDictionaryKeysValues()
#if _runtime(_ObjC)
resetLeaksOfObjCDictionaryKeysValues()
Expand Down