Skip to content

Commit

Permalink
Support swift-syntax from 600.0.0-latest (#22)
Browse files Browse the repository at this point in the history
* Support swift-syntax from 600.0.0-latest

The Xcode 16 beta generates macro projects using these swift-syntax
snapshots. Luckily things seem to be backwards compatible, so we can
expand our supported range.

* Fix warnings
  • Loading branch information
stephencelis authored Jun 12, 2024
1 parent 5c4a1b9 commit 851c8b6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "625ccca8570773dd84a34ee51a81aa2bc5a4f97a",
"version" : "1.16.0"
"revision" : "8ddd519780452729c6634ad6bd0d2595938e9ea3",
"version" : "1.16.1"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "08a2f0a9a30e0f705f79c9cfaca1f68b71bdc775",
"version" : "510.0.0"
"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/apple/swift-syntax", "509.0.0"..<"511.0.0"),
.package(url: "https://github.com/apple/swift-syntax", "509.0.0"..<"601.0.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.16.0"),
],
targets: [
Expand Down
36 changes: 26 additions & 10 deletions Sources/MacroTesting/AssertMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,19 @@ public func assertMacro(
origSourceFile: .init(moduleName: "TestModule", fullFilePath: "Test.swift")
]
)
var expandedSourceFile = origSourceFile.expand(
macros: macros,
in: context,
indentationWidth: indentationWidth
)
#if canImport(SwiftSyntax600)
var expandedSourceFile = origSourceFile.expand(
macros: macros,
contextGenerator: { _ in context },
indentationWidth: indentationWidth
)
#else
var expandedSourceFile = origSourceFile.expand(
macros: macros,
in: context,
indentationWidth: indentationWidth
)
#endif

var offset = 0

Expand Down Expand Up @@ -300,11 +308,19 @@ public func assertMacro(
fixedSourceFile: .init(moduleName: "TestModule", fullFilePath: "Test.swift")
]
)
expandedSourceFile = fixedSourceFile.expand(
macros: macros,
in: context,
indentationWidth: indentationWidth
)
#if canImport(SwiftSyntax600)
expandedSourceFile = fixedSourceFile.expand(
macros: macros,
contextGenerator: { _ in context },
indentationWidth: indentationWidth
)
#else
expandedSourceFile = fixedSourceFile.expand(
macros: macros,
in: context,
indentationWidth: indentationWidth
)
#endif
} else if fixedSource != nil {
offset += 1
assertInlineSnapshot(
Expand Down

0 comments on commit 851c8b6

Please sign in to comment.