-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathIssue2206Tests.swift
More file actions
41 lines (37 loc) · 1.16 KB
/
Issue2206Tests.swift
File metadata and controls
41 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacroExpansion
import SwiftSyntaxMacros
import SwiftSyntaxMacrosTestSupport
import XCTest
private struct NoOpMemberMacro: MemberMacro {
static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
conformingTo protocols: [TypeSyntax],
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
return []
}
}
final class Issue2206Tests: XCTestCase {
private let indentationWidth: Trivia = .spaces(2)
func testMemberMacroOnVariable() {
// Issue #2206: assertMacroExpansion should emit an error if member macro is applied to declaration that can’t have members
// Currently this is expected to FAIL because the diagnostic is swallowed.
assertMacroExpansion(
"""
@Test
var x: Int
""",
expandedSource: """
var x: Int
""",
diagnostics: [
DiagnosticSpec(message: "macro 'Test' can only be applied to a struct, enum, class, extension, or actor", line: 1, column: 1)
],
macros: ["Test": NoOpMemberMacro.self],
indentationWidth: indentationWidth
)
}
}