From 993c92d9cf6d90ae2e0dc1d06b0118b94df8de7a Mon Sep 17 00:00:00 2001 From: freak4pc Date: Sat, 1 Jun 2019 14:33:41 +0300 Subject: [PATCH] Resolve deprecation warnings --- Sources/Nimble/Expectation.swift | 4 ++++ Sources/Nimble/Matchers/AllPass.swift | 1 + Sources/Nimble/Matchers/Async.swift | 3 +++ Sources/Nimble/Matchers/BeCloseTo.swift | 2 ++ Sources/Nimble/Matchers/MatcherProtocols.swift | 1 + Sources/Nimble/Matchers/PostNotification.swift | 1 + Sources/Nimble/Matchers/Predicate.swift | 2 ++ Sources/Nimble/Matchers/SatisfyAllOf.swift | 2 ++ Sources/Nimble/Matchers/SatisfyAnyOf.swift | 8 ++++++-- 9 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Sources/Nimble/Expectation.swift b/Sources/Nimble/Expectation.swift index 41625a123..3afe1fc03 100644 --- a/Sources/Nimble/Expectation.swift +++ b/Sources/Nimble/Expectation.swift @@ -1,6 +1,7 @@ import Foundation // Deprecated +@available(*, deprecated) internal func expressionDoesNotMatch(_ expression: Expression, matcher: U, toNot: String, description: String?) -> (Bool, FailureMessage) where U: Matcher, U.ValueType == T { let msg = FailureMessage() @@ -69,6 +70,7 @@ public struct Expectation { ////////////////// OLD API ///////////////////// /// DEPRECATED: Tests the actual value using a matcher to match. + @available(*, deprecated) public func to(_ matcher: U, description: String? = nil) where U: Matcher, U.ValueType == T { let (pass, msg) = execute( @@ -83,6 +85,7 @@ public struct Expectation { } /// DEPRECATED: Tests the actual value using a matcher to not match. + @available(*, deprecated) public func toNot(_ matcher: U, description: String? = nil) where U: Matcher, U.ValueType == T { // swiftlint:disable:next line_length @@ -93,6 +96,7 @@ public struct Expectation { /// DEPRECATED: Tests the actual value using a matcher to not match. /// /// Alias to toNot(). + @available(*, deprecated) public func notTo(_ matcher: U, description: String? = nil) where U: Matcher, U.ValueType == T { toNot(matcher, description: description) diff --git a/Sources/Nimble/Matchers/AllPass.swift b/Sources/Nimble/Matchers/AllPass.swift index dbbccb9c5..c2ede4048 100644 --- a/Sources/Nimble/Matchers/AllPass.swift +++ b/Sources/Nimble/Matchers/AllPass.swift @@ -18,6 +18,7 @@ public func allPass return createPredicate(matcher) } +@available(*, deprecated) public func allPass(_ elementMatcher: M) -> Predicate where S: Sequence, M: Matcher, S.Iterator.Element == M.ValueType { return createPredicate(elementMatcher.predicate) diff --git a/Sources/Nimble/Matchers/Async.swift b/Sources/Nimble/Matchers/Async.swift index 5022fe211..6ffb40c3b 100644 --- a/Sources/Nimble/Matchers/Async.swift +++ b/Sources/Nimble/Matchers/Async.swift @@ -116,6 +116,7 @@ extension Expectation { /// @discussion /// This function manages the main run loop (`NSRunLoop.mainRunLoop()`) while this function /// is executing. Any attempts to touch the run loop may cause non-deterministic behavior. + @available(*, deprecated) public func toEventually(_ matcher: U, timeout: TimeInterval = AsyncDefaults.Timeout, pollInterval: TimeInterval = AsyncDefaults.PollInterval, description: String? = nil) where U: Matcher, U.ValueType == T { if expression.isClosure { @@ -145,6 +146,7 @@ extension Expectation { /// @discussion /// This function manages the main run loop (`NSRunLoop.mainRunLoop()`) while this function /// is executing. Any attempts to touch the run loop may cause non-deterministic behavior. + @available(*, deprecated) public func toEventuallyNot(_ matcher: U, timeout: TimeInterval = AsyncDefaults.Timeout, pollInterval: TimeInterval = AsyncDefaults.PollInterval, description: String? = nil) where U: Matcher, U.ValueType == T { if expression.isClosure { @@ -174,6 +176,7 @@ extension Expectation { /// @discussion /// This function manages the main run loop (`NSRunLoop.mainRunLoop()`) while this function /// is executing. Any attempts to touch the run loop may cause non-deterministic behavior. + @available(*, deprecated) public func toNotEventually(_ matcher: U, timeout: TimeInterval = AsyncDefaults.Timeout, pollInterval: TimeInterval = AsyncDefaults.PollInterval, description: String? = nil) where U: Matcher, U.ValueType == T { return toEventuallyNot(matcher, timeout: timeout, pollInterval: pollInterval, description: description) diff --git a/Sources/Nimble/Matchers/BeCloseTo.swift b/Sources/Nimble/Matchers/BeCloseTo.swift index d6fd1eed6..a01147aa9 100644 --- a/Sources/Nimble/Matchers/BeCloseTo.swift +++ b/Sources/Nimble/Matchers/BeCloseTo.swift @@ -46,6 +46,7 @@ public class NMBObjCBeCloseToMatcher: NSObject, NMBMatcher { _delta = within } + @available(*, deprecated) @objc public func matches(_ actualExpression: @escaping () -> NSObject?, failureMessage: FailureMessage, location: SourceLocation) -> Bool { let actualBlock: () -> NMBDoubleConvertible? = ({ return actualExpression() as? NMBDoubleConvertible @@ -61,6 +62,7 @@ public class NMBObjCBeCloseToMatcher: NSObject, NMBMatcher { } } + @available(*, deprecated) @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 38bb29708..4ac710745 100644 --- a/Sources/Nimble/Matchers/MatcherProtocols.swift +++ b/Sources/Nimble/Matchers/MatcherProtocols.swift @@ -12,6 +12,7 @@ public protocol Matcher { func doesNotMatch(_ actualExpression: Expression, failureMessage: FailureMessage) throws -> Bool } +@available(*, deprecated, message: "Use Predicate instead") extension Matcher { var predicate: Predicate { return Predicate.fromDeprecatedMatcher(self) diff --git a/Sources/Nimble/Matchers/PostNotification.swift b/Sources/Nimble/Matchers/PostNotification.swift index edfd43127..f3bf52db1 100644 --- a/Sources/Nimble/Matchers/PostNotification.swift +++ b/Sources/Nimble/Matchers/PostNotification.swift @@ -27,6 +27,7 @@ internal class NotificationCollector { private let mainThread = pthread_self() +@available(*, deprecated) public func postNotifications( _ notificationsMatcher: T, fromNotificationCenter center: NotificationCenter = .default) diff --git a/Sources/Nimble/Matchers/Predicate.swift b/Sources/Nimble/Matchers/Predicate.swift index 2604411af..ae19df36b 100644 --- a/Sources/Nimble/Matchers/Predicate.swift +++ b/Sources/Nimble/Matchers/Predicate.swift @@ -167,6 +167,7 @@ public enum PredicateStatus { } // Backwards compatibility until Old Matcher API removal +@available(*, deprecated) extension Predicate: Matcher { /// Compatibility layer for old Matcher API, deprecated public static func fromDeprecatedFullClosure(_ matcher: @escaping (Expression, FailureMessage, Bool) throws -> Bool) -> Predicate { @@ -196,6 +197,7 @@ extension Predicate: Matcher { /// Compatibility layer for old Matcher API, deprecated. /// Same as calling .predicate on a MatcherFunc or NonNilMatcherFunc type. + @available(*, deprecated) public static func fromDeprecatedMatcher(_ matcher: M) -> Predicate where M: Matcher, M.ValueType == T { return self.fromDeprecatedFullClosure(matcher.toClosure) } diff --git a/Sources/Nimble/Matchers/SatisfyAllOf.swift b/Sources/Nimble/Matchers/SatisfyAllOf.swift index da3ea9aac..55594e2df 100644 --- a/Sources/Nimble/Matchers/SatisfyAllOf.swift +++ b/Sources/Nimble/Matchers/SatisfyAllOf.swift @@ -2,6 +2,7 @@ import Foundation /// A Nimble matcher that succeeds when the actual value matches with all of the matchers /// provided in the variable list of matchers. +@available(*, deprecated) public func satisfyAllOf(_ matchers: U...) -> Predicate where U: Matcher, U.ValueType == T { return satisfyAllOf(matchers.map { $0.predicate }) @@ -35,6 +36,7 @@ internal func satisfyAllOf(_ predicates: [Predicate]) -> Predicate { } } +@available(*, deprecated) public func && (left: Predicate, right: Predicate) -> Predicate { return satisfyAllOf(left, right) } diff --git a/Sources/Nimble/Matchers/SatisfyAnyOf.swift b/Sources/Nimble/Matchers/SatisfyAnyOf.swift index 672495643..46e4aead6 100644 --- a/Sources/Nimble/Matchers/SatisfyAnyOf.swift +++ b/Sources/Nimble/Matchers/SatisfyAnyOf.swift @@ -1,7 +1,8 @@ import Foundation /// A Nimble matcher that succeeds when the actual value matches with any of the matchers -/// provided in the variable list of matchers. +/// provided in the variable list of matchers. +@available(*, deprecated) public func satisfyAnyOf(_ matchers: U...) -> Predicate where U: Matcher, U.ValueType == T { return satisfyAnyOf(matchers.map { $0.predicate }) @@ -35,14 +36,17 @@ internal func satisfyAnyOf(_ predicates: [Predicate]) -> Predicate { } } +@available(*, deprecated) public func || (left: Predicate, right: Predicate) -> Predicate { - return satisfyAnyOf(left, right) + return satisfyAnyOf(left, right) } +@available(*, deprecated) public func || (left: NonNilMatcherFunc, right: NonNilMatcherFunc) -> Predicate { return satisfyAnyOf(left, right) } +@available(*, deprecated) public func || (left: MatcherFunc, right: MatcherFunc) -> Predicate { return satisfyAnyOf(left, right) }