testing: Update CliTest Support.
And add tests for Cli preprocessing. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
+17
-14
@@ -301,43 +301,47 @@ public struct CliTestDeclarationMacro: PeerMacro, Sendable {
|
||||
in context: some MacroExpansionContext
|
||||
) throws -> [DeclSyntax] {
|
||||
|
||||
let test_name = declaration.cast(FunctionDeclSyntax.self).name
|
||||
|
||||
let cli_test_expected_output = node.leadingTrivia.filter({ $0.isComment }).map({
|
||||
doc_shrink("\($0)")
|
||||
}).joined(separator: "\\n")
|
||||
|
||||
let cli_test_driver_thunk_name = context.makeUniqueName(
|
||||
declaration.cast(FunctionDeclSyntax.self).name.text + "_thunk_")
|
||||
|
||||
let (expected_decl, expected_label) = if cli_test_expected_output.isEmpty {
|
||||
("let expected = \"\(test_name)\"", "withExpectedPath:")
|
||||
} else {
|
||||
("let expected = \"\(cli_test_expected_output)\"", "withExpected:")
|
||||
}
|
||||
|
||||
let cli_test_driver_thunk: DeclSyntax = """
|
||||
@Sendable private func \(cli_test_driver_thunk_name)() async throws {
|
||||
let expected = "\(raw: cli_test_expected_output)"
|
||||
\(raw: expected_decl)
|
||||
|
||||
_ = unsafe try await Testing.__requiringUnsafe(
|
||||
Testing.__requiringTry(
|
||||
Testing.__requiringAwait(swiftCliTestRunner(\(declaration.cast(FunctionDeclSyntax.self).name), expected))))
|
||||
Testing.__requiringAwait(swiftCliTestRunner(\(test_name), \(raw: expected_label) expected))))
|
||||
}
|
||||
"""
|
||||
|
||||
let cli_test_driver_generator_name = context.makeUniqueName(
|
||||
declaration.cast(FunctionDeclSyntax.self).name.text + "_generator_")
|
||||
let cli_test_driver_generator_name = context.makeUniqueName(test_name.text + "_generator_")
|
||||
let cli_test_driver_generator: DeclSyntax = """
|
||||
@Sendable private func \(cli_test_driver_generator_name)() async -> Testing.Test {
|
||||
return .__function(
|
||||
named: "xxxxxxxx()",
|
||||
named: "\(test_name)",
|
||||
in: nil,
|
||||
xcTestCompatibleSelector: Testing.__xcTestCompatibleSelector("xxxxxx:"),
|
||||
xcTestCompatibleSelector: Testing.__xcTestCompatibleSelector("\(test_name)"),
|
||||
traits: [],
|
||||
sourceLocation: Testing.SourceLocation(
|
||||
fileID: "Tests/CliTests/Cli.swift",
|
||||
filePath: "/Users/hawkinsw/code/p4ce/Tests/p4rseTests/CliTests/Cli.swift", line: 359,
|
||||
column: 2),
|
||||
sourceLocation: Testing.SourceLocation.__here(),
|
||||
parameters: [],
|
||||
testFunction: \(cli_test_driver_thunk_name)
|
||||
)
|
||||
}
|
||||
"""
|
||||
|
||||
let cli_test_driver_accessor_name = context.makeUniqueName(
|
||||
declaration.cast(FunctionDeclSyntax.self).name.text + "_accessor_")
|
||||
let cli_test_driver_accessor_name = context.makeUniqueName(test_name.text + "_accessor_")
|
||||
let cli_test_driver_accessor: DeclSyntax = """
|
||||
private nonisolated let \(cli_test_driver_accessor_name): Accessor = { outValue, type, _, _ in
|
||||
|
||||
@@ -357,8 +361,7 @@ public struct CliTestDeclarationMacro: PeerMacro, Sendable {
|
||||
)
|
||||
"""
|
||||
|
||||
let cli_test_driver_content_container_name = context.makeUniqueName(
|
||||
declaration.cast(FunctionDeclSyntax.self).name.text + "__🟡$_container_")
|
||||
let cli_test_driver_content_container_name = context.makeUniqueName(test_name.text + "__🟡$_container_")
|
||||
let cli_test_driver_container: DeclSyntax = """
|
||||
struct \(cli_test_driver_content_container_name): Testing.__TestContentRecordContainer {
|
||||
nonisolated static var __testContentRecord: TestContentRecord {
|
||||
|
||||
Reference in New Issue
Block a user