Skip to content

Commit 9faef9b

Browse files
authored
Test that the fixups are generated if display name is empty (#1267)
No functional change: adds new test cases for the change in #1256 Moved the tests previously added to `apiMisuseErrors` -> `apiMisuseErrorsIncludingFixIts`, and include the expected fixits It would probably be ok to leave them in `apiMisuseErrors` as well, but I think it would be kinda redundant since we also test the expected message along with the fixits already. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 75fde1d commit 9faef9b

File tree

1 file changed

+56
-8
lines changed

1 file changed

+56
-8
lines changed

Tests/TestingMacrosTests/TestDeclarationMacroTests.swift

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,6 @@ struct TestDeclarationMacroTests {
149149
"Attribute 'Test' cannot be applied to a function within structure 'S' because its conformance to 'Escapable' has been suppressed",
150150
"struct S: ~(Escapable) { @Test func f() {} }":
151151
"Attribute 'Test' cannot be applied to a function within structure 'S' because its conformance to 'Escapable' has been suppressed",
152-
153-
// empty display name string literal
154-
#"@Test("") func f() {}"#:
155-
"Attribute 'Test' specifies an empty display name for this function",
156-
##"@Test(#""#) func f() {}"##:
157-
"Attribute 'Test' specifies an empty display name for this function",
158-
#"@Suite("") struct S {}"#:
159-
"Attribute 'Suite' specifies an empty display name for this structure",
160152
]
161153
)
162154
func apiMisuseErrors(input: String, expectedMessage: String) throws {
@@ -241,6 +233,62 @@ struct TestDeclarationMacroTests {
241233
),
242234
]
243235
),
236+
237+
// empty display name string literal
238+
#"@Test("") func f() {}"#:
239+
(
240+
message: "Attribute 'Test' specifies an empty display name for this function",
241+
fixIts: [
242+
ExpectedFixIt(
243+
message: "Remove display name argument",
244+
changes: [
245+
.replace(oldSourceCode: #""""#, newSourceCode: "")
246+
]),
247+
ExpectedFixIt(
248+
message: "Add display name",
249+
changes: [
250+
.replace(
251+
oldSourceCode: #""""#,
252+
newSourceCode: #""\#(EditorPlaceholderExprSyntax("display name"))""#)
253+
])
254+
]
255+
),
256+
##"@Test(#""#) func f() {}"##:
257+
(
258+
message: "Attribute 'Test' specifies an empty display name for this function",
259+
fixIts: [
260+
ExpectedFixIt(
261+
message: "Remove display name argument",
262+
changes: [
263+
.replace(oldSourceCode: ##"#""#"##, newSourceCode: "")
264+
]),
265+
ExpectedFixIt(
266+
message: "Add display name",
267+
changes: [
268+
.replace(
269+
oldSourceCode: ##"#""#"##,
270+
newSourceCode: #""\#(EditorPlaceholderExprSyntax("display name"))""#)
271+
])
272+
]
273+
),
274+
#"@Suite("") struct S {}"#:
275+
(
276+
message: "Attribute 'Suite' specifies an empty display name for this structure",
277+
fixIts: [
278+
ExpectedFixIt(
279+
message: "Remove display name argument",
280+
changes: [
281+
.replace(oldSourceCode: #""""#, newSourceCode: "")
282+
]),
283+
ExpectedFixIt(
284+
message: "Add display name",
285+
changes: [
286+
.replace(
287+
oldSourceCode: #""""#,
288+
newSourceCode: #""\#(EditorPlaceholderExprSyntax("display name"))""#)
289+
])
290+
]
291+
)
244292
]
245293
}
246294

0 commit comments

Comments
 (0)