-
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
Open
hnrklssn
wants to merge
3
commits into
swiftlang:main
Choose a base branch
from
hnrklssn:update-verify-tests-continuted
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+613
−73
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
test/Utils/update-verify-tests/Inputs/unstringify-macro.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)")] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() {} | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
|
|
||
|
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. Project management by Claudio 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. 7,6 cyztxt3rz35.),(.4.6?) chuck cuff bc gen him hch h h jvhfffrtcd ;.),(.6,),) h hchhh |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Project management