diff --git a/.swiftpm/configuration/Package.resolved b/.swiftpm/configuration/Package.resolved index 2c3597d..1e1416a 100644 --- a/.swiftpm/configuration/Package.resolved +++ b/.swiftpm/configuration/Package.resolved @@ -5,14 +5,14 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-snapshot-testing", "state" : { - "revision" : "63d3b45dd249878a41c56274a748ca2c1c9c5230", - "version" : "1.17.1" + "revision" : "6d932a79e7173b275b96c600c86c603cf84f153c", + "version" : "1.17.4" } }, { "identity" : "swift-syntax", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-syntax", + "location" : "https://github.com/swiftlang/swift-syntax", "state" : { "revision" : "303e5c5c36d6a558407d364878df131c3546fad8", "version" : "510.0.2" diff --git a/Package.swift b/Package.swift index 78b7a4b..bcffdee 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.17.1"), + .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.17.4"), .package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"), ], targets: [ diff --git a/Sources/MacroTesting/AssertMacro.swift b/Sources/MacroTesting/AssertMacro.swift index f02ba10..855f477 100644 --- a/Sources/MacroTesting/AssertMacro.swift +++ b/Sources/MacroTesting/AssertMacro.swift @@ -9,6 +9,10 @@ import SwiftSyntaxMacroExpansion import SwiftSyntaxMacros import XCTest +#if canImport(Testing) + import Testing +#endif + /// Asserts that a given Swift source string matches an expected string with all macros expanded. /// /// To write a macro assertion, you simply pass the mapping of macros to expand along with the @@ -124,7 +128,12 @@ public func assertMacro( line: UInt = #line, column: UInt = #column ) { - withSnapshotTesting(record: record ?? SnapshotTestingConfiguration.current?.record) { + #if canImport(Testing) + let record = record ?? SnapshotTestingConfiguration.current?.record ?? Test.current?.record + #else + let record = record ?? SnapshotTestingConfiguration.current?.record + #endif + withSnapshotTesting(record: record) { let macros = macros ?? MacroTestingConfiguration.current.macros guard let macros, !macros.isEmpty else { recordIssue( diff --git a/Sources/MacroTesting/MacrosTestTrait.swift b/Sources/MacroTesting/MacrosTestTrait.swift index a3d9e1b..c920f7a 100644 --- a/Sources/MacroTesting/MacrosTestTrait.swift +++ b/Sources/MacroTesting/MacrosTestTrait.swift @@ -2,7 +2,7 @@ import SnapshotTesting import SwiftSyntax import SwiftSyntaxMacros - @_spi(Experimental) import Testing + import Testing @_spi(Experimental) extension Trait where Self == _MacrosTestTrait { @@ -28,24 +28,29 @@ /// A type representing the configuration of snapshot testing. @_spi(Experimental) - public struct _MacrosTestTrait: CustomExecutionTrait, SuiteTrait, TestTrait { + public struct _MacrosTestTrait: SuiteTrait, TestTrait { public let isRecursive = true let configuration: MacroTestingConfiguration let record: SnapshotTestingConfiguration.Record? + } + + extension Test { + var macros: [String: Macro.Type]? { + for trait in traits.reversed() { + if let macros = (trait as? _MacrosTestTrait)?.configuration.macros { + return macros + } + } + return nil + } - public func execute( - _ function: @escaping () async throws -> Void, - for test: Test, - testCase: Test.Case? - ) async throws { - try await withMacroTesting( - indentationWidth: configuration.indentationWidth, - macros: configuration.macros - ) { - try await withSnapshotTesting(record: record) { - try await function() + var record: SnapshotTestingConfiguration.Record? { + for trait in traits.reversed() { + if let macros = (trait as? _MacrosTestTrait)?.record { + return macros } } + return nil } } #endif