-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compatibility with beta 3 plus allow optional injections (#2)
Compatibility with beta 3 plus allow optional injections
- Loading branch information
Showing
13 changed files
with
186 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
Pod::Spec.new do |spec| | ||
spec.name = "InjectPropertyWrapper" | ||
spec.version = "0.2.0" | ||
spec.version = "0.3.0" | ||
spec.author = { "Peter Verhage" => "[email protected]" } | ||
spec.homepage = "https://github.com/egeniq/InjectPropertyWrapper" | ||
spec.license = { :type => "MIT", :file => "LICENSE" } | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// FatalError.swift | ||
// | ||
// | ||
// Created by Peter Verhage on 03/07/2019. | ||
// | ||
// See https://marcosantadev.com/test-swift-fatalerror/ | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
struct FatalErrorUtil { | ||
private static let defaultFatalErrorClosure = { Swift.fatalError($0, file: $1, line: $2) } | ||
static var fatalErrorClosure: (String, StaticString, UInt) -> Never = defaultFatalErrorClosure | ||
|
||
static func replaceFatalError(closure: @escaping (String, StaticString, UInt) -> Never) { | ||
fatalErrorClosure = closure | ||
} | ||
|
||
static func restoreFatalError() { | ||
fatalErrorClosure = defaultFatalErrorClosure | ||
} | ||
} | ||
|
||
func fatalError(_ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) -> Never { | ||
FatalErrorUtil.fatalErrorClosure(message(), file, line) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Tests/InjectPropertyWrapperTests/XCTestCase+FatalError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Peter Verhage on 03/07/2019. | ||
// | ||
// See https://marcosantadev.com/test-swift-fatalerror/ | ||
// | ||
|
||
import Foundation | ||
|
||
import XCTest | ||
@testable import InjectPropertyWrapper | ||
|
||
extension XCTestCase { | ||
func expectFatalError(expectedMessage: String, testcase: @escaping () -> Void) { | ||
let expectation = self.expectation(description: "expectingFatalError") | ||
var assertionMessage: String? = nil | ||
|
||
FatalErrorUtil.replaceFatalError { message, _, _ in | ||
assertionMessage = message | ||
expectation.fulfill() | ||
self.unreachable() | ||
} | ||
|
||
DispatchQueue.global(qos: .userInitiated).async(execute: testcase) | ||
|
||
waitForExpectations(timeout: 2) { _ in | ||
XCTAssertEqual(assertionMessage, expectedMessage) | ||
FatalErrorUtil.restoreFatalError() | ||
} | ||
} | ||
|
||
private func unreachable() -> Never { | ||
repeat { | ||
RunLoop.current.run() | ||
} while (true) | ||
} | ||
} |