diff --git a/Sources/Testing/Expectations/ExpectationChecking+Macro.swift b/Sources/Testing/Expectations/ExpectationChecking+Macro.swift index 3a190e679..9dfc5ace7 100644 --- a/Sources/Testing/Expectations/ExpectationChecking+Macro.swift +++ b/Sources/Testing/Expectations/ExpectationChecking+Macro.swift @@ -1175,6 +1175,7 @@ public func __checkClosureCall( /// /// - Warning: This function is used to implement the `#expect()` and /// `#require()` macros. Do not call it directly. +#if SWT_FIXED_154221449 @_spi(Experimental) public func __checkClosureCall( identifiedBy exitTestID: (UInt64, UInt64, UInt64, UInt64), @@ -1199,6 +1200,32 @@ public func __checkClosureCall( sourceLocation: sourceLocation ) } +#else +@_spi(Experimental) +public func __checkClosureCall( + identifiedBy exitTestID: (UInt64, UInt64, UInt64, UInt64), + encodingCapturedValues capturedValues: repeat each T, + processExitsWith expectedExitCondition: ExitTest.Condition, + observing observedValues: [any PartialKeyPath & Sendable] = [], + performing _: @convention(c) () -> Void, + expression: __Expression, + comments: @autoclosure () -> [Comment], + isRequired: Bool, + isolation: isolated (any Actor)? = #isolation, + sourceLocation: SourceLocation +) async -> Result where repeat each T: Codable & Sendable { + await callExitTest( + identifiedBy: exitTestID, + encodingCapturedValues: Array(repeat each capturedValues), + processExitsWith: expectedExitCondition, + observing: observedValues, + expression: expression, + comments: comments(), + isRequired: isRequired, + sourceLocation: sourceLocation + ) +} +#endif #endif // MARK: - diff --git a/Sources/TestingMacros/ConditionMacro.swift b/Sources/TestingMacros/ConditionMacro.swift index 0ef0970e9..9d0c4f15f 100644 --- a/Sources/TestingMacros/ConditionMacro.swift +++ b/Sources/TestingMacros/ConditionMacro.swift @@ -98,7 +98,20 @@ extension ConditionMacro { if let trailingClosureIndex { // Assume that the comment, if present is the last argument in the // argument list prior to the trailing closure that has no label. +#if SWT_FIXED_154221449 commentIndex = macroArguments[.. 1 { // If there is no trailing closure argument and there is more than one // argument, then the comment is the last argument with no label (and also @@ -547,6 +560,7 @@ extension ExitTestConditionMacro { var leadingArguments = [ Argument(label: "identifiedBy", expression: idExpr), ] +#if SWT_FIXED_154221449 if !capturedValues.isEmpty { leadingArguments.append( Argument( @@ -559,6 +573,19 @@ extension ExitTestConditionMacro { ) ) } +#else + if let firstCapturedValue = capturedValues.first { + leadingArguments.append( + Argument( + label: "encodingCapturedValues", + expression: firstCapturedValue.typeCheckedExpression + ) + ) + leadingArguments += capturedValues.dropFirst() + .map(\.typeCheckedExpression) + .map { Argument(expression: $0) } + } +#endif arguments = leadingArguments + arguments // Replace the exit test body (as an argument to the macro) with a stub diff --git a/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift b/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift index 80c216854..08536aa69 100644 --- a/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift +++ b/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift @@ -36,7 +36,7 @@ struct CapturedValueInfo { /// The expression to assign to the captured value with type-checking applied. var typeCheckedExpression: ExprSyntax { - #"#__capturedValue(\#(expression.trimmed), \#(literal: name.trimmedDescription), (\#(type.trimmed)).self)"# + #"#__capturedValue(\#(expression.trimmed), \#(literal: name.trimmedDescription), \#(type.trimmed).self)"# } init(_ capture: ClosureCaptureSyntax, in context: some MacroExpansionContext) {