Skip to content

Commit 5344f13

Browse files
authored
test: added swift-syntax temporary fix for extension macros testing (#33)
Available at https://github.com/soumyamahunt/swift-syntax/tree/extension-macro-assert-fix
1 parent 4542ac2 commit 5344f13

8 files changed

Lines changed: 45 additions & 42 deletions

File tree

.spi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version: 1
22
builder:
33
configs:
4-
- documentation_targets: [CodableMacroPlugin, MetaCodable]
4+
- documentation_targets: [MetaCodable, HelperCoders]

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
"editor.unicodeHighlight.allowedCharacters": {
1111
"-": true
1212
},
13+
"swift.disableAutoResolve": true,
14+
"swift.swiftEnvironmentVariables": {
15+
"SWIFT_SYNTAX_EXTENSION_MACRO_FIXED": "true"
16+
},
1317
}

Package.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,19 @@ let package = Package(
4545
),
4646
]
4747
)
48+
49+
if Context.environment["SWIFT_SYNTAX_EXTENSION_MACRO_FIXED"] != nil {
50+
package.dependencies.remove(at: 0)
51+
package.dependencies.append(
52+
.package(
53+
url: "https://github.com/soumyamahunt/swift-syntax.git",
54+
branch: "extension-macro-assert-fix"
55+
)
56+
)
57+
58+
package.targets.forEach { target in
59+
var settings = target.swiftSettings ?? []
60+
settings.append(.define("SWIFT_SYNTAX_EXTENSION_MACRO_FIXED"))
61+
target.swiftSettings = settings
62+
}
63+
}

Tests/MetaCodableTests/CodableTests.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ final class CodableTests: XCTestCase {
104104
case value = "value"
105105
}
106106
}
107-
"""
107+
""",
108+
conformsTo: ["Codable": ["Decodable"]]
108109
)
109110
}
110111

@@ -142,7 +143,8 @@ final class CodableTests: XCTestCase {
142143
case value = "value"
143144
}
144145
}
145-
"""
146+
""",
147+
conformsTo: ["Codable": ["Encodable"]]
146148
)
147149
}
148150

@@ -173,7 +175,8 @@ final class CodableTests: XCTestCase {
173175
func encode(to encoder: Encoder) throws {
174176
}
175177
}
176-
"""
178+
""",
179+
conformsTo: ["Codable": []]
177180
)
178181
}
179182
}
@@ -182,6 +185,9 @@ func assertMacroExpansion(
182185
_ originalSource: String,
183186
expandedSource: String,
184187
diagnostics: [DiagnosticSpec] = [],
188+
conformsTo conformanceMap: [String: [TypeSyntax]] = [
189+
"Codable": ["Decodable", "Encodable"]
190+
],
185191
testModuleName: String = "TestModule",
186192
testFileName: String = "test.swift",
187193
indentationWidth: Trivia = .spaces(4),
@@ -204,6 +210,7 @@ func assertMacroExpansion(
204210
"CodingKeys": CodingKeys.self,
205211
"IgnoreCodingInitialized": IgnoreCodingInitialized.self,
206212
],
213+
conformsTo: conformanceMap,
207214
testModuleName: testModuleName, testFileName: testFileName,
208215
indentationWidth: indentationWidth,
209216
file: file, line: line
@@ -221,14 +228,9 @@ extension DiagnosticSpec {
221228
return .init(
222229
id: MessageID(
223230
domain: "SwiftSyntaxMacroExpansion",
224-
id: "accessorMacroOnVariableWithMultipleBindings"
231+
id: "peerMacroOnVariableWithMultipleBindings"
225232
),
226-
message:
227-
"swift-syntax applies macros syntactically and"
228-
+ " there is no way to represent a variable declaration"
229-
+ " with multiple bindings that have accessors syntactically."
230-
+ " While the compiler allows this expansion,"
231-
+ " swift-syntax cannot represent it and thus disallows it.",
233+
message: "peer macro can only be applied to a single variable",
232234
line: line, column: column
233235
)
234236
}

Tests/MetaCodableTests/CodedAtTests.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,7 @@ final class CodedAtTests: XCTestCase {
5151
}
5252
""",
5353
diagnostics: [
54-
.multiBinding(line: 2, column: 5),
55-
.init(
56-
id: CodedAt.misuseID,
57-
message:
58-
"@CodedAt can't be used with grouped variables declaration",
59-
line: 2, column: 5,
60-
fixIts: [
61-
.init(message: "Remove @CodedAt attribute")
62-
]
63-
),
54+
.multiBinding(line: 2, column: 5)
6455
]
6556
)
6657
}

Tests/MetaCodableTests/GroupedMutableVariableTests.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ final class GroupedMutableVariableTests: XCTestCase {
5050
case three = "three"
5151
}
5252
}
53-
""",
54-
diagnostics: [.multiBinding(line: 4, column: 5)]
53+
"""
5554
)
5655
}
5756

@@ -106,8 +105,7 @@ final class GroupedMutableVariableTests: XCTestCase {
106105
case three = "three"
107106
}
108107
}
109-
""",
110-
diagnostics: [.multiBinding(line: 4, column: 5)]
108+
"""
111109
)
112110
}
113111

@@ -199,8 +197,7 @@ final class GroupedMutableVariableTests: XCTestCase {
199197
case three = "three"
200198
}
201199
}
202-
""",
203-
diagnostics: [.multiBinding(line: 4, column: 5)]
200+
"""
204201
)
205202
}
206203

@@ -255,8 +252,7 @@ final class GroupedMutableVariableTests: XCTestCase {
255252
case three = "three"
256253
}
257254
}
258-
""",
259-
diagnostics: [.multiBinding(line: 4, column: 5)]
255+
"""
260256
)
261257
}
262258

@@ -311,8 +307,7 @@ final class GroupedMutableVariableTests: XCTestCase {
311307
case three = "three"
312308
}
313309
}
314-
""",
315-
diagnostics: [.multiBinding(line: 4, column: 5)]
310+
"""
316311
)
317312
}
318313
}

Tests/MetaCodableTests/GroupedVariableTests.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ final class GroupedVariableTests: XCTestCase {
5050
case three = "three"
5151
}
5252
}
53-
""",
54-
diagnostics: [.multiBinding(line: 4, column: 5)]
53+
"""
5554
)
5655
}
5756

@@ -97,8 +96,7 @@ final class GroupedVariableTests: XCTestCase {
9796
case two = "two"
9897
}
9998
}
100-
""",
101-
diagnostics: [.multiBinding(line: 4, column: 5)]
99+
"""
102100
)
103101
}
104102

@@ -186,8 +184,7 @@ final class GroupedVariableTests: XCTestCase {
186184
case three = "three"
187185
}
188186
}
189-
""",
190-
diagnostics: [.multiBinding(line: 4, column: 5)]
187+
"""
191188
)
192189
}
193190

@@ -233,8 +230,7 @@ final class GroupedVariableTests: XCTestCase {
233230
case three = "three"
234231
}
235232
}
236-
""",
237-
diagnostics: [.multiBinding(line: 4, column: 5)]
233+
"""
238234
)
239235
}
240236

@@ -280,8 +276,7 @@ final class GroupedVariableTests: XCTestCase {
280276
case three = "three"
281277
}
282278
}
283-
""",
284-
diagnostics: [.multiBinding(line: 4, column: 5)]
279+
"""
285280
)
286281
}
287282
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"scripts": {
2222
"build": "npm exec --package=swiftylab-ci -- build.js",
23-
"test": "npm exec --package=swiftylab-ci -- test.js",
23+
"test": "SWIFT_SYNTAX_EXTENSION_MACRO_FIXED=true npm exec --package=swiftylab-ci -- test.js",
2424
"archive": "echo implement",
2525
"generate": "echo implement",
2626
"format": "npm exec --package=swiftylab-ci -- format.js",

0 commit comments

Comments
 (0)