Skip to content

Commit

Permalink
Merge pull request Quick#536 from Quick/backport-xcode-10
Browse files Browse the repository at this point in the history
Backport Xcode 10 changes to 7.x-branch
  • Loading branch information
ikesyo authored Jun 6, 2018
2 parents a314123 + d447cae commit b7ea296
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Sources/Nimble/Adapters/NMBExpectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ internal struct ObjCMatcherWrapper: Matcher {

// Equivalent to Expectation, but for Nimble's Objective-C interface
public class NMBExpectation: NSObject {
internal let _actualBlock: () -> NSObject!
internal let _actualBlock: () -> NSObject?
internal var _negative: Bool
internal let _file: FileString
internal let _line: UInt
internal var _timeout: TimeInterval = 1.0

@objc public init(actualBlock: @escaping () -> NSObject!, negative: Bool, file: FileString, line: UInt) {
@objc public init(actualBlock: @escaping () -> NSObject?, negative: Bool, file: FileString, line: UInt) {
self._actualBlock = actualBlock
self._negative = negative
self._file = file
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nimble/Adapters/NMBObjCMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class NMBObjCMatcher: NSObject, NMBMatcher {
return true
}

public func matches(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
public func matches(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let expr = Expression(expression: actualBlock, location: location)
let result = _match(
expr,
Expand All @@ -67,7 +67,7 @@ public class NMBObjCMatcher: NSObject, NMBMatcher {
}
}

public func doesNotMatch(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
public func doesNotMatch(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let expr = Expression(expression: actualBlock, location: location)
let result = _doesNotMatch(
expr,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nimble/Matchers/BeCloseTo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NMBObjCBeCloseToMatcher: NSObject, NMBMatcher {
_delta = within
}

@objc public func matches(_ actualExpression: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
@objc public func matches(_ actualExpression: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let actualBlock: () -> NMBDoubleConvertible? = ({
return actualExpression() as? NMBDoubleConvertible
})
Expand All @@ -52,7 +52,7 @@ public class NMBObjCBeCloseToMatcher: NSObject, NMBMatcher {
return try! matcher.matches(expr, failureMessage: failureMessage)
}

@objc public func doesNotMatch(_ actualExpression: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
@objc public func doesNotMatch(_ actualExpression: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let actualBlock: () -> NMBDoubleConvertible? = ({
return actualExpression() as? NMBDoubleConvertible
})
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nimble/Matchers/MatcherProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ extension Matcher {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
/// Objective-C interface to the Swift variant of Matcher.
@objc public protocol NMBMatcher {
func matches(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool
func doesNotMatch(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool
func matches(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool
func doesNotMatch(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions Sources/Nimble/Matchers/Predicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,20 @@ public class NMBPredicate: NSObject {
self.predicate = predicate
}

func satisfies(_ expression: @escaping () -> NSObject!, location: SourceLocation) -> NMBPredicateResult {
func satisfies(_ expression: @escaping () -> NSObject?, location: SourceLocation) -> NMBPredicateResult {
let expr = Expression(expression: expression, location: location)
return self.predicate(expr)
}
}

extension NMBPredicate: NMBMatcher {
public func matches(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
public func matches(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let result = satisfies(actualBlock, location: location).toSwift()
result.message.update(failureMessage: failureMessage)
return result.status.toBoolean(expectation: .toMatch)
}

public func doesNotMatch(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
public func doesNotMatch(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let result = satisfies(actualBlock, location: location).toSwift()
result.message.update(failureMessage: failureMessage)
return result.status.toBoolean(expectation: .toNotMatch)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nimble/Matchers/RaisesException.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class NMBObjCRaiseExceptionMatcher: NSObject, NMBMatcher {
_block = block
}

@objc public func matches(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
@objc public func matches(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
let block: () -> Any? = ({ _ = actualBlock(); return nil })
let expr = Expression(expression: block, location: location)

Expand All @@ -141,7 +141,7 @@ public class NMBObjCRaiseExceptionMatcher: NSObject, NMBMatcher {
).matches(expr, failureMessage: failureMessage)
}

@objc public func doesNotMatch(_ actualBlock: @escaping () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
@objc public func doesNotMatch(_ actualBlock: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
return !matches(actualBlock, failureMessage: failureMessage, location: location)
}

Expand Down
12 changes: 3 additions & 9 deletions Sources/Nimble/Utils/Stringers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ extension Data: TestOutputStringConvertible {
/// will return the result of constructing a string from the value.
///
/// - SeeAlso: `TestOutputStringConvertible`
public func stringify<T>(_ value: T) -> String {
public func stringify<T>(_ value: T?) -> String {
guard let value = value else { return "nil" }

if let value = value as? TestOutputStringConvertible {
return value.testDescription
}
Expand All @@ -156,14 +158,6 @@ public func stringify<T>(_ value: T) -> String {
return String(describing: value)
}

/// -SeeAlso: `stringify<T>(value: T)`
public func stringify<T>(_ value: T?) -> String {
if let unboxed = value {
return stringify(unboxed)
}
return "nil"
}

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@objc public class NMBStringer: NSObject {
@objc public class func stringify(_ obj: Any?) -> String {
Expand Down
2 changes: 1 addition & 1 deletion Sources/NimbleObjectiveC/NMBExceptionCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ - (nonnull instancetype)initWithHandler:(void(^ _Nullable)(NSException * _Nonnul
return self;
}

- (void)tryBlock:(void(^ _Nonnull)(void))unsafeBlock {
- (void)tryBlock:(__attribute__((noescape)) void(^ _Nonnull)(void))unsafeBlock {
@try {
unsafeBlock();
}
Expand Down

0 comments on commit b7ea296

Please sign in to comment.