Skip to content

[Test] Add @escaping to async refactoring tests #38614

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
Jul 24, 2021
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
2 changes: 1 addition & 1 deletion test/SourceKit/Refactoring/basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ HasInitWithDefaultArgs(y: 45, z: 89)
func `hasBackticks`(`x`: Int) {}
`hasBackticks`(`x`:2)

func hasAsyncAlternative(completion: (String?, Error?) -> Void) { }
func hasAsyncAlternative(completion: @escaping (String?, Error?) -> Void) { }
func hasCallToAsyncAlternative() {
hasAsyncAlternative { str, err in print(str!) }
}
Expand Down
2 changes: 2 additions & 0 deletions test/refactoring/ConvertAsync/async_attribute_added.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// REQUIRES: concurrency

// RUN: %empty-directory(%t)

// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 -enable-experimental-concurrency | %FileCheck -check-prefix=SIMPLE %s
Expand Down
127 changes: 63 additions & 64 deletions test/refactoring/ConvertAsync/basic.swift

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion test/refactoring/ConvertAsync/check_compiles.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// REQUIRES: concurrency

// RUN: %empty-directory(%t)

func simple(completion: () -> Void) { }
func simple(completion: @escaping () -> Void) { }
func anything() -> Bool { return true }

// RUN: %swift-frontend -typecheck %s
Expand Down
8 changes: 5 additions & 3 deletions test/refactoring/ConvertAsync/convert_async_renames.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// REQUIRES: concurrency

// RUN: %empty-directory(%t)

func simple(_ completion: (String) -> Void) { }
func simple(_ completion: @escaping (String) -> Void) { }
func simple() async -> String { }

func simpleArg(arg: String, _ completion: (String) -> Void) { }
func simpleArg(arg: String, _ completion: @escaping (String) -> Void) { }
func simpleArg(arg: String) async -> String { }

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

func whatever() -> Bool { return true }
Expand Down
2 changes: 2 additions & 0 deletions test/refactoring/ConvertAsync/convert_async_wrapper.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// REQUIRES: concurrency

// RUN: %empty-directory(%t)

enum CustomError : Error {
Expand Down
20 changes: 10 additions & 10 deletions test/refactoring/ConvertAsync/convert_bool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import Foundation
import ConvertBoolObjC

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

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

Expand Down Expand Up @@ -185,7 +185,7 @@ boolWithErr { success, err in
}
}
if !success {
for x: Int in [] {
for _: Int in [] {
fatalError("oh no \(err!)")
}
}
Expand All @@ -212,7 +212,7 @@ boolWithErr { success, err in
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: if !success {
// BOOL-DONT-HANDLE2-NEXT: for x: Int in [] {
// BOOL-DONT-HANDLE2-NEXT: for _: Int in [] {
// BOOL-DONT-HANDLE2-NEXT: fatalError("oh no \(<#err#>!)")
// BOOL-DONT-HANDLE2-NEXT: }
// BOOL-DONT-HANDLE2-NEXT: }
Expand All @@ -221,7 +221,7 @@ boolWithErr { success, err in
// 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
boolWithErr { success, err in
if !success {
fatalError("oh no maybe \(err)")
fatalError("oh no maybe \(String(describing: err))")
}
print("not err")
}
Expand All @@ -230,7 +230,7 @@ boolWithErr { success, err in

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

Expand Down Expand Up @@ -342,7 +342,7 @@ optionalBoolWithErr { str, optBool, b, err in
print("d \(err!)")
}
if optBool == false {
print("e \(err)")
print("e \(String(describing: err))")
}
if optBool != true {
print("f \(err!)")
Expand All @@ -360,7 +360,7 @@ optionalBoolWithErr { str, optBool, b, err in
// OPT-BOOL-WITH-ERR-NEXT: let (str, optBool, b) = try await optionalBoolWithErr()
// OPT-BOOL-WITH-ERR-NEXT: print("a \(<#err#>!)")
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> == false {
// OPT-BOOL-WITH-ERR-NEXT: print("e \(<#err#>)")
// OPT-BOOL-WITH-ERR-NEXT: print("e \(String(describing: <#err#>))")
// OPT-BOOL-WITH-ERR-NEXT: }
// OPT-BOOL-WITH-ERR-NEXT: if <#optBool#> != true {
// OPT-BOOL-WITH-ERR-NEXT: print("f \(<#err#>!)")
Expand Down Expand Up @@ -426,7 +426,7 @@ ClassWithHandlerMethods.secondBoolFlagFailure("") { str, unrelated, failure, err
if failure && err != nil {
print("neat")
}
if failure, let err = err {
if failure, let _ = err {
print("neato")
}
}
Expand Down
Loading