XCTAssertUnrecoverable 1.0.0

XCTAssertUnrecoverable 1.0.0

Maintained by ukitaka.



  • By
  • ukitaka

XCTAssertUnrecoverable

Build Status platforms pod Carthage compatible Swift Package Manager compatible

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 install

Carthage

Add this to Cartfile.private.

github "ukitaka/XCTAssertUnrecoverable"
$ carthage update

Swift 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 build

Usage

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!")
    }
}

Requirements

Swift 4.1