@@ -163,9 +163,6 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
163
163
/// This is the case when the scanner is looking for tests inside a disabled suite.
164
164
private let allTestsDisabled : Bool
165
165
166
- /// Whether the tests discovered by the scanner should be marked as being delcared in an extension.
167
- private let isScanningExtension : Bool
168
-
169
166
/// The names of the types that this scanner is scanning members for.
170
167
///
171
168
/// For example, when scanning for tests inside `Bar` in the following, this is `["Foo", "Bar"]`
@@ -180,26 +177,24 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
180
177
private let parentTypeNames : [ String ]
181
178
182
179
/// The discovered test items.
183
- private var result : [ TestItem ] = [ ]
180
+ private var result : [ AnnotatedTestItem ] = [ ]
184
181
185
182
private init (
186
183
snapshot: DocumentSnapshot ,
187
184
allTestsDisabled: Bool ,
188
- isScanningExtension: Bool ,
189
185
parentTypeNames: [ String ]
190
186
) {
191
187
self . snapshot = snapshot
192
188
self . allTestsDisabled = allTestsDisabled
193
189
self . parentTypeNames = parentTypeNames
194
- self . isScanningExtension = isScanningExtension
195
190
super. init ( viewMode: . fixedUp)
196
191
}
197
192
198
193
/// Public entry point. Scans the syntax tree of the given snapshot for swift-testing tests.
199
194
public static func findTestSymbols(
200
195
in snapshot: DocumentSnapshot ,
201
196
syntaxTreeManager: SyntaxTreeManager
202
- ) async -> [ TestItem ] {
197
+ ) async -> [ AnnotatedTestItem ] {
203
198
guard snapshot. text. contains ( " Suite " ) || snapshot. text. contains ( " Test " ) else {
204
199
// If the file contains swift-testing tests, it must contain a `@Suite` or `@Test` attribute.
205
200
// Only check for the attribute name because the attribute may be module qualified and contain an arbitrary amount
@@ -211,7 +206,6 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
211
206
let visitor = SyntacticSwiftTestingTestScanner (
212
207
snapshot: snapshot,
213
208
allTestsDisabled: false ,
214
- isScanningExtension: false ,
215
209
parentTypeNames: [ ]
216
210
)
217
211
visitor. walk ( syntaxTree)
@@ -245,7 +239,6 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
245
239
let memberScanner = SyntacticSwiftTestingTestScanner (
246
240
snapshot: snapshot,
247
241
allTestsDisabled: attributeData? . isDisabled ?? false ,
248
- isScanningExtension: node is ExtensionDeclSyntax ,
249
242
parentTypeNames: parentTypeNames + typeNames
250
243
)
251
244
memberScanner. walk ( node. memberBlock)
@@ -256,15 +249,18 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
256
249
}
257
250
258
251
let range = snapshot. range ( of: node. positionAfterSkippingLeadingTrivia..< node. endPositionBeforeTrailingTrivia)
259
- let testItem = TestItem (
260
- id: ( parentTypeNames + typeNames) . joined ( separator: " / " ) ,
261
- label: attributeData? . displayName ?? typeNames. last!,
262
- disabled: ( attributeData? . isDisabled ?? false ) || allTestsDisabled,
263
- isExtension: node is ExtensionDeclSyntax ,
264
- style: TestStyle . swiftTesting,
265
- location: Location ( uri: snapshot. uri, range: range) ,
266
- children: memberScanner. result,
267
- tags: attributeData? . tags. map ( TestTag . init ( id: ) ) ?? [ ]
252
+ // Members wont be extensions since extensions will only be at the top level.
253
+ let testItem = AnnotatedTestItem (
254
+ testItem: TestItem (
255
+ id: ( parentTypeNames + typeNames) . joined ( separator: " / " ) ,
256
+ label: attributeData? . displayName ?? typeNames. last!,
257
+ disabled: ( attributeData? . isDisabled ?? false ) || allTestsDisabled,
258
+ style: TestStyle . swiftTesting,
259
+ location: Location ( uri: snapshot. uri, range: range) ,
260
+ children: memberScanner. result. map ( \. testItem) ,
261
+ tags: attributeData? . tags. map ( TestTag . init ( id: ) ) ?? [ ]
262
+ ) ,
263
+ isExtension: node. is ( ExtensionDeclSyntax . self)
268
264
)
269
265
result. append ( testItem)
270
266
return . skipChildren
@@ -311,15 +307,17 @@ final class SyntacticSwiftTestingTestScanner: SyntaxVisitor {
311
307
node. name. text + " ( " + node. signature. parameterClause. parameters. map { " \( $0. firstName. text) : " } . joined ( ) + " ) "
312
308
313
309
let range = snapshot. range ( of: node. positionAfterSkippingLeadingTrivia..< node. endPositionBeforeTrailingTrivia)
314
- let testItem = TestItem (
315
- id: ( parentTypeNames + [ name] ) . joined ( separator: " / " ) ,
316
- label: attributeData. displayName ?? name,
317
- disabled: attributeData. isDisabled || allTestsDisabled,
318
- isExtension: isScanningExtension,
319
- style: TestStyle . swiftTesting,
320
- location: Location ( uri: snapshot. uri, range: range) ,
321
- children: [ ] ,
322
- tags: attributeData. tags. map ( TestTag . init ( id: ) )
310
+ let testItem = AnnotatedTestItem (
311
+ testItem: TestItem (
312
+ id: ( parentTypeNames + [ name] ) . joined ( separator: " / " ) ,
313
+ label: attributeData. displayName ?? name,
314
+ disabled: attributeData. isDisabled || allTestsDisabled,
315
+ style: TestStyle . swiftTesting,
316
+ location: Location ( uri: snapshot. uri, range: range) ,
317
+ children: [ ] ,
318
+ tags: attributeData. tags. map ( TestTag . init ( id: ) )
319
+ ) ,
320
+ isExtension: false
323
321
)
324
322
result. append ( testItem)
325
323
return . visitChildren
0 commit comments