Skip to content
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

Xcode 16 beta 5: Fix test trait #28

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions .swiftpm/configuration/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "63d3b45dd249878a41c56274a748ca2c1c9c5230",
"version" : "1.17.1"
"branch" : "fix-test-trait",
"revision" : "cf0742603c2aabb3226fc4f1e1dfb92add3e9ddf"
}
},
{
"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"
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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", branch: "fix-test-trait"),
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
],
targets: [
Expand Down
11 changes: 10 additions & 1 deletion Sources/MacroTesting/AssertMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
31 changes: 18 additions & 13 deletions Sources/MacroTesting/MacrosTestTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import SnapshotTesting
import SwiftSyntax
import SwiftSyntaxMacros
@_spi(Experimental) import Testing
import Testing

@_spi(Experimental)
extension Trait where Self == _MacrosTestTrait {
Expand All @@ -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
Loading