From 382b5e1b46e14ae8e90e86a65ec5536b6b941a02 Mon Sep 17 00:00:00 2001 From: Adam Sharp Date: Mon, 4 Jun 2018 17:15:18 -0400 Subject: [PATCH 1/3] Add missing attribute causing compile error in Xcode 10 --- Sources/NimbleObjectiveC/NMBExceptionCapture.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/NimbleObjectiveC/NMBExceptionCapture.m b/Sources/NimbleObjectiveC/NMBExceptionCapture.m index 338104705..52684b709 100644 --- a/Sources/NimbleObjectiveC/NMBExceptionCapture.m +++ b/Sources/NimbleObjectiveC/NMBExceptionCapture.m @@ -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(); } From 7bc9370c9c0b07c4e43907d0ab6a1761a6fc42e0 Mon Sep 17 00:00:00 2001 From: Adam Sharp Date: Mon, 4 Jun 2018 17:17:47 -0400 Subject: [PATCH 2/3] Swift 4.2: Remove illegal use of IUO in return type position --- Sources/Nimble/Adapters/NMBExpectation.swift | 4 ++-- Sources/Nimble/Adapters/NMBObjCMatcher.swift | 4 ++-- Sources/Nimble/Matchers/BeCloseTo.swift | 4 ++-- Sources/Nimble/Matchers/MatcherProtocols.swift | 4 ++-- Sources/Nimble/Matchers/Predicate.swift | 6 +++--- Sources/Nimble/Matchers/RaisesException.swift | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Sources/Nimble/Adapters/NMBExpectation.swift b/Sources/Nimble/Adapters/NMBExpectation.swift index 88d94062d..5e1afd573 100644 --- a/Sources/Nimble/Adapters/NMBExpectation.swift +++ b/Sources/Nimble/Adapters/NMBExpectation.swift @@ -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 diff --git a/Sources/Nimble/Adapters/NMBObjCMatcher.swift b/Sources/Nimble/Adapters/NMBObjCMatcher.swift index 9ba2ffac6..0288b75ba 100644 --- a/Sources/Nimble/Adapters/NMBObjCMatcher.swift +++ b/Sources/Nimble/Adapters/NMBObjCMatcher.swift @@ -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, @@ -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, diff --git a/Sources/Nimble/Matchers/BeCloseTo.swift b/Sources/Nimble/Matchers/BeCloseTo.swift index dfb4e2853..34fa1b827 100644 --- a/Sources/Nimble/Matchers/BeCloseTo.swift +++ b/Sources/Nimble/Matchers/BeCloseTo.swift @@ -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 }) @@ -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 }) diff --git a/Sources/Nimble/Matchers/MatcherProtocols.swift b/Sources/Nimble/Matchers/MatcherProtocols.swift index 82f3cf036..6f8f103db 100644 --- a/Sources/Nimble/Matchers/MatcherProtocols.swift +++ b/Sources/Nimble/Matchers/MatcherProtocols.swift @@ -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 diff --git a/Sources/Nimble/Matchers/Predicate.swift b/Sources/Nimble/Matchers/Predicate.swift index d32b0e239..f8123443f 100644 --- a/Sources/Nimble/Matchers/Predicate.swift +++ b/Sources/Nimble/Matchers/Predicate.swift @@ -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) diff --git a/Sources/Nimble/Matchers/RaisesException.swift b/Sources/Nimble/Matchers/RaisesException.swift index 60553bda8..3e7f2dfc5 100644 --- a/Sources/Nimble/Matchers/RaisesException.swift +++ b/Sources/Nimble/Matchers/RaisesException.swift @@ -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) @@ -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) } From d447cae0ffaaf203f0f5c11f6b70556b2d7189af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Tue, 5 Jun 2018 15:41:59 +0200 Subject: [PATCH 3/3] Remove unnecessary non-optional stringify method --- Sources/Nimble/Utils/Stringers.swift | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Sources/Nimble/Utils/Stringers.swift b/Sources/Nimble/Utils/Stringers.swift index cd6de201d..7c4d273ec 100644 --- a/Sources/Nimble/Utils/Stringers.swift +++ b/Sources/Nimble/Utils/Stringers.swift @@ -144,7 +144,9 @@ extension Data: TestOutputStringConvertible { /// will return the result of constructing a string from the value. /// /// - SeeAlso: `TestOutputStringConvertible` -public func stringify(_ value: T) -> String { +public func stringify(_ value: T?) -> String { + guard let value = value else { return "nil" } + if let value = value as? TestOutputStringConvertible { return value.testDescription } @@ -156,14 +158,6 @@ public func stringify(_ value: T) -> String { return String(describing: value) } -/// -SeeAlso: `stringify(value: T)` -public func stringify(_ 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 {