Skip to content

Commit 20c1a8f

Browse files
authored
Xcode 16 beta 5: Fix test trait (pointfreeco#28)
* Fix test trait We can't yet leverage custom execution traits, and in fact Xcode 16 beta 5 removed access to them. Instead we can use the task's current test to access trait information directly from our helpers. * wip
1 parent a35257b commit 20c1a8f

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

.swiftpm/configuration/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
)
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.17.1"),
20+
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.17.4"),
2121
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
2222
],
2323
targets: [

Sources/MacroTesting/AssertMacro.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import SwiftSyntaxMacroExpansion
99
import SwiftSyntaxMacros
1010
import XCTest
1111

12+
#if canImport(Testing)
13+
import Testing
14+
#endif
15+
1216
/// Asserts that a given Swift source string matches an expected string with all macros expanded.
1317
///
1418
/// To write a macro assertion, you simply pass the mapping of macros to expand along with the
@@ -124,7 +128,12 @@ public func assertMacro(
124128
line: UInt = #line,
125129
column: UInt = #column
126130
) {
127-
withSnapshotTesting(record: record ?? SnapshotTestingConfiguration.current?.record) {
131+
#if canImport(Testing)
132+
let record = record ?? SnapshotTestingConfiguration.current?.record ?? Test.current?.record
133+
#else
134+
let record = record ?? SnapshotTestingConfiguration.current?.record
135+
#endif
136+
withSnapshotTesting(record: record) {
128137
let macros = macros ?? MacroTestingConfiguration.current.macros
129138
guard let macros, !macros.isEmpty else {
130139
recordIssue(

Sources/MacroTesting/MacrosTestTrait.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import SnapshotTesting
33
import SwiftSyntax
44
import SwiftSyntaxMacros
5-
@_spi(Experimental) import Testing
5+
import Testing
66

77
@_spi(Experimental)
88
extension Trait where Self == _MacrosTestTrait {
@@ -28,24 +28,29 @@
2828

2929
/// A type representing the configuration of snapshot testing.
3030
@_spi(Experimental)
31-
public struct _MacrosTestTrait: CustomExecutionTrait, SuiteTrait, TestTrait {
31+
public struct _MacrosTestTrait: SuiteTrait, TestTrait {
3232
public let isRecursive = true
3333
let configuration: MacroTestingConfiguration
3434
let record: SnapshotTestingConfiguration.Record?
35+
}
36+
37+
extension Test {
38+
var macros: [String: Macro.Type]? {
39+
for trait in traits.reversed() {
40+
if let macros = (trait as? _MacrosTestTrait)?.configuration.macros {
41+
return macros
42+
}
43+
}
44+
return nil
45+
}
3546

36-
public func execute(
37-
_ function: @escaping () async throws -> Void,
38-
for test: Test,
39-
testCase: Test.Case?
40-
) async throws {
41-
try await withMacroTesting(
42-
indentationWidth: configuration.indentationWidth,
43-
macros: configuration.macros
44-
) {
45-
try await withSnapshotTesting(record: record) {
46-
try await function()
47+
var record: SnapshotTestingConfiguration.Record? {
48+
for trait in traits.reversed() {
49+
if let macros = (trait as? _MacrosTestTrait)?.record {
50+
return macros
4751
}
4852
}
53+
return nil
4954
}
5055
}
5156
#endif

0 commit comments

Comments
 (0)