You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- New `assertMacroExpansion` API with option to specify macro specifications with `macroSpecs` argument
53
+
- Description: `macroSpecs` can have additional specifications like conformances provided by member or extension macro that can be used for macro expansion.
/// to also specify the list of conformances passed to the macro expansion.
308
+
publicfunc assertMacroExpansion(
309
+
_ originalSource:String,
310
+
expandedSource expectedExpandedSource:String,
311
+
diagnostics:[DiagnosticSpec]=[],
312
+
macros:[String:Macro.Type],
313
+
applyFixIts:[String]?=nil,
314
+
fixedSource expectedFixedSource:String?=nil,
315
+
testModuleName:String="TestModule",
316
+
testFileName:String="test.swift",
317
+
indentationWidth:Trivia=.spaces(4),
318
+
file:StaticString= #file,
319
+
line:UInt= #line
320
+
){
321
+
letspecs= macros.mapValues{MacroSpec(type: $0)}
322
+
assertMacroExpansion(
323
+
originalSource,
324
+
expandedSource: expectedExpandedSource,
325
+
diagnostics: diagnostics,
326
+
macroSpecs: specs,
327
+
applyFixIts: applyFixIts,
328
+
fixedSource: expectedFixedSource,
329
+
testModuleName: testModuleName,
330
+
testFileName: testFileName,
331
+
indentationWidth: indentationWidth
332
+
)
333
+
}
334
+
335
+
/// Assert that expanding the given macros in the original source produces
336
+
/// the given expanded source code.
337
+
///
338
+
/// - Parameters:
339
+
/// - originalSource: The original source code, which is expected to contain
340
+
/// macros in various places (e.g., `#stringify(x + y)`).
341
+
/// - expectedExpandedSource: The source code that we expect to see after
342
+
/// performing macro expansion on the original source.
343
+
/// - diagnostics: The diagnostics when expanding any macro
344
+
/// - macroSpecs: The macros that should be expanded, provided as a dictionary
345
+
/// mapping macro names (e.g., `"CodableMacro"`) to specification with macro type
346
+
/// (e.g., `CodableMacro.self`) and a list of conformances macro provides
347
+
/// (e.g., `["Decodable", "Encodable"]`).
302
348
/// - applyFixIts: If specified, filters the Fix-Its that are applied to generate `fixedSource` to only those whose message occurs in this array. If `nil`, all Fix-Its from the diagnostics are applied.
303
349
/// - fixedSource: If specified, asserts that the source code after applying Fix-Its matches this string.
304
350
/// - testModuleName: The name of the test module to use.
@@ -308,7 +354,7 @@ public func assertMacroExpansion(
308
354
_ originalSource:String,
309
355
expandedSource expectedExpandedSource:String,
310
356
diagnostics:[DiagnosticSpec]=[],
311
-
macros:[String:Macro.Type],
357
+
macroSpecs:[String:MacroSpec],
312
358
applyFixIts:[String]?=nil,
313
359
fixedSource expectedFixedSource:String?=nil,
314
360
testModuleName:String="TestModule",
@@ -329,7 +375,7 @@ public func assertMacroExpansion(
0 commit comments