|
| 1 | +// RUN: %target-run-simple-swift 2>&1 | FileCheck %s |
| 2 | +// REQUIRES: executable_test |
| 3 | +// REQUIRES: objc_interop |
| 4 | + |
| 5 | +import StdlibUnittest |
| 6 | +import ObjectiveC |
| 7 | +import Foundation |
| 8 | + |
| 9 | +// Don't actually exit with a non-zero status, just say we're going to do it. |
| 10 | +_setTestSuiteFailedCallback() { print("abort()") } |
| 11 | + |
| 12 | + |
| 13 | +func raiseNSException() { |
| 14 | + NSException(name: "Trogdor", reason: "Burnination", userInfo: nil).raise() |
| 15 | +} |
| 16 | + |
| 17 | +var TestSuiteCrashes = TestSuite("NSExceptionCrashes") |
| 18 | + |
| 19 | +TestSuiteCrashes.test("uncaught") { |
| 20 | + print("uncaught") |
| 21 | + raiseNSException() |
| 22 | +} |
| 23 | +// CHECK-LABEL: stdout>>> uncaught |
| 24 | +// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Burnination |
| 25 | +// CHECK: stderr>>> CRASHED: SIG |
| 26 | +// CHECK: the test crashed unexpectedly |
| 27 | +// CHECK: [ FAIL ] NSExceptionCrashes.uncaught |
| 28 | + |
| 29 | +TestSuiteCrashes.test("crashesAsExpected") { |
| 30 | + print("crashesAsExpected") |
| 31 | + expectCrashLater() |
| 32 | + raiseNSException() |
| 33 | +} |
| 34 | +// CHECK-LABEL: stdout>>> crashesAsExpected |
| 35 | +// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Burnination |
| 36 | +// CHECK: stderr>>> OK: saw expected "crashed: sig |
| 37 | +// CHECK: [ OK ] NSExceptionCrashes.crashesAsExpected |
| 38 | + |
| 39 | +TestSuiteCrashes.test("crashesWithMessage") |
| 40 | + .crashOutputMatches("libUnittest]") |
| 41 | + .crashOutputMatches("Trogdor") |
| 42 | + .crashOutputMatches("Burnination").code { |
| 43 | + print("crashesWithMessage") |
| 44 | + expectCrashLater() |
| 45 | + raiseNSException() |
| 46 | +} |
| 47 | +// CHECK-LABEL: stdout>>> crashesWithMessage |
| 48 | +// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception Trogdor: Burnination |
| 49 | +// CHECK: stderr>>> OK: saw expected "crashed: sig |
| 50 | +// CHECK: [ OK ] NSExceptionCrashes.crashesWithMessage |
| 51 | + |
| 52 | +TestSuiteCrashes.test("nonNSException") |
| 53 | + .crashOutputMatches("countryside").code { |
| 54 | + print("nonNSException") |
| 55 | + expectCrashLater() |
| 56 | + objc_exception_throw("countryside") |
| 57 | +} |
| 58 | +// CHECK-LABEL: stdout>>> nonNSException |
| 59 | +// CHECK: stderr>>> *** [StdlibUnittest] Terminating due to uncaught exception: countryside |
| 60 | +// CHECK: stderr>>> OK: saw expected "crashed: sig |
| 61 | +// CHECK: [ OK ] NSExceptionCrashes.nonNSException |
| 62 | + |
| 63 | +// CHECK: NSExceptionCrashes: Some tests failed, aborting |
| 64 | +// CHECK: abort() |
| 65 | + |
| 66 | +runAllTests() |
| 67 | + |
0 commit comments