Configure macro recording with Swift Testing Traits
mainWhen using the swift-testing framework, you can use the .macros trait to configure macro testing behavior for a @Suite. This allows you to specify which macros are available and control how expansions are recorded.
Available configurations for the record parameter within .macros(...):
.all: Automatically re-records the freshest expanded macro into theexpansiontrailing closure when the test is run..missing: Records only missing snapshots.
You can also control recording behavior globally using the SNAPSHOT_TESTING_RECORD environment variable.
import Testing
import MacroTesting
@Suite(
.macros(
["stringify": StringifyMacro.self],
record: .missing // Record only missing snapshots
)
)
struct StringifyMacroSwiftTestingTests {
@Test
func testStringify() {
assertMacro {
"""
#stringify(a + b)
"""
"""
(a + b, "a + b")
"""
}
}
}