Skip to content

Commit e243319

Browse files
Fix indentation width test trait parameter (#30)
* Fix indentation width test trait parameter Forgot to thread this through when fixing the build for beta 5. * wip --------- Co-authored-by: Brandon Williams <[email protected]>
1 parent c33adc7 commit e243319

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Sources/MacroTesting/AssertMacro.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,21 @@ public func assertMacro(
128128
line: UInt = #line,
129129
column: UInt = #column
130130
) {
131+
var indentationWidth = indentationWidth
132+
?? MacroTestingConfiguration.current.indentationWidth
133+
var macros = macros
134+
?? MacroTestingConfiguration.current.macros
135+
var record = record
136+
?? SnapshotTestingConfiguration.current?.record
131137
#if canImport(Testing)
132-
let record = record ?? SnapshotTestingConfiguration.current?.record ?? Test.current?.record
133-
#else
134-
let record = record ?? SnapshotTestingConfiguration.current?.record
138+
indentationWidth = indentationWidth
139+
?? Test.current?.indentationWidth
140+
macros = macros
141+
?? Test.current?.macros
142+
record = record
143+
?? Test.current?.record
135144
#endif
136-
withSnapshotTesting(record: record) {
137-
#if canImport(Testing)
138-
let macros = macros ?? MacroTestingConfiguration.current.macros ?? Test.current?.macros
139-
#else
140-
let macros = macros ?? MacroTestingConfiguration.current.macros
141-
#endif
145+
withMacroTesting(indentationWidth: indentationWidth, record: record, macros: macros) {
142146
guard let macros, !macros.isEmpty else {
143147
recordIssue(
144148
"""

Sources/MacroTesting/MacrosTestTrait.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
}
3636

3737
extension Test {
38+
var indentationWidth: Trivia? {
39+
for trait in traits.reversed() {
40+
if let indentationWidth = (trait as? _MacrosTestTrait)?.configuration.indentationWidth {
41+
return indentationWidth
42+
}
43+
}
44+
return nil
45+
}
46+
3847
var macros: [String: Macro.Type]? {
3948
for trait in traits.reversed() {
4049
if let macros = (trait as? _MacrosTestTrait)?.configuration.macros {

0 commit comments

Comments
 (0)