-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from num42/feature/add_diagnostics_and_allow_em…
…pty_dependency_structs Feature/add diagnostics and allow empty dependency structs
- Loading branch information
Showing
7 changed files
with
275 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@attached(member, names: arbitrary) | ||
public macro AutoRegisterable() = #externalMacro( | ||
module: "AutoRegisterableMacros", | ||
type: "AutoRegisterableMacro" | ||
module: "AutoRegisterableMacros", | ||
type: "AutoRegisterableMacro" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Tests/AutoRegisterableTests/AutoRegisterableDiagnosticsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import MacroTester | ||
import SwiftSyntaxMacros | ||
import SwiftSyntaxMacrosTestSupport | ||
import XCTest | ||
|
||
#if canImport(AutoRegisterableMacros) | ||
import AutoRegisterableMacros | ||
|
||
final class AutoRegisterableDiagnosticsTests: XCTestCase { | ||
let testMacros: [String: Macro.Type] = [ | ||
"AutoRegisterable": AutoRegisterableMacro.self, | ||
] | ||
|
||
func testEnumThrowsError() throws { | ||
assertMacroExpansion( | ||
""" | ||
@AutoRegisterable | ||
enum AnEnum {} | ||
""", | ||
expandedSource: """ | ||
enum AnEnum {} | ||
""", | ||
diagnostics: [ | ||
.init( | ||
message: AutoRegisterableMacro.MacroError.requiresStructOrClass.description, | ||
line: 1, | ||
column: 1 | ||
), | ||
], | ||
macros: testMacros | ||
) | ||
} | ||
|
||
func testStructHasNoDependencies() throws { | ||
assertMacroExpansion( | ||
""" | ||
@AutoRegisterable | ||
struct AStruct {} | ||
""", | ||
expandedSource: """ | ||
struct AStruct {} | ||
""", | ||
diagnostics: [ | ||
.init( | ||
message: AutoRegisterableMacro.MacroError.requiresDependencies.description, | ||
line: 1, | ||
column: 1 | ||
), | ||
], | ||
macros: testMacros | ||
) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.