forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionalTraps.swift
49 lines (41 loc) · 1.37 KB
/
OptionalTraps.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %target-build-swift %s -o %t/Assert_Debug -Onone
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Release -O
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Unchecked -Ounchecked
//
// RUN: %target-run %t/Assert_Debug
// RUN: %target-run %t/Assert_Release
// RUN: %target-run %t/Assert_Unchecked
// REQUIRES: executable_test
import StdlibUnittest
// Also import modules which are used by StdlibUnittest internally. This
// workaround is needed to link all required libraries in case we compile
// StdlibUnittest with -sil-serialize-all.
import SwiftPrivate
#if _runtime(_ObjC)
import ObjectiveC
#endif
func returnNil() -> AnyObject? {
return _opaqueIdentity(nil as AnyObject?)
}
var OptionalTraps = TestSuite("OptionalTraps")
OptionalTraps.test("UnwrapNone")
.skip(.Custom(
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.code {
var a: AnyObject? = returnNil()
expectCrashLater()
let unwrapped: AnyObject = a!
_blackHole(unwrapped)
}
OptionalTraps.test("UnwrapNone/Ounchecked")
.xfail(.Custom(
{ !_isFastAssertConfiguration() },
reason: "unwrapping nil should trap unless we are in -Ounchecked mode"))
.code {
var a: AnyObject? = returnNil()
expectEqual(0, unsafeBitCast(a!, Int.self))
}
runAllTests()