This library makes it possible to test that universal error / logic failure occurs, even if you use fatalError, preconditionFailure and so on.
XCTAssertUnrecoverable depends on johnno1962/Fortify, but it is included in this library directly to support CocoaPods, Carthage for now.
# Podfile
use_frameworks!
target 'YOUR_TESTING_TARGET' do
pod 'XCTAssertUnrecoverable', '~> 1.0'
end$ pod installAdd this to Cartfile.private.
github "ukitaka/XCTAssertUnrecoverable"
$ carthage updatelet package = Package(
name: "YourModule",
dependencies: [
.package(url: "https://github.com/ukitaka/XCTAssertUnrecoverable.git", "1.0.0")
],
targets: [
.target(
name: "YourModule",
dependencies: [ ... ]),
.testTarget(
name: "YourModuleTests",
dependencies: ["XCTAssertUnrecoverable"]),
]
)$ swift build
Only one function XCTAssertUnrecoverable is provided.
import XCTest
import XCTAssertUnrecoverable
class ExampleTests: XCTestCase {
func testExample() {
XCTAssertUnrecoverable {
// some program that will crash.
}
}
}Important: Please disable a debugger.
lldb traps some signals such as SIGILL, SIGABRT so you cannot use this library with debugger.
Important: Be careful with build configuration, and optimization level.
For instance, assert works only in -Onone builds.
So it may not crash in other optimization level.
| -Onone | -O | -Osize | -Ounchecked | |
|---|---|---|---|---|
| fatalError | ✅ | ✅ | ✅ | ✅ |
| precondition | ✅ | ✅ | ✅ | ❌ |
| assert | ✅ | ❌ | ❌ | ❌ |
Note: Multithreading is not supported yet.
// NG
XCTAssertUnrecoverable {
DispatchQueue.global().async {
fatalError("fatal error!")
}
}Swift 4.1


