Skip to content

Commit

Permalink
test: added swift-syntax temporary fix for extension macros testing (
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyamahunt committed Nov 3, 2023
1 parent 4542ac2 commit 5344f13
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .spi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [CodableMacroPlugin, MetaCodable]
- documentation_targets: [MetaCodable, HelperCoders]
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
"editor.unicodeHighlight.allowedCharacters": {
"-": true
},
"swift.disableAutoResolve": true,
"swift.swiftEnvironmentVariables": {
"SWIFT_SYNTAX_EXTENSION_MACRO_FIXED": "true"
},
}
16 changes: 16 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ let package = Package(
),
]
)

if Context.environment["SWIFT_SYNTAX_EXTENSION_MACRO_FIXED"] != nil {
package.dependencies.remove(at: 0)
package.dependencies.append(
.package(
url: "https://github.com/soumyamahunt/swift-syntax.git",
branch: "extension-macro-assert-fix"
)
)

package.targets.forEach { target in
var settings = target.swiftSettings ?? []
settings.append(.define("SWIFT_SYNTAX_EXTENSION_MACRO_FIXED"))
target.swiftSettings = settings
}
}
22 changes: 12 additions & 10 deletions Tests/MetaCodableTests/CodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ final class CodableTests: XCTestCase {
case value = "value"
}
}
"""
""",
conformsTo: ["Codable": ["Decodable"]]
)
}

Expand Down Expand Up @@ -142,7 +143,8 @@ final class CodableTests: XCTestCase {
case value = "value"
}
}
"""
""",
conformsTo: ["Codable": ["Encodable"]]
)
}

Expand Down Expand Up @@ -173,7 +175,8 @@ final class CodableTests: XCTestCase {
func encode(to encoder: Encoder) throws {
}
}
"""
""",
conformsTo: ["Codable": []]
)
}
}
Expand All @@ -182,6 +185,9 @@ func assertMacroExpansion(
_ originalSource: String,
expandedSource: String,
diagnostics: [DiagnosticSpec] = [],
conformsTo conformanceMap: [String: [TypeSyntax]] = [
"Codable": ["Decodable", "Encodable"]
],
testModuleName: String = "TestModule",
testFileName: String = "test.swift",
indentationWidth: Trivia = .spaces(4),
Expand All @@ -204,6 +210,7 @@ func assertMacroExpansion(
"CodingKeys": CodingKeys.self,
"IgnoreCodingInitialized": IgnoreCodingInitialized.self,
],
conformsTo: conformanceMap,
testModuleName: testModuleName, testFileName: testFileName,
indentationWidth: indentationWidth,
file: file, line: line
Expand All @@ -221,14 +228,9 @@ extension DiagnosticSpec {
return .init(
id: MessageID(
domain: "SwiftSyntaxMacroExpansion",
id: "accessorMacroOnVariableWithMultipleBindings"
id: "peerMacroOnVariableWithMultipleBindings"
),
message:
"swift-syntax applies macros syntactically and"
+ " there is no way to represent a variable declaration"
+ " with multiple bindings that have accessors syntactically."
+ " While the compiler allows this expansion,"
+ " swift-syntax cannot represent it and thus disallows it.",
message: "peer macro can only be applied to a single variable",
line: line, column: column
)
}
Expand Down
11 changes: 1 addition & 10 deletions Tests/MetaCodableTests/CodedAtTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ final class CodedAtTests: XCTestCase {
}
""",
diagnostics: [
.multiBinding(line: 2, column: 5),
.init(
id: CodedAt.misuseID,
message:
"@CodedAt can't be used with grouped variables declaration",
line: 2, column: 5,
fixIts: [
.init(message: "Remove @CodedAt attribute")
]
),
.multiBinding(line: 2, column: 5)
]
)
}
Expand Down
15 changes: 5 additions & 10 deletions Tests/MetaCodableTests/GroupedMutableVariableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ final class GroupedMutableVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -106,8 +105,7 @@ final class GroupedMutableVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -199,8 +197,7 @@ final class GroupedMutableVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -255,8 +252,7 @@ final class GroupedMutableVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -311,8 +307,7 @@ final class GroupedMutableVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}
}
Expand Down
15 changes: 5 additions & 10 deletions Tests/MetaCodableTests/GroupedVariableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ final class GroupedVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -97,8 +96,7 @@ final class GroupedVariableTests: XCTestCase {
case two = "two"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -186,8 +184,7 @@ final class GroupedVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -233,8 +230,7 @@ final class GroupedVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}

Expand Down Expand Up @@ -280,8 +276,7 @@ final class GroupedVariableTests: XCTestCase {
case three = "three"
}
}
""",
diagnostics: [.multiBinding(line: 4, column: 5)]
"""
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"scripts": {
"build": "npm exec --package=swiftylab-ci -- build.js",
"test": "npm exec --package=swiftylab-ci -- test.js",
"test": "SWIFT_SYNTAX_EXTENSION_MACRO_FIXED=true npm exec --package=swiftylab-ci -- test.js",
"archive": "echo implement",
"generate": "echo implement",
"format": "npm exec --package=swiftylab-ci -- format.js",
Expand Down

0 comments on commit 5344f13

Please sign in to comment.