You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -37,10 +37,6 @@ public typealias DiagnosticSpec = SwiftSyntaxMacrosGenericTestSupport.Diagnostic
37
37
/// Assert that expanding the given macros in the original source produces
38
38
/// the given expanded source code.
39
39
///
40
-
/// - Warning: If you call this function inside a Swift Testing test case,
41
-
/// the test will report no assertion failures even if the test fails.
42
-
/// Use ``expectMacroExpansion(_:expandedSource:diagnostics:macroSpecs:applyFixIts:fixedSource:testModuleName:testFileName:indentationWidth:buildConfiguration:fileID:file:line:column:)`` instead.
43
-
///
44
40
/// - Parameters:
45
41
/// - originalSource: The original source code, which is expected to contain
46
42
/// macros in various places (e.g., `#stringify(x + y)`).
@@ -55,7 +51,7 @@ public typealias DiagnosticSpec = SwiftSyntaxMacrosGenericTestSupport.Diagnostic
55
51
/// - indentationWidth: The indentation width used in the expansion.
56
52
/// - buildConfiguration: a build configuration that will be made available
/// to also specify the list of conformances passed to the macro expansion.
60
56
publicfunc assertMacroExpansion(
61
57
_ originalSource:String,
@@ -68,8 +64,10 @@ public func assertMacroExpansion(
68
64
testFileName:String="test.swift",
69
65
indentationWidth:Trivia=.spaces(4),
70
66
buildConfiguration:(anyBuildConfiguration)?=nil,
67
+
fileID:StaticString= #fileID,
71
68
file:StaticString= #filePath,
72
-
line:UInt= #line
69
+
line:UInt= #line,
70
+
column:UInt= #column
73
71
){
74
72
letspecs= macros.mapValues{MacroSpec(type: $0)}
75
73
assertMacroExpansion(
@@ -83,18 +81,16 @@ public func assertMacroExpansion(
83
81
testFileName: testFileName,
84
82
indentationWidth: indentationWidth,
85
83
buildConfiguration: buildConfiguration,
84
+
fileID: fileID,
86
85
file: file,
87
-
line: line
86
+
line: line,
87
+
column: column
88
88
)
89
89
}
90
90
91
91
/// Assert that expanding the given macros in the original source produces
92
92
/// the given expanded source code.
93
93
///
94
-
/// - Warning: If you call this function inside a Swift Testing test case,
95
-
/// the test will report no assertion failures even if the test fails.
96
-
/// Use ``expectMacroExpansion(_:expandedSource:diagnostics:macroSpecs:applyFixIts:fixedSource:testModuleName:testFileName:indentationWidth:buildConfiguration:fileID:file:line:column:)`` instead.
97
-
///
98
94
/// - Parameters:
99
95
/// - originalSource: The original source code, which is expected to contain
100
96
/// macros in various places (e.g., `#stringify(x + y)`).
@@ -110,62 +106,9 @@ public func assertMacroExpansion(
110
106
/// - testModuleName: The name of the test module to use.
111
107
/// - testFileName: The name of the test file name to use.
112
108
/// - indentationWidth: The indentation width used in the expansion.
109
+
/// - buildConfiguration: a build configuration that will be made available
/// Expect that expanding the given macros in the original source produces
150
-
/// the given expanded source code.
151
-
/// This function is the Swift Testing equivalent of ``assertMacroExpansion(_:expandedSource:diagnostics:macroSpecs:applyFixIts:fixedSource:testModuleName:testFileName:indentationWidth:buildConfiguration:file:line:)``
152
-
///
153
-
/// - Parameters:
154
-
/// - originalSource: The original source code, which is expected to contain
155
-
/// macros in various places (e.g., `#stringify(x + y)`).
156
-
/// - expectedExpandedSource: The source code that we expect to see after
157
-
/// performing macro expansion on the original source.
158
-
/// - diagnostics: The diagnostics when expanding any macro
159
-
/// - macroSpecs: The macros that should be expanded, provided as a dictionary
160
-
/// mapping macro names (e.g., `"CodableMacro"`) to specification with macro type
161
-
/// (e.g., `CodableMacro.self`) and a list of conformances macro provides
162
-
/// (e.g., `["Decodable", "Encodable"]`).
163
-
/// - applyFixIts: If specified, filters the Fix-Its that are applied to generate `fixedSource` to only those whose message occurs in this array. If `nil`, all Fix-Its from the diagnostics are applied.
164
-
/// - fixedSource: If specified, asserts that the source code after applying Fix-Its matches this string.
165
-
/// - testModuleName: The name of the test module to use.
166
-
/// - testFileName: The name of the test file name to use.
167
-
/// - indentationWidth: The indentation width used in the expansion.
168
-
publicfunc expectMacroExpansion(
169
112
_ originalSource:String,
170
113
expandedSource expectedExpandedSource:String,
171
114
diagnostics:[DiagnosticSpec]=[],
@@ -192,74 +135,34 @@ public func expectMacroExpansion(
192
135
testFileName: testFileName,
193
136
indentationWidth: indentationWidth,
194
137
buildConfiguration: buildConfiguration,
195
-
failureHandler:{
138
+
failureHandler:{ testFailure in
139
+
// Record a Swift Testing issue.
140
+
//
141
+
// (Note: If/when Swift Testing gains interoperability with XCTest, this
142
+
// will be translated into an XCTest failure if called while an XCTest is
143
+
// running.)
196
144
Issue.record(
197
-
Comment(rawValue:$0.message),
145
+
Comment(rawValue:testFailure.message),
198
146
sourceLocation:.init(
199
-
fileID:fileID.description,
200
-
filePath:file.description,
201
-
line:Int(line),
202
-
column:Int(column)
147
+
fileID:testFailure.location.fileID,
148
+
filePath:testFailure.location.filePath,
149
+
line:testFailure.location.line,
150
+
column:testFailure.location.column
203
151
)
204
152
)
205
-
},
206
-
fileID:"", // Not used in the failure handler
207
-
filePath: file,
208
-
line: line,
209
-
column:0 // Not used in the failure handler
210
-
)
211
-
}
212
153
213
-
/// Expect that expanding the given macros in the original source produces
214
-
/// the given expanded source code.
215
-
/// This function is the Swift Testing equivalent of ``assertMacroExpansion(_:expandedSource:diagnostics:macroSpecs:applyFixIts:fixedSource:testModuleName:testFileName:indentationWidth:buildConfiguration:file:line:)``
216
-
///
217
-
/// - Parameters:
218
-
/// - originalSource: The original source code, which is expected to contain
219
-
/// macros in various places (e.g., `#stringify(x + y)`).
220
-
/// - expectedExpandedSource: The source code that we expect to see after
221
-
/// performing macro expansion on the original source.
222
-
/// - diagnostics: The diagnostics when expanding any macro
223
-
/// - macros: The macros that should be expanded, provided as a dictionary
224
-
/// mapping macro names (e.g., `"stringify"`) to implementation types
225
-
/// (e.g., `StringifyMacro.self`).
226
-
/// - applyFixIts: If specified, filters the Fix-Its that are applied to generate `fixedSource` to only those whose message occurs in this array. If `nil`, all Fix-Its from the diagnostics are applied.
227
-
/// - fixedSource: If specified, asserts that the source code after applying Fix-Its matches this string.
228
-
/// - testModuleName: The name of the test module to use.
229
-
/// - testFileName: The name of the test file name to use.
230
-
/// - indentationWidth: The indentation width used in the expansion.
231
-
publicfunc expectMacroExpansion(
232
-
_ originalSource:String,
233
-
expandedSource expectedExpandedSource:String,
234
-
diagnostics:[DiagnosticSpec]=[],
235
-
macros:[String:Macro.Type],
236
-
applyFixIts:[String]?=nil,
237
-
fixedSource expectedFixedSource:String?=nil,
238
-
testModuleName:String="TestModule",
239
-
testFileName:String="test.swift",
240
-
indentationWidth:Trivia=.spaces(4),
241
-
buildConfiguration:(anyBuildConfiguration)?=nil,
242
-
fileID:StaticString= #fileID,
243
-
file:StaticString= #filePath,
244
-
line:UInt= #line,
245
-
column:UInt= #column
246
-
){
247
-
letspecs= macros.mapValues{MacroSpec(type: $0)}
248
-
expectMacroExpansion(
249
-
originalSource,
250
-
expandedSource: expectedExpandedSource,
251
-
diagnostics: diagnostics,
252
-
macroSpecs: specs,
253
-
applyFixIts: applyFixIts,
254
-
fixedSource: expectedFixedSource,
255
-
testModuleName: testModuleName,
256
-
testFileName: testFileName,
257
-
indentationWidth: indentationWidth,
258
-
buildConfiguration: buildConfiguration,
154
+
// Record an XCTest failure.
155
+
//
156
+
// FIXME: If/when Swift Testing gains interoperability with XCTest, this
157
+
// will become redundant with the above -- at least, when this library is
158
+
// compiled and run using a Swift version which supports interoperability.
159
+
// At that point, this should be adjusted so that it's only called when
0 commit comments