@@ -25,7 +25,7 @@ public struct SuiteDeclarationMacro: MemberMacro, PeerMacro, Sendable {
2525 guard _diagnoseIssues ( with: declaration, suiteAttribute: node, in: context) else {
2626 return [ ]
2727 }
28- return _createTestContainerDecls ( for: declaration, suiteAttribute: node, in: context)
28+ return _createSuiteDecls ( for: declaration, suiteAttribute: node, in: context)
2929 }
3030
3131 public static func expansion(
@@ -97,8 +97,7 @@ public struct SuiteDeclarationMacro: MemberMacro, PeerMacro, Sendable {
9797 return !diagnostics. lazy. map ( \. severity) . contains ( . error)
9898 }
9999
100- /// Create a declaration for a type that conforms to the `__TestContainer`
101- /// protocol and which contains the given suite type.
100+ /// Create the declarations necessary to discover a suite at runtime.
102101 ///
103102 /// - Parameters:
104103 /// - declaration: The type declaration the result should encapsulate.
@@ -107,7 +106,7 @@ public struct SuiteDeclarationMacro: MemberMacro, PeerMacro, Sendable {
107106 ///
108107 /// - Returns: An array of declarations providing runtime information about
109108 /// the test suite type `declaration`.
110- private static func _createTestContainerDecls (
109+ private static func _createSuiteDecls (
111110 for declaration: some DeclGroupSyntax ,
112111 suiteAttribute: AttributeSyntax ,
113112 in context: some MacroExpansionContext
@@ -127,28 +126,48 @@ public struct SuiteDeclarationMacro: MemberMacro, PeerMacro, Sendable {
127126 // Parse the @Suite attribute.
128127 let attributeInfo = AttributeInfo ( byParsing: suiteAttribute, on: declaration, in: context)
129128
130- // The emitted type must be public or the compiler can optimize it away
131- // (since it is not actually used anywhere that the compiler can see.)
132- //
133- // The emitted type must be deprecated to avoid causing warnings in client
134- // code since it references the suite metatype, which may be deprecated
135- // to allow test functions to validate deprecated APIs. The emitted type is
136- // also annotated unavailable, since it's meant only for use by the testing
137- // library at runtime. The compiler does not allow combining 'unavailable'
138- // and 'deprecated' into a single availability attribute: rdar://111329796
139- let typeName = declaration. type. tokens ( viewMode: . fixedUp) . map ( \. textWithoutBackticks) . joined ( )
140- let enumName = context. makeUniqueName ( " __🟠$test_container__suite__ \( typeName) " )
129+ let generatorName = context. makeUniqueName ( " generator " )
130+ result. append (
131+ """
132+ @available(*, deprecated, message: " This property is an implementation detail of the testing library. Do not use it directly. " )
133+ @Sendable private static func \( generatorName) () async -> Testing.Test {
134+ .__type(
135+ \( declaration. type. trimmed) .self,
136+ \( raw: attributeInfo. functionArgumentList ( in: context) )
137+ )
138+ }
139+ """
140+ )
141+
142+ let accessorName = context. makeUniqueName ( " accessor " )
143+ result. append (
144+ """
145+ @available(*, deprecated, message: " This property is an implementation detail of the testing library. Do not use it directly. " )
146+ private nonisolated static let \( accessorName) : Testing.__TestContentRecordAccessor = { outValue, type, _ in
147+ Testing.Test.__store( \( generatorName) , into: outValue, asTypeAt: type)
148+ }
149+ """
150+ )
151+
152+ let testContentRecordName = context. makeUniqueName ( " testContentRecord " )
153+ result. append (
154+ makeTestContentRecordDecl (
155+ named: testContentRecordName,
156+ in: declaration. type,
157+ ofKind: . testDeclaration,
158+ accessingWith: accessorName,
159+ context: attributeInfo. testContentRecordFlags
160+ )
161+ )
162+
163+ // Emit a type that contains a reference to the test content record.
164+ let className = context. makeUniqueName ( " __🟡$ " )
141165 result. append (
142166 """
143167 @available(*, deprecated, message: " This type is an implementation detail of the testing library. Do not use it directly. " )
144- enum \( enumName) : Testing.__TestContainer {
145- static var __tests: [Testing.Test] {
146- get async {[
147- .__type(
148- \( declaration. type. trimmed) .self,
149- \( raw: attributeInfo. functionArgumentList ( in: context) )
150- )
151- ]}
168+ final class \( className) : Testing.__TestContentRecordContainer {
169+ override nonisolated class var __testContentRecord: Testing.__TestContentRecord {
170+ \( testContentRecordName)
152171 }
153172 }
154173 """
0 commit comments