ukitaka/xctassertunrecoverable
This library makes it possible to test that universal error / logic failure occurs, even if you use `fatalError`, `preconditionFailure` and so on.
Installation
XCTAssertUnrecoverable depends on johnno1962/Fortify, but it is included in this library directly to support CocoaPods, Carthage for now.
CocoaPods
# Podfile
use_frameworks!
target 'YOUR_TESTING_TARGET' do
pod 'XCTAssertUnrecoverable', '~> 1.0'
end$ pod installCarthage
Add this to Cartfile.private.
github "ukitaka/XCTAssertUnrecoverable"$ carthage updateSwift Package Manager
let 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 buildUsage
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.
<img src="Assets/disable-lldb.png" />
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!")
}
}Requirements
Swift 4.1
Package Metadata
Repository: ukitaka/xctassertunrecoverable
Default branch: master
README: README.md