Skip to content

Commit 4dafaca

Browse files
committed
In assertStringsEqualWithDiff trim newlines from expanded source
This removes the oddity that if you expand an attached macro on the first line, the expected expanded source needs to start with a newline. Also, when the actual expanded source does not match the expected one, print the actual expanded source as it’s sometimes easier to read than the diff, especially if there are multiple differences.
1 parent 24bf3f9 commit 4dafaca

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Sources/SwiftSyntaxMacrosTestSupport/Assertions.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,12 @@ public func assertMacroExpansion(
282282
let expandedSourceFile = origSourceFile.expand(macros: macros, in: context).formatted(using: BasicFormat(indentationWidth: indentationWidth))
283283

284284
assertStringsEqualWithDiff(
285-
expandedSourceFile.description.trimmingTrailingWhitespace(),
286-
expandedSource.trimmingTrailingWhitespace(),
285+
expandedSourceFile.description.trimmingTrailingWhitespace().trimmingCharacters(in: .newlines),
286+
expandedSource.trimmingTrailingWhitespace().trimmingCharacters(in: .newlines),
287+
additionalInfo: """
288+
Actual expanded source:
289+
\(expandedSource)
290+
""",
287291
file: file,
288292
line: line
289293
)

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,6 @@ final class MacroSystemTests: XCTestCase {
783783
}
784784
""",
785785
expandedSource: """
786-
787786
struct X {
788787
func f() {
789788
}
@@ -807,7 +806,6 @@ final class MacroSystemTests: XCTestCase {
807806
#bitwidthNumberedStructs("MyInt")
808807
""",
809808
expandedSource: """
810-
811809
struct MyInt8 {
812810
}
813811
struct MyInt16 {
@@ -829,7 +827,6 @@ final class MacroSystemTests: XCTestCase {
829827
var x: Int
830828
""",
831829
expandedSource: """
832-
833830
var x: Int {
834831
get {
835832
_x.wrappedValue
@@ -852,7 +849,6 @@ final class MacroSystemTests: XCTestCase {
852849
func f(a: Int, for b: String, _ value: Double) async -> String { }
853850
""",
854851
expandedSource: """
855-
856852
func f(a: Int, for b: String, _ value: Double) async -> String {
857853
}
858854
@@ -876,7 +872,6 @@ final class MacroSystemTests: XCTestCase {
876872
}
877873
""",
878874
expandedSource: """
879-
880875
struct S {
881876
var value: Int
882877
var _storage: Storage<Self>
@@ -904,7 +899,6 @@ final class MacroSystemTests: XCTestCase {
904899
}
905900
""",
906901
expandedSource: """
907-
908902
struct Point {
909903
@Wrapper
910904
var x: Int
@@ -949,7 +943,6 @@ final class MacroSystemTests: XCTestCase {
949943
}
950944
""",
951945
expandedSource: """
952-
953946
struct Point {
954947
@Wrapper
955948
var x: Int

0 commit comments

Comments
 (0)