Skip to content

Commit

Permalink
Fix indentation width test trait parameter (#30)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
stephencelis and mbrandonw authored Aug 19, 2024
1 parent c33adc7 commit e243319
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Sources/MacroTesting/AssertMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,21 @@ public func assertMacro(
line: UInt = #line,
column: UInt = #column
) {
var indentationWidth = indentationWidth
?? MacroTestingConfiguration.current.indentationWidth
var macros = macros
?? MacroTestingConfiguration.current.macros
var record = record
?? SnapshotTestingConfiguration.current?.record
#if canImport(Testing)
let record = record ?? SnapshotTestingConfiguration.current?.record ?? Test.current?.record
#else
let record = record ?? SnapshotTestingConfiguration.current?.record
indentationWidth = indentationWidth
?? Test.current?.indentationWidth
macros = macros
?? Test.current?.macros
record = record
?? Test.current?.record
#endif
withSnapshotTesting(record: record) {
#if canImport(Testing)
let macros = macros ?? MacroTestingConfiguration.current.macros ?? Test.current?.macros
#else
let macros = macros ?? MacroTestingConfiguration.current.macros
#endif
withMacroTesting(indentationWidth: indentationWidth, record: record, macros: macros) {
guard let macros, !macros.isEmpty else {
recordIssue(
"""
Expand Down
9 changes: 9 additions & 0 deletions Sources/MacroTesting/MacrosTestTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
}

extension Test {
var indentationWidth: Trivia? {
for trait in traits.reversed() {
if let indentationWidth = (trait as? _MacrosTestTrait)?.configuration.indentationWidth {
return indentationWidth
}
}
return nil
}

var macros: [String: Macro.Type]? {
for trait in traits.reversed() {
if let macros = (trait as? _MacrosTestTrait)?.configuration.macros {
Expand Down

0 comments on commit e243319

Please sign in to comment.