Skip to content

Commit b6af50d

Browse files
authored
Merge pull request #38614 from apple/add-escaping-to-async-tests
[Test] Add @escaping to async refactoring tests
2 parents 00349ef + fabb021 commit b6af50d

19 files changed

+271
-228
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/check_compiles.swift

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

3-
func simple(completion: () -> Void) { }
5+
func simple(completion: @escaping () -> Void) { }
46
func anything() -> Bool { return true }
57

68
// RUN: %swift-frontend -typecheck %s

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
@@ -7,9 +7,9 @@
77
import Foundation
88
import ConvertBoolObjC
99

10-
func boolWithErr(completion: (Bool, Error?) -> Void) {}
11-
func multipleBoolWithErr(completion: (String?, Bool, Bool, Error?) -> Void) {}
12-
func optionalBoolWithErr(completion: (String?, Bool?, Bool, Error?) -> Void) {}
10+
func boolWithErr(completion: @escaping (Bool, Error?) -> Void) {}
11+
func multipleBoolWithErr(completion: @escaping (String?, Bool, Bool, Error?) -> Void) {}
12+
func optionalBoolWithErr(completion: @escaping (String?, Bool?, Bool, Error?) -> Void) {}
1313

1414
// All 7 of the below should generate the same refactoring.
1515

@@ -185,7 +185,7 @@ boolWithErr { success, err in
185185
}
186186
}
187187
if !success {
188-
for x: Int in [] {
188+
for _: Int in [] {
189189
fatalError("oh no \(err!)")
190190
}
191191
}
@@ -212,7 +212,7 @@ boolWithErr { success, err in
212212
// BOOL-DONT-HANDLE2-NEXT: }
213213
// BOOL-DONT-HANDLE2-NEXT: }
214214
// BOOL-DONT-HANDLE2-NEXT: if !success {
215-
// BOOL-DONT-HANDLE2-NEXT: for x: Int in [] {
215+
// BOOL-DONT-HANDLE2-NEXT: for _: Int in [] {
216216
// BOOL-DONT-HANDLE2-NEXT: fatalError("oh no \(<#err#>!)")
217217
// BOOL-DONT-HANDLE2-NEXT: }
218218
// BOOL-DONT-HANDLE2-NEXT: }
@@ -221,7 +221,7 @@ boolWithErr { success, err in
221221
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -I %S/Inputs -I %t %clang-importer-sdk-nosource | %FileCheck -check-prefix=BOOL-DONT-HANDLE3 %s
222222
boolWithErr { success, err in
223223
if !success {
224-
fatalError("oh no maybe \(err)")
224+
fatalError("oh no maybe \(String(describing: err))")
225225
}
226226
print("not err")
227227
}
@@ -230,7 +230,7 @@ boolWithErr { success, err in
230230

231231
// BOOL-DONT-HANDLE3: let success = try await boolWithErr()
232232
// BOOL-DONT-HANDLE3-NEXT: if !success {
233-
// BOOL-DONT-HANDLE3-NEXT: fatalError("oh no maybe \(<#err#>)")
233+
// BOOL-DONT-HANDLE3-NEXT: fatalError("oh no maybe \(String(describing: <#err#>))")
234234
// BOOL-DONT-HANDLE3-NEXT: }
235235
// BOOL-DONT-HANDLE3-NEXT: print("not err")
236236

@@ -342,7 +342,7 @@ optionalBoolWithErr { str, optBool, b, err in
342342
print("d \(err!)")
343343
}
344344
if optBool == false {
345-
print("e \(err)")
345+
print("e \(String(describing: err))")
346346
}
347347
if optBool != true {
348348
print("f \(err!)")
@@ -360,7 +360,7 @@ optionalBoolWithErr { str, optBool, b, err in
360360
// OPT-BOOL-WITH-ERR-NEXT: let (str, optBool, b) = try await optionalBoolWithErr()
361361
// OPT-BOOL-WITH-ERR-NEXT: print("a \(<#err#>!)")
362362
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> == false {
363-
// OPT-BOOL-WITH-ERR-NEXT: print("e \(<#err#>)")
363+
// OPT-BOOL-WITH-ERR-NEXT: print("e \(String(describing: <#err#>))")
364364
// OPT-BOOL-WITH-ERR-NEXT: }
365365
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> != true {
366366
// OPT-BOOL-WITH-ERR-NEXT: print("f \(<#err#>!)")
@@ -426,7 +426,7 @@ ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err
426426
if failure && err != nil {
427427
print("neat")
428428
}
429-
if failure, let err = err {
429+
if failure, let _ = err {
430430
print("neato")
431431
}
432432
}

0 commit comments

Comments
 (0)