Skip to content

Commit 6a5fc6d

Browse files
committed
Bit more cheese
1 parent eda41a9 commit 6a5fc6d

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed

Sources/TestingMacros/ConditionMacro.swift

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -454,57 +454,53 @@ extension ExitTestConditionMacro {
454454
"""
455455
)
456456

457-
// Create the accessor function for the test content record.
458-
let accessorDecl: DeclSyntax = """
459-
private nonisolated static let accessor: Testing.__TestContentRecordAccessor = { outValue, type, hint in
460-
Testing.ExitTest.__store(
461-
\(exitTestIDExpr),
462-
\(bodyThunkName),
463-
into: outValue,
464-
asTypeAt: type,
465-
withHintAt: hint
466-
)
467-
}
468-
"""
469-
470457
// Create a local type that can be discovered at runtime and which contains
471458
// the exit test body.
472-
let className = context.makeUniqueName("__🟡$")
473-
let testContentRecordDecl = makeTestContentRecordDecl(
474-
named: .identifier("testContentRecord"),
475-
in: TypeSyntax(IdentifierTypeSyntax(name: className)),
476-
ofKind: .exitTest,
477-
accessingWith: .identifier("accessor")
478-
)
459+
let enumName = context.makeUniqueName("")
460+
do {
461+
// Create the test content record.
462+
let testContentRecordDecl = makeTestContentRecordDecl(
463+
named: .identifier("testContentRecord"),
464+
in: TypeSyntax(IdentifierTypeSyntax(name: enumName)),
465+
ofKind: .exitTest,
466+
accessingWith: .identifier("accessor")
467+
)
479468

469+
// Create another local type for legacy test discovery.
470+
var recordDecl: DeclSyntax?
480471
#if !SWT_NO_LEGACY_TEST_DISCOVERY
481-
decls.append(
482-
"""
483-
@available(*, deprecated, message: "This type is an implementation detail of the testing library. Do not use it directly.")
484-
final class \(className): Testing.__TestContentRecordContainer {
485-
\(accessorDecl)
486-
487-
\(testContentRecordDecl)
488-
472+
let className = context.makeUniqueName("__🟡$")
473+
recordDecl = """
474+
private final class \(className): Testing.__TestContentRecordContainer {
489475
override nonisolated class var __testContentRecord: Testing.__TestContentRecord {
490-
testContentRecord
476+
\(enumName).testContentRecord
491477
}
492478
}
493479
"""
494-
)
495-
#else
496-
decls.append(
497-
"""
498-
@available(*, deprecated, message: "This type is an implementation detail of the testing library. Do not use it directly.")
499-
final class \(className) {
500-
\(accessorDecl)
501-
502-
\(testContentRecordDecl)
503-
}
504-
"""
505-
)
506480
#endif
507481

482+
decls.append(
483+
"""
484+
@available(*, deprecated, message: "This type is an implementation detail of the testing library. Do not use it directly.")
485+
enum \(enumName) {
486+
private nonisolated static let accessor: Testing.__TestContentRecordAccessor = { outValue, type, hint in
487+
Testing.ExitTest.__store(
488+
\(exitTestIDExpr),
489+
\(bodyThunkName),
490+
into: outValue,
491+
asTypeAt: type,
492+
withHintAt: hint
493+
)
494+
}
495+
496+
\(testContentRecordDecl)
497+
498+
\(recordDecl)
499+
}
500+
"""
501+
)
502+
}
503+
508504
arguments[trailingClosureIndex].expression = ExprSyntax(
509505
ClosureExprSyntax {
510506
for decl in decls {

0 commit comments

Comments
 (0)