File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Sources/SwiftSyntaxMacrosTestSupport Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import _SwiftSyntaxTestSupport
14
14
import SwiftBasicFormat
15
15
import SwiftDiagnostics
16
16
import SwiftParser
17
+ import SwiftParserDiagnostics
17
18
import SwiftSyntax
18
19
import SwiftSyntaxMacros
19
20
import XCTest
@@ -279,11 +280,27 @@ public func assertMacroExpansion(
279
280
let context = BasicMacroExpansionContext (
280
281
sourceFiles: [ origSourceFile: . init( moduleName: testModuleName, fullFilePath: testFileName) ]
281
282
)
282
- let expandedSourceFile = origSourceFile. expand ( macros: macros, in: context) . formatted ( using: BasicFormat ( indentationWidth: indentationWidth) )
283
283
284
+ let expandedSourceFile = origSourceFile. expand ( macros: macros, in: context)
285
+ let diags = ParseDiagnosticsGenerator . diagnostics ( for: expandedSourceFile)
286
+ if !diags. isEmpty {
287
+ XCTFail (
288
+ """
289
+ Expanded source should not contain any syntax errors, but contains:
290
+ \( DiagnosticsFormatter . annotatedSource ( tree: expandedSourceFile, diags: diags) )
291
+
292
+ Expanded syntax tree was:
293
+ \( expandedSourceFile. debugDescription)
294
+ """ ,
295
+ file: file,
296
+ line: line
297
+ )
298
+ }
299
+
300
+ let formattedSourceFile = expandedSourceFile. formatted ( using: BasicFormat ( indentationWidth: indentationWidth) )
284
301
assertStringsEqualWithDiff (
285
- expandedSourceFile . description. trimmingTrailingWhitespace ( ) . trimmingCharacters ( in: . newlines) ,
286
- expandedSource. trimmingTrailingWhitespace ( ) . trimmingCharacters ( in: . newlines) ,
302
+ formattedSourceFile . description. trimmingCharacters ( in: . newlines) ,
303
+ expandedSource. trimmingCharacters ( in: . newlines) ,
287
304
additionalInfo: """
288
305
Actual expanded source:
289
306
\( expandedSource)
You can’t perform that action at this time.
0 commit comments