|
11 | 11 | public import SwiftSyntax |
12 | 12 | public import SwiftSyntaxMacros |
13 | 13 |
|
| 14 | +#if !hasFeature(SymbolLinkageMarkers) && SWT_NO_LEGACY_TEST_DISCOVERY |
| 15 | +#error("Platform-specific misconfiguration: either SymbolLinkageMarkers or legacy test discovery is required to expand #expect(exitsWith:)") |
| 16 | +#endif |
| 17 | + |
14 | 18 | /// A protocol containing the common implementation for the expansions of the |
15 | 19 | /// `#expect()` and `#require()` macros. |
16 | 20 | /// |
@@ -452,42 +456,59 @@ extension ExitTestConditionMacro { |
452 | 456 |
|
453 | 457 | // Create a local type that can be discovered at runtime and which contains |
454 | 458 | // the exit test body. |
455 | | - let className = context.makeUniqueName("__🟡$") |
456 | | - let testContentRecordDecl = makeTestContentRecordDecl( |
457 | | - named: .identifier("testContentRecord"), |
458 | | - in: TypeSyntax(IdentifierTypeSyntax(name: className)), |
459 | | - ofKind: .exitTest, |
460 | | - accessingWith: .identifier("accessor") |
461 | | - ) |
462 | | - |
463 | | - decls.append( |
464 | | - """ |
465 | | - @available(*, deprecated, message: "This type is an implementation detail of the testing library. Do not use it directly.") |
466 | | - final class \(className): Testing.__TestContentRecordContainer { |
467 | | - private nonisolated static let accessor: Testing.__TestContentRecordAccessor = { outValue, type, hint in |
468 | | - Testing.ExitTest.__store( |
469 | | - \(exitTestIDExpr), |
470 | | - \(bodyThunkName), |
471 | | - into: outValue, |
472 | | - asTypeAt: type, |
473 | | - withHintAt: hint |
474 | | - ) |
475 | | - } |
476 | | -
|
477 | | - \(testContentRecordDecl) |
| 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 | + ) |
478 | 468 |
|
| 469 | + // Create another local type for legacy test discovery. |
| 470 | + var recordDecl: DeclSyntax? |
| 471 | +#if !SWT_NO_LEGACY_TEST_DISCOVERY |
| 472 | + let className = context.makeUniqueName("__🟡$") |
| 473 | + recordDecl = """ |
| 474 | + private final class \(className): Testing.__TestContentRecordContainer { |
479 | 475 | override nonisolated class var __testContentRecord: Testing.__TestContentRecord { |
480 | | - testContentRecord |
| 476 | + \(enumName).testContentRecord |
481 | 477 | } |
482 | 478 | } |
483 | 479 | """ |
484 | | - ) |
| 480 | +#endif |
| 481 | + |
| 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 | + } |
485 | 503 |
|
486 | 504 | arguments[trailingClosureIndex].expression = ExprSyntax( |
487 | 505 | ClosureExprSyntax { |
488 | 506 | for decl in decls { |
489 | | - CodeBlockItemSyntax(item: .decl(decl)) |
490 | | - .with(\.trailingTrivia, .newline) |
| 507 | + CodeBlockItemSyntax( |
| 508 | + leadingTrivia: .newline, |
| 509 | + item: .decl(decl), |
| 510 | + trailingTrivia: .newline |
| 511 | + ) |
491 | 512 | } |
492 | 513 | } |
493 | 514 | ) |
|
0 commit comments