Skip to content

Migrating to Swift 3 #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Sources/XCTest/XCTAssert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private enum _XCTAssertion {
private enum _XCTAssertionResult {
case Success
case ExpectedFailure(String?)
case UnexpectedFailure(ErrorType)
case UnexpectedFailure(ErrorProtocol)

var expected: Bool {
switch (self) {
Expand Down Expand Up @@ -155,7 +155,7 @@ private func _XCTEvaluateAssertion(assertion: _XCTAssertion, @autoclosure messag
///
/// Now calling failures in `AssertEmpty` will be reported in the file and on
/// the line that the assert function is *called*, not where it is defined.
public func XCTAssert(@autoclosure expression: () throws -> BooleanType, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
public func XCTAssert(@autoclosure expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
XCTAssertTrue(expression, message, file: file, line: line)
}

Expand Down Expand Up @@ -214,18 +214,18 @@ public func XCTAssertEqual<T, U: Equatable>(@autoclosure expression1: () throws
}
}

public func XCTAssertEqualWithAccuracy<T: FloatingPointType>(@autoclosure expression1: () throws -> T, @autoclosure _ expression2: () throws -> T, accuracy: T, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
public func XCTAssertEqualWithAccuracy<T: FloatingPoint>(@autoclosure expression1: () throws -> T, @autoclosure _ expression2: () throws -> T, accuracy: T, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
_XCTEvaluateAssertion(.EqualWithAccuracy, message: message, file: file, line: line) {
let (value1, value2) = (try expression1(), try expression2())
if abs(value1.distanceTo(value2)) <= abs(accuracy.distanceTo(T(0))) {
if abs(value1.distance(to: value2)) <= abs(accuracy.distance(to: T(0))) {
return .Success
} else {
return .ExpectedFailure("(\"\(value1)\") is not equal to (\"\(value2)\") +/- (\"\(accuracy)\")")
}
}
}

public func XCTAssertFalse(@autoclosure expression: () throws -> BooleanType, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
public func XCTAssertFalse(@autoclosure expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
_XCTEvaluateAssertion(.False, message: message, file: file, line: line) {
let value = try expression()
if !value.boolValue {
Expand Down Expand Up @@ -346,10 +346,10 @@ public func XCTAssertNotEqual<T, U: Equatable>(@autoclosure expression1: () thro
}
}

public func XCTAssertNotEqualWithAccuracy<T: FloatingPointType>(@autoclosure expression1: () throws -> T, @autoclosure _ expression2: () throws -> T, _ accuracy: T, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
public func XCTAssertNotEqualWithAccuracy<T: FloatingPoint>(@autoclosure expression1: () throws -> T, @autoclosure _ expression2: () throws -> T, _ accuracy: T, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
_XCTEvaluateAssertion(.NotEqualWithAccuracy, message: message, file: file, line: line) {
let (value1, value2) = (try expression1(), try expression2())
if abs(value1.distanceTo(value2)) > abs(accuracy.distanceTo(T(0))) {
if abs(value1.distance(to: value2)) > abs(accuracy.distance(to: T(0))) {
return .Success
} else {
return .ExpectedFailure("(\"\(value1)\") is equal to (\"\(value2)\") +/- (\"\(accuracy)\")")
Expand All @@ -368,7 +368,7 @@ public func XCTAssertNotNil(@autoclosure expression: () throws -> Any?, @autoclo
}
}

public func XCTAssertTrue(@autoclosure expression: () throws -> BooleanType, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
public func XCTAssertTrue(@autoclosure expression: () throws -> Boolean, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
_XCTEvaluateAssertion(.True, message: message, file: file, line: line) {
let value = try expression()
if value.boolValue {
Expand All @@ -385,9 +385,9 @@ public func XCTFail(message: String = "", file: StaticString = #file, line: UInt
}
}

public func XCTAssertThrowsError<T>(@autoclosure expression: () throws -> T, _ message: String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (error: ErrorType) -> Void = { _ in }) {
public func XCTAssertThrowsError<T>(@autoclosure expression: () throws -> T, _ message: String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (error: ErrorProtocol) -> Void = { _ in }) {
_XCTEvaluateAssertion(.ThrowsError, message: message, file: file, line: line) {
var caughtErrorOptional: ErrorType?
var caughtErrorOptional: ErrorProtocol?
do {
_ = try expression()
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTest/XCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ extension XCTestCase {
if unfulfilledDescriptions.count > 0 {
// Not all expectations were fulfilled. Append a failure
// to the array of expectation-based failures.
let descriptions = unfulfilledDescriptions.joinWithSeparator(", ")
let descriptions = unfulfilledDescriptions.joined(separator: ", ")
let failure = XCTFailure(
message: "Exceeded timeout of \(timeout) seconds, with unfulfilled expectations: \(descriptions)",
failureDescription: "Asynchronous wait failed",
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTest/XCTimeUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private func currentTimeIntervalSinceReferenceTime() -> TimeInterval {
var tv = timeval()
let currentTime = withUnsafeMutablePointer(&tv, { (t: UnsafeMutablePointer<timeval>) -> TimeInterval in
gettimeofday(t, nil)
return TimeInterval(t.memory.tv_sec) + TimeInterval(t.memory.tv_usec) / 1000000.0
return TimeInterval(t.pointee.tv_sec) + TimeInterval(t.pointee.tv_usec) / 1000000.0
})
return currentTime
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/ErrorHandling/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ErrorHandling: XCTestCase {
func functionThatDoesNotThrowError() throws {
}

enum SomeError: ErrorType {
enum SomeError: ErrorProtocol {
case AnError(String)
}

Expand Down
1 change: 1 addition & 0 deletions XCTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
5B5D86D21BBC74AD00234F36 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0730;
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
ORGANIZATIONNAME = Apple;
Expand Down