ReSwift / ReSwift
1
//
2
//  Assertions
3
//  Copyright © 2015 mohamede1945. All rights reserved.
4
//  https://github.com/mohamede1945/AssertionsTestingExample
5
//
6

7
import Foundation
8

9
/// drop-in fatalError replacement for testing
10

11
/**
12
 Swift.fatalError wrapper for catching in tests
13

14
 - parameter message: Message to be wrapped
15
 - parameter file:    Calling file
16
 - parameter line:    Calling line
17
 */
18 0
func raiseFatalError(_ message: @autoclosure () -> String = "",
19 6
                     file: StaticString = #file, line: UInt = #line) -> Never {
20 6
    Assertions.fatalErrorClosure(message(), file, line)
21 6
    repeat {
22 6
        RunLoop.current.run()
23 6
    } while (true)
24
}
25

26
/// Stores custom assertions closures, by default it points to Swift functions. But test target can
27
/// override them.
28
class Assertions {
29
    static var fatalErrorClosure = swiftFatalErrorClosure
30
    static let swiftFatalErrorClosure: (String, StaticString, UInt) -> Void
31
        = { Swift.fatalError($0, file: $1, line: $2) }
32
}

Read our documentation on viewing source code .

Loading