XCTAssertUnrecoverable

master

Make it possible to test that universal error / logic failure occurs.
ukitaka/XCTAssertUnrecoverable

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.

# Podfile
use_frameworks!

target 'YOUR_TESTING_TARGET' do
    pod 'XCTAssertUnrecoverable', '~> 1.0'
end
$ pod install

Add this to Cartfile.private.

github "ukitaka/XCTAssertUnrecoverable"
$ carthage update
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

Description

  • Swift Tools 4.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Apr 14 2024 20:06:11 GMT-0900 (Hawaii-Aleutian Daylight Time)