Skip to content
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

Trim parameter names in SwiftTestingScanner #1209

Merged

Conversation

plemarquand
Copy link
Contributor

Test specified with anonymous arguments would produce an id with extra whitespace, i.e: funcWithArgument(_ x: Int) would produce a TestItem id of funcWithArgument(_ :)

This patch trims this extra whitespace to produce IDs that are consistent with Swift's function ids, i.e: funcWithArgument(_:)

Test specified with anonymous arguments would produce an id with extra
whitespace, i.e: `funcWithArgument(_ x: Int)` would produce a TestItem
id of `funcWithArgument(_ :)`

This patch trims this extra whitespace to produce IDs that are
consistent with Swift's function ids, i.e: `funcWithArgument(_:)`
@@ -292,7 +292,7 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
}

let name =
node.name.text + "(" + node.signature.parameterClause.parameters.map { "\($0.firstName):" }.joined() + ")"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is still not quite correct because of optional leading/trailing backticks. See apple/swift-syntax#1936.

swift-testing has logic to trim these off that you may need to adopt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the best course of action is to leverage apple/swift-syntax#2576 when its ready. @ahoppen In the short term is it worth stripping the backticks in the TestItem initializer until the proper solution is merged?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long-term yes, short-term we'll need you to remove them manually I think. (Whether or not it's "worth it" is subjective, but swift-testing's own test suite checks for this sort of thing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahoppen @grynspan I think its worth merging this on its own and addressing the backticks in a follow up.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine—let's just not forget.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #1211 as a stopgap until apple/swift-syntax#2576 is ready

@plemarquand
Copy link
Contributor Author

@swift-ci Please test

@plemarquand
Copy link
Contributor Author

@swift-ci Please test Windows

@plemarquand plemarquand requested a review from ahoppen May 1, 2024 17:40
@plemarquand plemarquand merged commit 7c4acf9 into apple:main May 1, 2024
3 checks passed
@plemarquand plemarquand deleted the fix-test-item-arg-trivia-trimming branch May 1, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants