Skip to content

Commit

Permalink
Merge pull request #389 from Quick/dont-use-objc-initialize
Browse files Browse the repository at this point in the history
Alternative implementation of #372
  • Loading branch information
jeffh authored Jan 24, 2017
2 parents f32a236 + 7e8195a commit 44e3fbd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
17 changes: 4 additions & 13 deletions Sources/Nimble/Adapters/NimbleXCTestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,7 @@ class NimbleXCTestUnavailableHandler: AssertionHandler {
}
}

#if _runtime(_ObjC)

#if SWIFT_PACKAGE
extension XCTestObservationCenter {
override open class func initialize() {
self.shared().addTestObserver(CurrentTestCaseTracker.sharedInstance)
}
}
#endif

#if !SWIFT_PACKAGE
/// Helper class providing access to the currently executing XCTestCase instance, if any
@objc final internal class CurrentTestCaseTracker: NSObject, XCTestObservation {
@objc static let sharedInstance = CurrentTestCaseTracker()
Expand All @@ -71,15 +62,15 @@ func isXCTestAvailable() -> Bool {
}

private func recordFailure(_ message: String, location: SourceLocation) {
#if _runtime(_ObjC)
#if SWIFT_PACKAGE
XCTFail("\(message)", file: location.file, line: location.line)
#else
if let testCase = CurrentTestCaseTracker.sharedInstance.currentTestCase {
testCase.recordFailure(withDescription: message, inFile: location.file, atLine: location.line, expected: true)
} else {
let msg = "Attempted to report a test failure to XCTest while no test case was running. " +
"The failure was:\n\"\(message)\"\nIt occurred at: \(location.file):\(location.line)"
NSException(name: .internalInconsistencyException, reason: msg, userInfo: nil).raise()
}
#else
XCTFail("\(message)\n", file: location.file, line: location.line)
#endif
}
4 changes: 2 additions & 2 deletions Sources/Nimble/DSL+Wait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ internal class NMBWait: NSObject {
}
}

#if _runtime(_ObjC)
@objc(untilFile:line:action:)
#if SWIFT_PACKAGE
internal class func until(_ file: FileString = #file, line: UInt = #line, action: @escaping (() -> Void) -> Void) -> Void {
until(timeout: 1, file: file, line: line, action: action)
}
#else
@objc(untilFile:line:action:)
internal class func until(_ file: FileString = #file, line: UInt = #line, action: @escaping (() -> Void) -> Void) -> Void {
until(timeout: 1, file: file, line: line, action: action)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Nimble/Utils/SourceLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Foundation
// stdlib, and because recent versions of the XCTest overlay require `StaticString`
// when calling `XCTFail`. Under the Objective-C runtime (i.e. building on Mac), we
// have to use `String` instead because StaticString can't be generated from Objective-C
#if _runtime(_ObjC)
public typealias FileString = String
#else
#if SWIFT_PACKAGE
public typealias FileString = StaticString
#else
public typealias FileString = String
#endif

public final class SourceLocation: NSObject {
Expand Down

0 comments on commit 44e3fbd

Please sign in to comment.