You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The testable module for a macro will only build for the host platform which currently causes somewhat confusing issues if e.g. one is running tests for iOS in Xcode. This change will allow us to skip the tests if they are being run in an unsupported configuration.
rdar://110541100
Copy file name to clipboardExpand all lines: Sources/Workspace/InitPackage.swift
+14-2Lines changed: 14 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -641,14 +641,19 @@ public final class InitPackage {
641
641
import SwiftSyntaxMacros
642
642
import SwiftSyntaxMacrosTestSupport
643
643
import XCTest
644
+
645
+
// Macro implementations build for the host, so the corresponding module is not available when cross-compiling. Cross-compiled tests may still make use of the macro itself in end-to-end tests.
646
+
#if canImport(\##(moduleName)Macros)
644
647
import \##(moduleName)Macros
645
648
646
649
let testMacros: [String: Macro.Type] = [
647
650
"stringify": StringifyMacro.self,
648
651
]
652
+
#endif
649
653
650
654
final class \##(moduleName)Tests: XCTestCase {
651
-
func testMacro() {
655
+
func testMacro() throws {
656
+
#if canImport(\##(moduleName)Macros)
652
657
assertMacroExpansion(
653
658
"""
654
659
#stringify(a + b)
@@ -658,9 +663,13 @@ public final class InitPackage {
658
663
""",
659
664
macros: testMacros
660
665
)
666
+
#else
667
+
throw XCTSkip("macros are only supported when running tests for the host platform")
668
+
#endif
661
669
}
662
670
663
-
func testMacroWithStringLiteral() {
671
+
func testMacroWithStringLiteral() throws {
672
+
#if canImport(\##(moduleName)Macros)
664
673
assertMacroExpansion(
665
674
#"""
666
675
#stringify("Hello, \(name)")
@@ -670,6 +679,9 @@ public final class InitPackage {
670
679
"""#,
671
680
macros: testMacros
672
681
)
682
+
#else
683
+
throw XCTSkip("macros are only supported when running tests for the host platform")
0 commit comments