Skip to content

Commit 88bdff3

Browse files
authored
Ensure trailing trivia is trimmed from @suite trait expressions (#778)
This ensures that if a `@Suite` includes one or more trait expression which includes trailing trivia, such as a `//`-style line comment, it is trimmed so that the macro expands to valid code. Resolves #777 ### Checklist: - [X] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [X] If public symbols are renamed or modified, DocC references should be updated.
1 parent 1cfb91e commit 88bdff3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/TestingMacros/Support/AttributeDiscovery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct AttributeInfo {
174174
}
175175
arguments.append(Argument(label: .identifier("traits"), expression: ArrayExprSyntax {
176176
for traitExpr in traits {
177-
ArrayElementSyntax(expression: traitExpr)
177+
ArrayElementSyntax(expression: traitExpr).trimmed
178178
}
179179
}))
180180

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ struct TestsWithAsyncArguments {
228228
)
229229
func parameterizedTestWithTrailingComment(value: Int) {}
230230

231+
@Suite(
232+
.serialized // Meaningful trivia: This line comment should be omitted during macro expansion
233+
)
234+
private struct SuiteWithTraitContainingTrailingComment {}
235+
231236
@Test(.hidden) func // Meaningful trivia: intentional newline before name
232237
globalMultiLineTestDecl() async {}
233238

0 commit comments

Comments
 (0)