Files
swift-mirror/test/1_stdlib/OptionalTraps.swift
Dmitri Hrybenko 932e228ed2 IRGen: mark autolinking information on ELF as used
Swift SVN r25845
2015-03-08 03:49:54 +00:00

41 lines
1.1 KiB
Swift

// 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
import StdlibUnittest
func returnNil() -> AnyObject? {
return _opaqueIdentity(nil as AnyObject?)
}
var OptionalTraps = TestSuite("OptionalTraps")
OptionalTraps.test("UnwrapNone")
.skip(.Custom(
{ _isFastAssertConfiguration() },
reason: "unwrapping nil might or might not cause a crash in -Ounchecked mode"))
.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!, Word.self))
}
runAllTests()