-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[utils] add support for expected-expansion to update-verify-tests #85390
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import SwiftSyntax | ||
| import SwiftSyntaxBuilder | ||
| import SwiftSyntaxMacros | ||
|
|
||
| public struct UnstringifyPeerMacro: PeerMacro { | ||
| public static func expansion( | ||
| of node: AttributeSyntax, | ||
| providingPeersOf declaration: some DeclSyntaxProtocol, | ||
| in context: some MacroExpansionContext | ||
| ) throws -> [DeclSyntax] { | ||
| do { | ||
| let argumentList = node.arguments!.as(LabeledExprListSyntax.self)! | ||
| let arguments = [LabeledExprSyntax](argumentList) | ||
| let arg = arguments.first!.expression.as(StringLiteralExprSyntax.self)! | ||
| let content = arg.representedLiteralValue! | ||
| return [DeclSyntax("\(raw: content)")] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| // REQUIRES: swift_swift_parser, executable_test | ||
|
|
||
| // RUN: %empty-directory(%t) | ||
| // RUN: split-file %s %t | ||
|
|
||
| // Building this macro takes some time, so amortise the cost by using it for multiple sub tests | ||
| // RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(UnstringifyMacroDefinition) -module-name=UnstringifyMacroDefinition \ | ||
| // RUN: %S/Inputs/unstringify-macro.swift -g -no-toolchain-stdlib-rpath | ||
|
|
||
|
|
||
|
|
||
| // RUN: not %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/single.swift 2>%t/output.txt | ||
| // RUN: %update-verify-tests < %t/output.txt | ||
| // RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/single.swift | ||
| // RUN: %diff %t/single.swift %t/single.swift.expected | ||
|
|
||
| // RUN: not %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/multiple.swift 2>%t/output.txt | ||
| // RUN: %update-verify-tests < %t/output.txt | ||
| // RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/multiple.swift | ||
| // RUN: %diff %t/multiple.swift %t/multiple.swift.expected | ||
|
|
||
| // RUN: not %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/existing.swift 2>%t/output.txt | ||
| // RUN: %update-verify-tests < %t/output.txt | ||
| // RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/existing.swift | ||
| // RUN: %diff %t/existing.swift %t/existing.swift.expected | ||
|
|
||
| // RUN: not %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/gone.swift 2>%t/output.txt | ||
| // RUN: %update-verify-tests < %t/output.txt | ||
| // RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/gone.swift | ||
| // RUN: %diff %t/gone.swift %t/gone.swift.expected | ||
|
|
||
| // RUN: not %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/wrong-location.swift 2>%t/output.txt | ||
| // RUN: %update-verify-tests < %t/output.txt | ||
| // RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/wrong-location.swift | ||
| // RUN: %diff %t/wrong-location.swift %t/wrong-location.swift.expected | ||
|
|
||
| // RUN: not %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/nested.swift 2>%t/output.txt | ||
| // RUN: %update-verify-tests < %t/output.txt | ||
| // RUN: %target-swift-frontend-verify -load-plugin-library %t/%target-library-name(UnstringifyMacroDefinition) -typecheck %t/nested.swift | ||
| // RUN: %diff %t/nested.swift %t/nested.swift.expected | ||
|
|
||
| //--- single.swift | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| let a = x | ||
| } | ||
| """) | ||
| func foo() {} | ||
|
|
||
| //--- single.swift.expected | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| // expected-note@+1{{in expansion of macro 'unstringifyPeer' on global function 'foo()' here}} | ||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| let a = x | ||
| } | ||
| """) | ||
| // expected-expansion@+3:14{{ | ||
| // expected-warning@2{{initialization of immutable value 'a' was never used; consider replacing with assignment to '_' or removing it}} | ||
| // }} | ||
| func foo() {} | ||
|
|
||
| //--- multiple.swift | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| """) | ||
| func foo() {} | ||
|
|
||
| //--- multiple.swift.expected | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| // expected-note@+1 4{{in expansion of macro 'unstringifyPeer' on global function 'foo()' here}} | ||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| """) | ||
| // expected-expansion@+5:14{{ | ||
| // expected-note@1 2{{'x' declared here}} | ||
| // expected-error@2{{cannot find 'a' in scope; did you mean 'x'?}} | ||
| // expected-error@3{{cannot find 'b' in scope; did you mean 'x'?}} | ||
| // }} | ||
| func foo() {} | ||
|
|
||
| //--- existing.swift | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| """) | ||
| //expected-expansion@+4:14{{ | ||
| // expected-note@1 {{'x' declared here}} | ||
| // expected-error@3 {{cannot find 'b' in scope; did you mean 'x'?}} | ||
| //}} | ||
| func foo() {} | ||
|
|
||
| //--- existing.swift.expected | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| // expected-note@+1 4{{in expansion of macro 'unstringifyPeer' on global function 'foo()' here}} | ||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| """) | ||
| //expected-expansion@+5:14{{ | ||
| // expected-error@3 {{cannot find 'b' in scope; did you mean 'x'?}} | ||
| // expected-note@1 2{{'x' declared here}} | ||
| // expected-error@2 {{cannot find 'a' in scope; did you mean 'x'?}} | ||
| //}} | ||
| func foo() {} | ||
|
|
||
| //--- gone.swift | ||
| //expected-expansion@+4:14{{ | ||
| // expected-note@1 {{'x' declared here}} | ||
| // expected-error@3 {{cannot find 'b' in scope; did you mean 'x'?}} | ||
| //}} | ||
| func foo() {} | ||
|
|
||
| //--- gone.swift.expected | ||
| func foo() {} | ||
|
|
||
| //--- wrong-location.swift | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| // expected-expansion@2:14{{ | ||
| // expected-note@2 {{'x' declared here}} | ||
| // expected-error@3 {{cannot find 'b' in scope; did you mean 'x'?}} | ||
| // }} | ||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| """) | ||
| func foo() {} | ||
|
|
||
| //--- wrong-location.swift.expected | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| // expected-note@+1 4{{in expansion of macro 'unstringifyPeer' on global function 'foo()' here}} | ||
| @unstringifyPeer(""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| """) | ||
| // expected-expansion@+5:14{{ | ||
| // expected-note@1 2{{'x' declared here}} | ||
| // expected-error@2{{cannot find 'a' in scope; did you mean 'x'?}} | ||
| // expected-error@3{{cannot find 'b' in scope; did you mean 'x'?}} | ||
| // }} | ||
| func foo() {} | ||
|
|
||
| //--- nested.swift | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
| // hack to make this seem non-recursive | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer2(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| @unstringifyPeer(""" | ||
| func bar(_ y: Int) { | ||
| @unstringifyPeer2(\""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| \""") | ||
| func foo() {} | ||
| foo(y) | ||
| } | ||
| """) | ||
| func bar() {} | ||
|
|
||
| //--- nested.swift.expected | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
| // hack to make this seem non-recursive | ||
| @attached(peer, names: overloaded) | ||
| macro unstringifyPeer2(_ s: String) = | ||
| #externalMacro(module: "UnstringifyMacroDefinition", type: "UnstringifyPeerMacro") | ||
|
|
||
| // expected-note@+1 7{{in expansion of macro 'unstringifyPeer' on global function 'bar()' here}} | ||
| @unstringifyPeer(""" | ||
| func bar(_ y: Int) { | ||
| @unstringifyPeer2(\""" | ||
| func foo(_ x: Int) { | ||
| a = 2 | ||
| b = x | ||
| } | ||
| \""") | ||
| func foo() {} | ||
| foo(y) | ||
| } | ||
| """) | ||
| // expected-expansion@+10:14{{ | ||
| // expected-note@1 2{{did you mean 'y'?}} | ||
| // expected-note@2 4{{in expansion of macro 'unstringifyPeer2' on local function 'foo()' here}} | ||
| // expected-expansion@9:6{{ | ||
| // expected-note@1 2{{did you mean 'x'?}} | ||
| // expected-error@2{{cannot find 'a' in scope}} | ||
| // expected-error@3{{cannot find 'b' in scope}} | ||
| // }} | ||
| // expected-error@10{{argument passed to call that takes no arguments}} | ||
| // }} | ||
| func bar() {} | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,7 @@ | |
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument( | ||
| "--prefix", default="", help="The prefix passed to -verify" | ||
| ) | ||
| parser.add_argument("--prefix", default="", help="The prefix passed to -verify") | ||
| args = parser.parse_args() | ||
| (ret_code, output) = check_expectations(sys.stdin.readlines(), args.prefix) | ||
| print(output) | ||
|
|
@@ -41,4 +39,3 @@ def main(): | |
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ###K no km %+#^## ######U V VI toxicological concoction cool concoction juicing no Ovid ox us us wet so u is up if you go xx go There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. THE PROJECT
This comment was marked as spam.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include the new projectThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ##include The future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh ok /)&:99?!8)8)7(;(7?7?,&5;4!36,)))) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include your project
##Mini```