From e2433195c14cd9597fe2685e0c3af9e701582415 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 19 Aug 2024 14:11:26 -0700 Subject: [PATCH] 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 --- Sources/MacroTesting/AssertMacro.swift | 22 +++++++++++++--------- Sources/MacroTesting/MacrosTestTrait.swift | 9 +++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Sources/MacroTesting/AssertMacro.swift b/Sources/MacroTesting/AssertMacro.swift index 6095bb8..df125fa 100644 --- a/Sources/MacroTesting/AssertMacro.swift +++ b/Sources/MacroTesting/AssertMacro.swift @@ -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( """ diff --git a/Sources/MacroTesting/MacrosTestTrait.swift b/Sources/MacroTesting/MacrosTestTrait.swift index c920f7a..fad9e28 100644 --- a/Sources/MacroTesting/MacrosTestTrait.swift +++ b/Sources/MacroTesting/MacrosTestTrait.swift @@ -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 {