Skip to content

Commit 54e4b59

Browse files
committed
StdlibUnittest: Fix NSException catching (broken by SE-0054).
Previously, the callback for objc_setUncaughtExceptionHandler took a parameter of type 'AnyObject!', which was implicitly unwrapped at all uses inside the closure. When that became 'AnyObject?', we started getting an extra layer of Optional in the printed output. This reverts the tests to their pre-4d540c2a state.
1 parent 894318c commit 54e4b59

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,17 @@ func _childProcess() {
627627

628628
#if _runtime(_ObjC)
629629
objc_setUncaughtExceptionHandler {
630+
let exception: AnyObject = $0!
630631
var stderr = _Stderr()
631-
let maybeNSException = unsafeBitCast($0, to:_StdlibUnittestNSException.self)
632+
let maybeNSException =
633+
unsafeBitCast(exception, to: _StdlibUnittestNSException.self)
632634
if let name = maybeNSException.name {
633635
print("*** [StdlibUnittest] Terminating due to uncaught exception " +
634-
"\(name): \($0)",
636+
"\(name): \(exception)",
635637
to: &stderr)
636638
} else {
637-
print("*** [StdlibUnittest] Terminating due to uncaught exception: \($0)",
639+
print("*** [StdlibUnittest] Terminating due to uncaught exception: " +
640+
"\(exception)",
638641
to: &stderr)
639642
}
640643
}

validation-test/StdlibUnittest/NSException.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ TestSuiteCrashes.test("uncaught") {
2121
raiseNSException()
2222
}
2323
// CHECK-LABEL: stdout>>> uncaught
24-
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Optional(Burnination)
25-
// FIXME: listed reason above should be "Burnination", not "Optional(Burnination)"; may have to do with SE-0054
24+
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Burnination
2625
// CHECK: stderr>>> CRASHED: SIG
2726
// CHECK: the test crashed unexpectedly
2827
// CHECK: [ FAIL ] NSExceptionCrashes.uncaught
@@ -33,7 +32,7 @@ TestSuiteCrashes.test("crashesAsExpected") {
3332
raiseNSException()
3433
}
3534
// CHECK-LABEL: stdout>>> crashesAsExpected
36-
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Optional(Burnination)
35+
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Burnination
3736
// CHECK: stderr>>> OK: saw expected "crashed: sig
3837
// CHECK: [ OK ] NSExceptionCrashes.crashesAsExpected
3938

@@ -46,7 +45,7 @@ TestSuiteCrashes.test("crashesWithMessage")
4645
raiseNSException()
4746
}
4847
// CHECK-LABEL: stdout>>> crashesWithMessage
49-
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Optional(Burnination)
48+
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Burnination
5049
// CHECK: stderr>>> OK: saw expected "crashed: sig
5150
// CHECK: [ OK ] NSExceptionCrashes.crashesWithMessage
5251

@@ -57,7 +56,7 @@ TestSuiteCrashes.test("nonNSException")
5756
objc_exception_throw("countryside")
5857
}
5958
// CHECK-LABEL: stdout>>> nonNSException
60-
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception: Optional(countryside)
59+
// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception: countryside
6160
// CHECK: stderr>>> OK: saw expected "crashed: sig
6261
// CHECK: [ OK ] NSExceptionCrashes.nonNSException
6362

0 commit comments

Comments
 (0)