Skip to content

[StdLibUnitTest] Remove overloads that were needed pre-conditional conformance #19265

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
Sep 12, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ self.test("\(testNamePrefix)._preprocessingPass/semantics") {
return OpaqueValue(42)
}
if wasInvoked {
expectOptionalEqual(42, result?.value)
expectEqual(42, result?.value)
} else {
expectNil(result)
}
Expand All @@ -1999,7 +1999,7 @@ self.test("\(testNamePrefix)._preprocessingPass/semantics") {
}
expectNil(result)
if wasInvoked {
expectOptionalEqual(TestError.error2, caughtError as? TestError)
expectEqual(TestError.error2, caughtError as? TestError)
}
}
}
Expand Down
153 changes: 0 additions & 153 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,6 @@ public func expectNotEqual<T : Equatable>(_ expected: T, _ actual: T,
}
}

// Cannot write a sane set of overloads using generics because of:
// <rdar://problem/17015923> Array -> NSArray implicit conversion insanity
public func expectOptionalEqual<T : Equatable>(
_ expected: T, _ actual: T?,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line
) {
expectOptionalEqual(expected, actual, message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line), showFrame: false) {$0 == $1}
}

public func expectOptionalEqual<T>(
_ expected: T, _ actual: T?,
_ message: @autoclosure () -> String = "",
Expand All @@ -323,146 +310,6 @@ public func expectOptionalEqual<T>(
}
}

public func expectEqual<T : Equatable>(_ expected: T?, _ actual: T?,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line) {
if expected != actual {
expectationFailure(
"expected: \"\(expected.debugDescription)\" (of type \(String(reflecting: type(of: expected))))\n"
+ "actual: \"\(actual.debugDescription)\" (of type \(String(reflecting: type(of: actual))))",
trace: message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
}
}

public func expectNotEqual<T : Equatable>(
_ expected: T?, _ actual: T?,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line
) {
if expected == actual {
expectationFailure(
"unexpected value: \"\(actual.debugDescription)\" (of type \(String(reflecting: type(of: actual))))",
trace: message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
}
}

// Array<T> is not Equatable if T is. Provide additional overloads.
// Same for Dictionary.

public func expectEqual<T : Equatable>(
_ expected: ContiguousArray<T>, _ actual: ContiguousArray<T>,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line
) {
expectEqualTest(expected, actual, message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line), showFrame: false) { $0 == $1 }
}

public func expectOptionalEqual<T : Equatable>(
_ expected: ContiguousArray<T>, _ actual: ContiguousArray<T>?,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line) {
if (actual == nil) || expected != actual! {
expectationFailure(
"expected: \"\(expected)\" (of type \(String(reflecting: type(of: expected))))"
+ "actual: \"\(actual.debugDescription)\" (of type \(String(reflecting: type(of: actual))))",
trace: message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
}
}


public func expectEqual<T : Equatable>(
_ expected: ArraySlice<T>, _ actual: ArraySlice<T>,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line
) {
expectEqualTest(expected, actual, message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line), showFrame: false) { $0 == $1 }
}

public func expectOptionalEqual<T : Equatable>(
_ expected: ArraySlice<T>, _ actual: ArraySlice<T>?,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line) {
if (actual == nil) || expected != actual! {
expectationFailure(
"expected: \"\(expected)\" (of type \(String(reflecting: type(of: expected))))"
+ "actual: \"\(actual.debugDescription)\" (of type \(String(reflecting: type(of: actual))))",
trace: message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
}
}


public func expectEqual<T : Equatable>(
_ expected: Array<T>, _ actual: Array<T>,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line
) {
expectEqualTest(expected, actual, message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line), showFrame: false) { $0 == $1 }
}

public func expectOptionalEqual<T : Equatable>(
_ expected: Array<T>, _ actual: Array<T>?,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line) {
if (actual == nil) || expected != actual! {
expectationFailure(
"expected: \"\(expected)\" (of type \(String(reflecting: type(of: expected))))"
+ "actual: \"\(actual.debugDescription)\" (of type \(String(reflecting: type(of: actual))))",
trace: message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
}
}


public func expectEqual<T, U : Equatable>(
_ expected: Dictionary<T, U>, _ actual: Dictionary<T, U>,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line
) {
expectEqualTest(expected, actual, message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line), showFrame: false) { $0 == $1 }
}

public func expectOptionalEqual<T, U : Equatable>(
_ expected: Dictionary<T, U>, _ actual: Dictionary<T, U>?,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
file: String = #file, line: UInt = #line) {
if (actual == nil) || expected != actual! {
expectationFailure(
"expected: \"\(expected)\" (of type \(String(reflecting: type(of: expected))))"
+ "actual: \"\(actual.debugDescription)\" (of type \(String(reflecting: type(of: actual))))",
trace: message(),
stackTrace: stackTrace.pushIf(showFrame, file: file, line: line))
}
}


public func expectEqual(
_ expected: Any.Type, _ actual: Any.Type,
_ message: @autoclosure () -> String = "",
Expand Down
49 changes: 22 additions & 27 deletions test/stdlib/ErrorBridged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ErrorBridgingTests.test("NSError-to-enum bridging") {
let testURL = URL(string: "https://swift.org")!

autoreleasepool {
let underlyingError = CocoaError(.fileLockingError)
let underlyingError = CocoaError(.fileLocking)
as Error as NSError
let ns = NSError(domain: NSCocoaErrorDomain,
code: NSFileNoSuchFileError,
Expand All @@ -116,7 +116,7 @@ ErrorBridgingTests.test("NSError-to-enum bridging") {
case let x as CocoaError:
cocoaCode = x._code
expectTrue(x.isFileError)
expectEqual(x.code, CocoaError.fileNoSuchFileError)
expectEqual(x.code, .fileNoSuchFile)
default:
cocoaCode = nil
}
Expand All @@ -128,7 +128,7 @@ ErrorBridgingTests.test("NSError-to-enum bridging") {

let isNoSuchFileError: Bool
switch e {
case CocoaError.fileNoSuchFileError:
case CocoaError.fileNoSuchFile:
isNoSuchFileError = true
default:
isNoSuchFileError = false
Expand All @@ -138,10 +138,10 @@ ErrorBridgingTests.test("NSError-to-enum bridging") {

// Check the contents of the error.
let cocoaError = e as! CocoaError
expectOptionalEqual("/dev/null", cocoaError.filePath)
expectOptionalEqual(String.Encoding.ascii, cocoaError.stringEncoding)
expectOptionalEqual(underlyingError, cocoaError.underlying.map { $0 as NSError })
expectOptionalEqual(testURL, cocoaError.url)
expectEqual("/dev/null", cocoaError.filePath)
expectEqual(String.Encoding.ascii, cocoaError.stringEncoding)
expectEqual(underlyingError, cocoaError.underlying.map { $0 as NSError })
expectEqual(testURL, cocoaError.url)

// URLError domain
let nsURL = NSError(domain: NSURLErrorDomain,
Expand All @@ -159,7 +159,7 @@ ErrorBridgingTests.test("NSError-to-enum bridging") {
expectTrue(isBadURLError)

let urlError = eURL as! URLError
expectOptionalEqual(testURL, urlError.failingURL)
expectEqual(testURL, urlError.failingURL)
expectNil(urlError.failureURLPeerTrust)

// CoreLocation error domain
Expand All @@ -179,8 +179,8 @@ ErrorBridgingTests.test("NSError-to-enum bridging") {
switch eCL {
case let error as CLError:
isCLError = true
expectOptionalEqual(testURL, (error as NSError).userInfo[NSURLErrorKey as NSObject] as? URL)
expectOptionalEqual(testURL, error.userInfo[NSURLErrorKey] as? URL)
expectEqual(testURL, (error as NSError).userInfo[NSURLErrorKey as NSObject] as? URL)
expectEqual(testURL, error.userInfo[NSURLErrorKey] as? URL)
default:
isCLError = false
}
Expand Down Expand Up @@ -485,13 +485,13 @@ func testCustomizedError(error: Error, nsError: NSError) {
expectNil(nsError.userInfo[NSLocalizedRecoverySuggestionErrorKey as NSObject])
expectNil(nsError.userInfo[NSHelpAnchorErrorKey as NSObject])
} else {
expectOptionalEqual("something went horribly wrong",
expectEqual("something went horribly wrong",
nsError.userInfo[NSLocalizedDescriptionKey as NSObject] as? String)
expectOptionalEqual("because someone wrote 'throw'",
expectEqual("because someone wrote 'throw'",
nsError.userInfo[NSLocalizedFailureReasonErrorKey as NSObject] as? String)
expectOptionalEqual("delete the 'throw'",
expectEqual("delete the 'throw'",
nsError.userInfo[NSLocalizedRecoverySuggestionErrorKey as NSObject] as? String)
expectOptionalEqual("there is no help when writing tests",
expectEqual("there is no help when writing tests",
nsError.userInfo[NSHelpAnchorErrorKey as NSObject] as? String)
}
expectEqual("something went horribly wrong", error.localizedDescription)
Expand All @@ -504,10 +504,10 @@ func testCustomizedError(error: Error, nsError: NSError) {
if #available(OSX 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *) {
expectNil(nsError.userInfo[NSLocalizedRecoveryOptionsErrorKey as NSObject])
} else {
expectOptionalEqual(["Delete 'throw'", "Disable the test" ],
expectEqual(["Delete 'throw'", "Disable the test" ],
nsError.userInfo[NSLocalizedRecoveryOptionsErrorKey as NSObject] as? [String])
}
expectOptionalEqual(["Delete 'throw'", "Disable the test" ],
expectEqual(["Delete 'throw'", "Disable the test" ],
nsError.localizedRecoveryOptions)

// Directly recover.
Expand All @@ -519,12 +519,8 @@ func testCustomizedError(error: Error, nsError: NSError) {
} else {
attempter = nsError.userInfo[NSRecoveryAttempterErrorKey as NSObject]! as AnyObject
}
expectOptionalEqual(attempter.attemptRecovery(fromError: nsError,
optionIndex: 0),
true)
expectOptionalEqual(attempter.attemptRecovery(fromError: nsError,
optionIndex: 1),
false)
expectEqual(attempter.attemptRecovery(fromError: nsError, optionIndex: 0), true)
expectEqual(attempter.attemptRecovery(fromError: nsError, optionIndex: 1), false)

// Recover through delegate.
let rd1 = RecoveryDelegate(expectedSuccess: true, expectedContextInfo: ctx)
Expand Down Expand Up @@ -555,7 +551,7 @@ ErrorBridgingTests.test("Customizing NSError via protocols") {
// CustomNSError
expectEqual("custom", nsError.domain)
expectEqual(12345, nsError.code)
expectOptionalEqual(URL(string: "https://swift.org")!,
expectEqual(URL(string: "https://swift.org"),
nsError.userInfo[NSURLErrorKey as NSObject] as? URL)

testCustomizedError(error: error, nsError: nsError)
Expand All @@ -576,11 +572,10 @@ ErrorBridgingTests.test("Customizing localization/recovery laziness") {
if #available(OSX 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *) {
expectNil(nsError.userInfo[NSLocalizedRecoveryOptionsErrorKey as NSObject])
} else {
expectOptionalEqual(["Delete 'throw'", "Disable the test" ],
expectEqual(["Delete 'throw'", "Disable the test" ],
nsError.userInfo[NSLocalizedRecoveryOptionsErrorKey as NSObject] as? [String])
}
expectOptionalEqual(["Delete 'throw'", "Disable the test" ],
nsError.localizedRecoveryOptions)
expectEqual(["Delete 'throw'", "Disable the test" ], nsError.localizedRecoveryOptions)

// None of the operations above should affect the count
if #available(OSX 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *) {
Expand Down Expand Up @@ -676,7 +671,7 @@ ErrorBridgingTests.test("Wrapped NSError identity") {
let nsError5: NSError = cocoaError as NSError
expectTrue(nsError === nsError5)

if let cocoaError2 = error as? CocoaError {
if error is CocoaError {
let nsError6: NSError = cocoaError as NSError
expectTrue(nsError === nsError6)
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/stdlib/ImplicitlyUnwrappedOptional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ ImplicitlyUnwrappedOptionalTests.test("flatMap") {
// let half: Int32 -> Int16! =
// { if $0 % 2 == 0 { return Int16($0 / 2) } else { return .none } }

// expectOptionalEqual(2 as Int16, half(4))
// expectEqual(2 as Int16, half(4))
// expectNil(half(3))

// expectNil((.none as Int!).flatMap(half))
// expectOptionalEqual(2 as Int16, (4 as Int!).flatMap(half))
// expectEqual(2 as Int16, (4 as Int!).flatMap(half))
// expectNil((3 as Int!).flatMap(half))
}

Expand Down
Loading