mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`. As proposed in SE-0107: UnsafeRawPointer. `void*` imports as `UnsafeMutableRawPointer`. `const void*` imports as `UnsafeRawPointer`. Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer. * Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer. This requires explicit memory binding in several places, particularly in NSData and CoreAudio. * Fix a bunch of test cases for Void->Raw migration. * qsort takes IUO values * Bridge `Unsafe[Mutable]RawPointer as `void [const] *`. * Parse #dsohandle as UnsafeMutableRawPointer * Update a bunch of test cases for Void->Raw migration. * Trivial fix for the SceneKit test case. * Add an UnsafeRawPointer self initializer. This is unfortunately necessary for assignment between types imported from C. * Tiny simplification of the initializer.
55 lines
1.3 KiB
Swift
55 lines
1.3 KiB
Swift
// RUN: rm -rf %t && mkdir -p %t
|
|
//
|
|
// RUN: %target-clang -fobjc-arc %S/Inputs/ObjCClasses/ObjCClasses.m -c -o %t/ObjCClasses.o
|
|
// RUN: %target-build-swift -I %S/Inputs/ObjCClasses/ %t/ObjCClasses.o %s -o %t/a.out
|
|
// RUN: %target-run %t/a.out
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: objc_interop
|
|
|
|
import ObjCClasses
|
|
import Foundation
|
|
import StdlibUnittest
|
|
|
|
var ErrorHandlingTests = TestSuite("ErrorHandling")
|
|
|
|
ErrorHandlingTests.test("nil") {
|
|
do {
|
|
try TestingNSError.throwNilError()
|
|
expectUnreachable()
|
|
} catch {
|
|
expectEqual("Foundation._GenericObjCError.nilError", String(reflecting: error))
|
|
}
|
|
}
|
|
|
|
ErrorHandlingTests.test("pointerFailure") {
|
|
do {
|
|
_ = try TestingNSError.maybeThrow(true)
|
|
expectUnreachable()
|
|
} catch let error as NSError {
|
|
expectEqual("pointer error", error.domain)
|
|
}
|
|
}
|
|
|
|
ErrorHandlingTests.test("pointerSuccess") {
|
|
do {
|
|
var pointer = try TestingNSError.maybeThrow(false)
|
|
expectType(UnsafeMutableRawPointer.self, &pointer)
|
|
expectEqual(UnsafeMutablePointer(bitPattern: 42)!, pointer)
|
|
} catch {
|
|
expectUnreachableCatch(error)
|
|
}
|
|
}
|
|
|
|
ErrorHandlingTests.test("blockFailure") {
|
|
do {
|
|
_ = try TestingNSError.blockThrowError()
|
|
expectUnreachable()
|
|
} catch let error as NSError {
|
|
expectEqual("block error", error.domain)
|
|
}
|
|
}
|
|
|
|
runAllTests()
|
|
|