Skip to content

Support array of macros in test trait. #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/MacroTesting/MacrosTestTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@
record: record
)
}

/// Configure snapshot testing in a suite or test.
///
/// - Parameters:
/// - indentationWidth: The `Trivia` for setting indentation during macro expansion (e.g., `.spaces(2)`).
/// Defaults to the original source's indentation if unspecified.
/// - record: The recording strategy to use for macro expansions. This can be set to `.all`, `.missing`,
/// `.never`, or `.failed`. If not provided, it uses the current configuration, which can also be set via
/// the `SNAPSHOT_TESTING_RECORD` environment variable.
/// - macros: An array of macros. This specifies which macros should be expanded during testing.
public static func macros(
indentationWidth: Trivia? = nil,
record: SnapshotTestingConfiguration.Record? = nil,
macros: [Macro.Type]? = nil
) -> Self {
_MacrosTestTrait(
configuration: MacroTestingConfiguration(
indentationWidth: indentationWidth,
macros: macros.map { Dictionary(macros: $0) }
),
record: record
)
}
}

/// A type representing the configuration of snapshot testing.
Expand Down