Files
swift-mirror/test/refactoring/ConvertAsync/convert_invalid.swift
Ben Barham fabb02100f [Test] Add @escaping to async refactoring tests
The async refactorings ignore whether a completion handler had
`@escaping` or not. In preparation of fixing this, fix up all functions
to have `@escaping` for their completion handler parameter.

Also some small miscellaneous fixes in order to reduce the number of
warnings output on test failures and also the addition of `REQUIRES:
concurrency` on all tests.
2021-07-24 09:53:17 +10:00

34 lines
1.4 KiB
Swift

// REQUIRES: concurrency
// RUN: %empty-directory(%t)
func callbackIntWithError(_ completion: @escaping (Bool, Error?) -> Void) {}
// rdar://79864182
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=INVALID-COND %s
callbackIntWithError { x, err in
if x {
print("ok")
}
}
// INVALID-COND: let x = try await callbackIntWithError()
// INVALID-COND-NEXT: if x {
// INVALID-COND-NEXT: print("ok")
// INVALID-COND-NEXT: }
func withoutAsyncAlternative(closure: (Int) -> Void) {}
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=UNKNOWN-ERROR-IN-CONTINUATION %s
func testUnknownErrorInContinuation(completionHandler: @escaping (Int?, Error?) -> Void) {
withoutAsyncAlternative { theValue in
completionHandler(theValue, MyUndefinedError())
}
}
// UNKNOWN-ERROR-IN-CONTINUATION: func testUnknownErrorInContinuation() async throws -> Int {
// UNKNOWN-ERROR-IN-CONTINUATION-NEXT: return try await withCheckedThrowingContinuation { continuation in
// UNKNOWN-ERROR-IN-CONTINUATION-NEXT: withoutAsyncAlternative { theValue in
// UNKNOWN-ERROR-IN-CONTINUATION-NEXT: continuation.resume(throwing: MyUndefinedError())
// UNKNOWN-ERROR-IN-CONTINUATION-NEXT: }
// UNKNOWN-ERROR-IN-CONTINUATION-NEXT: }
// UNKNOWN-ERROR-IN-CONTINUATION-NEXT: }