From 23d627d712a33ab550a86dec7996ac1ccaf51df5 Mon Sep 17 00:00:00 2001 From: Alex Tran Qui Date: Mon, 4 Apr 2016 14:56:59 +0200 Subject: [PATCH] Added support for swift 3.0 (DEVELOPMENT-SNAPSHOT-2016-03-24-a) on OSX. --- src/CatchingFire.swift | 24 ++++++++++++++---------- test/CatchingFireTests.swift | 2 +- test/ExampleTests.swift | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/CatchingFire.swift b/src/CatchingFire.swift index 0ced4f1..e9f7498 100644 --- a/src/CatchingFire.swift +++ b/src/CatchingFire.swift @@ -8,6 +8,10 @@ import XCTest +#if !swift(>=3.0) + typealias ErrorProtocol = ErrorType +#endif + /// This allows you to write safe tests for the happy path of failable functions. /// It helps you to avoid the `try!` operator in tests. @@ -77,11 +81,11 @@ public func AssertNoThrow(@noescape closure: () throws -> ()) { /// /// If the expression or closure doesn't throw the expected error, your test fails. /// -public func AssertThrows(expectedError: E, @autoclosure _ closure: () throws -> R) -> () { +public func AssertThrows(expectedError: E, @autoclosure(escaping) _ closure: () throws -> R) -> () { AssertThrows(expectedError) { try closure() } } -public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { +public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { do { try closure() XCTFail("Expected to catch <\(expectedError)>, " @@ -95,11 +99,11 @@ public func AssertThrows(expectedError: E, @noescape _ clo } } -public func AssertThrows(expectedError: E, @autoclosure _ closure: () throws -> R) -> () { +public func AssertThrows(expectedError: E, @autoclosure(escaping) _ closure: () throws -> R) -> () { AssertThrows(expectedError) { try closure() } } -public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { +public func AssertThrows(expectedError: E, @noescape _ closure: () throws -> ()) -> () { do { try closure() XCTFail("Expected to catch <\(expectedError)>, " @@ -115,8 +119,8 @@ public func AssertThrows(expectedError: E, @ } } -/// Implement pattern matching for ErrorTypes -internal func ~=(lhs: ErrorType, rhs: ErrorType) -> Bool { +/// Implement pattern matching for ErrorProtocol +internal func ~=(lhs: ErrorProtocol, rhs: ErrorProtocol) -> Bool { return lhs._domain == rhs._domain && rhs._code == rhs._code } @@ -124,14 +128,14 @@ internal func ~=(lhs: ErrorType, rhs: ErrorType) -> Bool { /// Helper struct to catch errors thrown by others, which aren't publicly exposed. /// /// Note: -/// Don't use this when a given ErrorType implementation exists. +/// Don't use this when a given ErrorProtocol implementation exists. /// If you want to use that to test errors thrown in your own framework, you should /// consider to adopt an enumeration-based approach first in the framework code itself and expose /// them instead as part of the public API. Even if you have some internal error cases, you can //// put them in a separate enum and import your framework as `@testable` in your tests without /// affecting the public API, if that matters. /// -public struct Error : ErrorType { +public struct Error : ErrorProtocol { public let domain: String public let code: Int @@ -152,8 +156,8 @@ public func ==(lhs: Error, rhs: Error) -> Bool { && lhs._code == rhs._code } -/// Implement pattern matching for Error & ErrorType -public func ~=(lhs: Error, rhs: ErrorType) -> Bool { +/// Implement pattern matching for Error & ErrorProtocol +public func ~=(lhs: Error, rhs: ErrorProtocol) -> Bool { return lhs._domain == rhs._domain && rhs._code == rhs._code } diff --git a/test/CatchingFireTests.swift b/test/CatchingFireTests.swift index d22b9e5..c13bd2f 100644 --- a/test/CatchingFireTests.swift +++ b/test/CatchingFireTests.swift @@ -9,7 +9,7 @@ import XCTest import CatchingFire -enum Error : ErrorType { +enum Error : ErrorProtocol { case MayNotBeZero } diff --git a/test/ExampleTests.swift b/test/ExampleTests.swift index b20bfda..afda4f1 100644 --- a/test/ExampleTests.swift +++ b/test/ExampleTests.swift @@ -10,7 +10,7 @@ import XCTest import CatchingFire -enum BombError: ErrorType { +enum BombError: ErrorProtocol { case WrongWire case TimeElapsed }