Skip to content

Commit 5a5b1af

Browse files
committed
[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.
1 parent e84be85 commit 5a5b1af

18 files changed

+268
-227
lines changed

test/SourceKit/Refactoring/basic.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ HasInitWithDefaultArgs(y: 45, z: 89)
116116
func `hasBackticks`(`x`: Int) {}
117117
`hasBackticks`(`x`:2)
118118

119-
func hasAsyncAlternative(completion: (String?, Error?) -> Void) { }
119+
func hasAsyncAlternative(completion: @escaping (String?, Error?) -> Void) { }
120120
func hasCallToAsyncAlternative() {
121121
hasAsyncAlternative { str, err in print(str!) }
122122
}

test/refactoring/ConvertAsync/async_attribute_added.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// REQUIRES: concurrency
2+
13
// RUN: %empty-directory(%t)
24

35
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -enable-experimental-concurrency | %FileCheck -check-prefix=SIMPLE %s

test/refactoring/ConvertAsync/basic.swift

Lines changed: 63 additions & 64 deletions
Large diffs are not rendered by default.

test/refactoring/ConvertAsync/convert_async_renames.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
// REQUIRES: concurrency
2+
13
// RUN: %empty-directory(%t)
24

3-
func simple(_ completion: (String) -> Void) { }
5+
func simple(_ completion: @escaping (String) -> Void) { }
46
func simple() async -> String { }
57

6-
func simpleArg(arg: String, _ completion: (String) -> Void) { }
8+
func simpleArg(arg: String, _ completion: @escaping (String) -> Void) { }
79
func simpleArg(arg: String) async -> String { }
810

9-
func simpleErr(arg: String, _ completion: (String?, Error?) -> Void) { }
11+
func simpleErr(arg: String, _ completion: @escaping (String?, Error?) -> Void) { }
1012
func simpleErr(arg: String) async throws -> String { }
1113

1214
func whatever() -> Bool { return true }

test/refactoring/ConvertAsync/convert_async_wrapper.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// REQUIRES: concurrency
2+
13
// RUN: %empty-directory(%t)
24

35
enum CustomError : Error {

test/refactoring/ConvertAsync/convert_bool.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import Foundation
1414
import ConvertBoolObjC
1515

16-
func boolWithErr(completion: (Bool, Error?) -> Void) {}
17-
func multipleBoolWithErr(completion: (String?, Bool, Bool, Error?) -> Void) {}
18-
func optionalBoolWithErr(completion: (String?, Bool?, Bool, Error?) -> Void) {}
16+
func boolWithErr(completion: @escaping (Bool, Error?) -> Void) {}
17+
func multipleBoolWithErr(completion: @escaping (String?, Bool, Bool, Error?) -> Void) {}
18+
func optionalBoolWithErr(completion: @escaping (String?, Bool?, Bool, Error?) -> Void) {}
1919

2020
// All 7 of the below should generate the same refactoring.
2121

@@ -191,7 +191,7 @@ boolWithErr { success, err in
191191
}
192192
}
193193
if !success {
194-
for x: Int in [] {
194+
for _: Int in [] {
195195
fatalError("oh no \(err!)")
196196
}
197197
}
@@ -218,7 +218,7 @@ boolWithErr { success, err in
218218
// BOOL-DONT-HANDLE2-NEXT: }
219219
// BOOL-DONT-HANDLE2-NEXT: }
220220
// BOOL-DONT-HANDLE2-NEXT: if !success {
221-
// BOOL-DONT-HANDLE2-NEXT: for x: Int in [] {
221+
// BOOL-DONT-HANDLE2-NEXT: for _: Int in [] {
222222
// BOOL-DONT-HANDLE2-NEXT: fatalError("oh no \(<#err#>!)")
223223
// BOOL-DONT-HANDLE2-NEXT: }
224224
// BOOL-DONT-HANDLE2-NEXT: }
@@ -227,7 +227,7 @@ boolWithErr { success, err in
227227
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -sdk %clang-importer-sdk-path | %FileCheck -check-prefix=BOOL-DONT-HANDLE3 %s
228228
boolWithErr { success, err in
229229
if !success {
230-
fatalError("oh no maybe \(err)")
230+
fatalError("oh no maybe \(String(describing: err))")
231231
}
232232
print("not err")
233233
}
@@ -236,7 +236,7 @@ boolWithErr { success, err in
236236

237237
// BOOL-DONT-HANDLE3: let success = try await boolWithErr()
238238
// BOOL-DONT-HANDLE3-NEXT: if !success {
239-
// BOOL-DONT-HANDLE3-NEXT: fatalError("oh no maybe \(<#err#>)")
239+
// BOOL-DONT-HANDLE3-NEXT: fatalError("oh no maybe \(String(describing: <#err#>))")
240240
// BOOL-DONT-HANDLE3-NEXT: }
241241
// BOOL-DONT-HANDLE3-NEXT: print("not err")
242242

@@ -348,7 +348,7 @@ optionalBoolWithErr { str, optBool, b, err in
348348
print("d \(err!)")
349349
}
350350
if optBool == false {
351-
print("e \(err)")
351+
print("e \(String(describing: err))")
352352
}
353353
if optBool != true {
354354
print("f \(err!)")
@@ -366,7 +366,7 @@ optionalBoolWithErr { str, optBool, b, err in
366366
// OPT-BOOL-WITH-ERR-NEXT: let (str, optBool, b) = try await optionalBoolWithErr()
367367
// OPT-BOOL-WITH-ERR-NEXT: print("a \(<#err#>!)")
368368
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> == false {
369-
// OPT-BOOL-WITH-ERR-NEXT: print("e \(<#err#>)")
369+
// OPT-BOOL-WITH-ERR-NEXT: print("e \(String(describing: <#err#>))")
370370
// OPT-BOOL-WITH-ERR-NEXT: }
371371
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> != true {
372372
// OPT-BOOL-WITH-ERR-NEXT: print("f \(<#err#>!)")
@@ -432,7 +432,7 @@ ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err
432432
if failure && err != nil {
433433
print("neat")
434434
}
435-
if failure, let err = err {
435+
if failure, let _ = err {
436436
print("neato")
437437
}
438438
}

test/refactoring/ConvertAsync/convert_function.swift

Lines changed: 43 additions & 41 deletions
Large diffs are not rendered by default.

test/refactoring/ConvertAsync/convert_invalid.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
func callbackIntWithError(_ completion: (Int8, Error?) -> Void) {}
1+
// REQUIRES: concurrency
2+
3+
// RUN: %empty-directory(%t)
4+
5+
func callbackIntWithError(_ completion: @escaping (Bool, Error?) -> Void) {}
26

37
// rdar://79864182
48
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=INVALID-COND %s
@@ -12,11 +16,10 @@ callbackIntWithError { x, err in
1216
// INVALID-COND-NEXT: print("ok")
1317
// INVALID-COND-NEXT: }
1418

15-
1619
func withoutAsyncAlternative(closure: (Int) -> Void) {}
1720

1821
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=UNKNOWN-ERROR-IN-CONTINUATION %s
19-
func testUnknownErrorInContinuation(completionHandler: (Int?, Error?) -> Void) {
22+
func testUnknownErrorInContinuation(completionHandler: @escaping (Int?, Error?) -> Void) {
2023
withoutAsyncAlternative { theValue in
2124
completionHandler(theValue, MyUndefinedError())
2225
}

test/refactoring/ConvertAsync/convert_params_multi.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
func manyWithError(_ completion: (String?, Int?, Error?) -> Void) { }
2-
func mixed(_ completion: (String?, Int) -> Void) { }
3-
func mixedError(_ completion: (String?, Int, Error?) -> Void) { }
1+
// REQUIRES: concurrency
2+
3+
func manyWithError(_ completion: @escaping (String?, Int?, Error?) -> Void) { }
4+
func mixed(_ completion: @escaping (String?, Int) -> Void) { }
5+
func mixedError(_ completion: @escaping (String?, Int, Error?) -> Void) { }
46

57
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=MANYBOUND %s
68
manyWithError { res1, res2, err in

test/refactoring/ConvertAsync/convert_params_single.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
func withError(_ completion: (String?, Error?) -> Void) { }
2-
func notOptional(_ completion: (String, Error?) -> Void) { }
3-
func errorOnly(_ completion: (Error?) -> Void) { }
1+
// REQUIRES: concurrency
2+
3+
func withError(_ completion: @escaping (String?, Error?) -> Void) { }
4+
func notOptional(_ completion: @escaping (String, Error?) -> Void) { }
5+
func errorOnly(_ completion: @escaping (Error?) -> Void) { }
46
func test(_ str: String) -> Bool { return false }
57

68
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3 | %FileCheck -check-prefix=UNRELATED %s

0 commit comments

Comments
 (0)