Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,6 @@ extension Array where Element == PackageDescription.SwiftSetting {

.enableUpcomingFeature("MemberImportVisibility"),

// This setting is enabled in the package, but not in the toolchain build
// (via CMake). Enabling it is dependent on acceptance of the @section
// proposal via Swift Evolution.
.enableExperimentalFeature("SymbolLinkageMarkers"),

.enableUpcomingFeature("InferIsolatedConformances"),

// When building as a package, the macro plugin always builds as an
Expand All @@ -410,6 +405,21 @@ extension Array where Element == PackageDescription.SwiftSetting {
.define("SWT_NO_LIBDISPATCH", .whenEmbedded()),
]

#if compiler(>=6.3)
#if !SWT_FIXED_85411
// Work around https://github.com/swiftlang/swift/issues/85411
result += [
.enableExperimentalFeature("CompileTimeValuesPreview"),
]
#endif
#else
// This setting is enabled in the package, but not in the toolchain build
// (via CMake). The @section attribute is formally supported in Swift 6.3.
result += [
.enableExperimentalFeature("SymbolLinkageMarkers"),
]
#endif

return result
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/TestingMacros/ConditionMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public import SwiftSyntax
import SwiftSyntaxBuilder
public import SwiftSyntaxMacros

#if !hasFeature(SymbolLinkageMarkers) && SWT_NO_LEGACY_TEST_DISCOVERY
#error("Platform-specific misconfiguration: either SymbolLinkageMarkers or legacy test discovery is required to expand #expect(processExitsWith:)")
#if !((compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)) || hasFeature(SymbolLinkageMarkers)) && SWT_NO_LEGACY_TEST_DISCOVERY
#error("Platform-specific misconfiguration: either CompileTimeValuesPreview, SymbolLinkageMarkers, or legacy test discovery is required to expand #expect(processExitsWith:)")
#endif

/// A protocol containing the common implementation for the expansions of the
Expand Down
4 changes: 2 additions & 2 deletions Sources/TestingMacros/SuiteDeclarationMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public import SwiftSyntax
import SwiftSyntaxBuilder
public import SwiftSyntaxMacros

#if !hasFeature(SymbolLinkageMarkers) && SWT_NO_LEGACY_TEST_DISCOVERY
#error("Platform-specific misconfiguration: either SymbolLinkageMarkers or legacy test discovery is required to expand @Suite")
#if !((compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)) || hasFeature(SymbolLinkageMarkers)) && SWT_NO_LEGACY_TEST_DISCOVERY
#error("Platform-specific misconfiguration: either CompileTimeValuesPreview, SymbolLinkageMarkers, or legacy test discovery is required to expand @Suite")
#endif

/// A type describing the expansion of the `@Suite` attribute macro.
Expand Down
18 changes: 17 additions & 1 deletion Sources/TestingMacros/Support/TestContentGeneration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,23 @@ func makeTestContentRecordDecl(named name: TokenSyntax, in typeName: TypeSyntax?
)
"""

#if hasFeature(SymbolLinkageMarkers)
#if compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)
result = """
#if compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)
#if objectFormat(MachO)
@section("__DATA_CONST,__swift5_tests")
#elseif objectFormat(ELF) || objectFormat(Wasm)
@section("swift5_tests")
#elseif objectFormat(COFF)
@section(".sw5test$B")
#else
@Testing.__testing(warning: "Platform-specific implementation missing: object format unknown")
#endif
@used
#endif
\(result)
"""
#elseif hasFeature(SymbolLinkageMarkers)
result = """
#if hasFeature(SymbolLinkageMarkers)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
Expand Down
4 changes: 2 additions & 2 deletions Sources/TestingMacros/TestDeclarationMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public import SwiftSyntax
import SwiftSyntaxBuilder
public import SwiftSyntaxMacros

#if !hasFeature(SymbolLinkageMarkers) && SWT_NO_LEGACY_TEST_DISCOVERY
#error("Platform-specific misconfiguration: either SymbolLinkageMarkers or legacy test discovery is required to expand @Test")
#if !((compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)) || hasFeature(SymbolLinkageMarkers)) && SWT_NO_LEGACY_TEST_DISCOVERY
#error("Platform-specific misconfiguration: either CompileTimeValuesPreview, SymbolLinkageMarkers, or legacy test discovery is required to expand @Test")
#endif

/// A type describing the expansion of the `@Test` attribute macro.
Expand Down
4 changes: 3 additions & 1 deletion Tests/TestingMacrosTests/TestDeclarationMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ struct TestDeclarationMacroTests {
func differentFunctionTypes(input: String, expectedTypeName: String?, otherCode: String?) throws {
let (output, _) = try parse(input)

#if hasFeature(SymbolLinkageMarkers)
#if compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)
#expect(output.contains("@section"))
#elseif hasFeature(SymbolLinkageMarkers)
#expect(output.contains("@_section"))
#endif
#if !SWT_NO_LEGACY_TEST_DISCOVERY
Expand Down
17 changes: 15 additions & 2 deletions Tests/TestingTests/DiscoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct DiscoveryTests {
}
#endif

#if !SWT_NO_DYNAMIC_LINKING && hasFeature(SymbolLinkageMarkers)
#if !SWT_NO_DYNAMIC_LINKING && ((compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)) || hasFeature(SymbolLinkageMarkers))
struct MyTestContent: DiscoverableAsTestContent {
typealias TestContentAccessorHint = UInt32

Expand All @@ -80,6 +80,18 @@ struct DiscoveryTests {
record.context
}

#if compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)
#if objectFormat(MachO)
@section("__DATA_CONST,__swift5_tests")
#elseif objectFormat(ELF) || objectFormat(Wasm)
@section("swift5_tests")
#elseif objectFormat(COFF)
@section(".sw5test$B")
#else
@__testing(warning: "Platform-specific implementation missing: object format unknown")
#endif
@used
#else
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
@_section("__DATA_CONST,__swift5_tests")
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || os(WASI)
Expand All @@ -90,6 +102,7 @@ struct DiscoveryTests {
@__testing(warning: "Platform-specific implementation missing: test content section name unavailable")
#endif
@_used
#endif
private static let record: __TestContentRecord = (
0xABCD1234,
0,
Expand Down Expand Up @@ -144,7 +157,7 @@ struct DiscoveryTests {
}
#endif

#if !SWT_NO_LEGACY_TEST_DISCOVERY && hasFeature(SymbolLinkageMarkers)
#if !SWT_NO_LEGACY_TEST_DISCOVERY && ((compiler(>=6.3) && hasFeature(CompileTimeValuesPreview)) || hasFeature(SymbolLinkageMarkers))
@Test("Legacy test discovery finds the same number of tests") func discoveredTestCount() async {
let oldFlag = Environment.variable(named: "SWT_USE_LEGACY_TEST_DISCOVERY")
defer {
Expand Down