Testing with arguments and async closures

Not sure if this has already been reported but I'm having issue with the new swift testing framework where I pass in a parameter that is a closure block. For example

    @Test(
        "Testing with arguments",
        arguments: [SomeStruct.generateSomeData, SomeStruct. anotherGenerateSomeData]
    )
    func testingWithArguments(_ closureBlock: (String) async throws -> SomeStruct) async throws {
        let someStruct = try await closureBlock("")
        // expect ...
    }
struct SomeStruct {
    func generateSomeData(using string: String) async throws -> SomeStruct {
        //....
    }

    func anotherGenerateSomeData(using string: String) async throws -> SomeStruct {
        //....
    }
}

The issue is that the test runner gets stuck and doesn't continue with the test and just fail it. But if I only pass in one item instead of two in the array of closures, then it passes. Does this something to do with testing or it's just something that I cannot do at all with swift?

To make sure I understand, are you saying that this code does not build successfully, or it does build but encounters failure(s) at runtime? If the latter, I think we'll need to see more of the "real" code (I'm assuming some details have been omitted) to understand what exactly is failing.

@smontgomery I'm trying this code:

@Suite(.serialized) @MainActor struct magnetLogic {
    init() async { Magisterium.commenceSemester(PluginType: TestPlugin.self, unitTest: true) }

    @Test(arguments: [
      { (m: Magister, eid: EID) async -> Void in
        let drag = try! DragMeta(eid.entity(m)!, magister: m)
        eid.entity(m)!.position = [0.1, 0, 0.1]
        async let dragging: Void = drag.stop()
        await Magisterium.unitTest?.mockGameFrame(m)
        await dragging
      }
    ]) func aPileBringsHuggers(moveFn: (_ m: Magister, _ eid: EID) async -> Void) async throws {
      // ...
      await moveFn(m, BLL)
      // ...
    }
}

and it builds but the swift test gives this error upon running:

/Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift Command SwiftCompile failed with a nonzero exit code

I'm trying to pass async closures as parameters, because there's a couple of different ways a magnet can move in my program. I wanted to pass multiple async closures

This error:

Command SwiftCompile failed with a nonzero exit code

indicates there is some Swift compilation error. Can you paste the error(s) it outputs after this, or link to the complete log somewhere?

@smontgomery where does it output them? I can't see them in the Xcode warnings tab : S

Go to the Report navigator in Xcode (the rightmost tab), click the most recent Build item in that list, then find the error in there and expand to view its complete text output.

SwiftEmitModule normal arm64 Emitting\ module\ for\ MagisteriumTests (in target 'MagisteriumTests' from project 'Magisterium')
    cd /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift
    builtin-swiftTaskExecution -- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/MigrationTests.swift /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/MoveHistoryTests.swift /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/ValidationTests.swift -target arm64-apple-macos15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format\=dwarf -dwarf-version\=5 -module-cache-path /Users/lucaban/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 6 -enforce-exclusivity\=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -const-gather-protocols-file /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -empty-abi-descriptor -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file /Users/lucaban/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift -Xcc -D_LIBCPP_HARDENING_MODE\=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -ivfsstatcache -Xcc /Users/lucaban/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.2-24C94-1dd28740b163f220e3e9b9fd2a542f53.sdkstatcache -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/include -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/DerivedSources-normal/arm64 -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/DerivedSources/arm64 -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG\=1 -module-name MagisteriumTests -package-name magisterium -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins\#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins\#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -emit-module-doc-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.swiftdoc -emit-module-source-info-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.swiftsourceinfo -serialize-diagnostics-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests-master-emit-module.dia -emit-dependencies-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests-master-emit-module.d -o /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.swiftmodule -emit-abi-descriptor-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.abi.json

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/MigrationTests.swift /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/MoveHistoryTests.swift /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/ValidationTests.swift -target arm64-apple-macos15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/PackageFrameworks -F /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=5 -module-cache-path /Users/lucaban/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 6 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -const-gather-protocols-file /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -empty-abi-descriptor -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing -validate-clang-modules-once -clang-build-session-file /Users/lucaban/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -ivfsstatcache -Xcc /Users/lucaban/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.2-24C94-1dd28740b163f220e3e9b9fd2a542f53.sdkstatcache -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Products/Debug/include -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/DerivedSources-normal/arm64 -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/DerivedSources/arm64 -Xcc -I/Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name MagisteriumTests -package-name magisterium -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -emit-module-doc-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.swiftdoc -emit-module-source-info-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.swiftsourceinfo -serialize-diagnostics-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests-master-emit-module.dia -emit-dependencies-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests-master-emit-module.d -o /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.swiftmodule -emit-abi-descriptor-path /Users/lucaban/Library/Developer/Xcode/DerivedData/letsplay-gblwarlcwqjoztdlhyclggniinux/Build/Intermediates.noindex/Magisterium.build/Debug/MagisteriumTests.build/Objects-normal/arm64/MagisteriumTests.abi.json
1.	Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "/Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift")
4.	While type-checking 'E2ETests' (at /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift:36:45)
5.	While type-checking 'magnetLogic' (at /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift:607:34)
6.	While evaluating request StoredPropertiesRequest(MagisteriumTests.(file).E2ETests.magnetLogic@/Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift:607:41)
7.	While evaluating request ExpandPeerMacroRequest(MagisteriumTests.(file).E2ETests.magnetLogic.aPileBringsHuggers(moveFn:)@/Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift:618:13)
8.	While evaluating request ResolveMacroRequest(custom-attr, 0x13b53c020 StructDecl name=magnetLogic)
9.	While type-checking expression at [/Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift:610:5 - line:618:6] RangeText="@Test(arguments: [
      { (m: Magister, eid: EID) async -> Void in
        let drag = try! DragMeta(eid.entity(m)!, magister: m)
        eid.entity(m)!.position = [0.1, 0, 0.1]
        async let dragging: Void = drag.stop()
        await Magisterium.unitTest?.mockGameFrame(m)
        await dragging
      }
    ]"
10.	While type-checking-target starting at /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift:610:5
11.	While type-checking declaration 0x13b53f8c8 (at /Users/lucaban/ghq/github.com/craftingtablestudio/letsplay/swift/Packages/Magisterium/Tests/E2ETests.swift:612:9)
12.	While evaluating request FragileFunctionKindRequest(0x13b53f4f0 AbstractClosureExpr line=611 : (Magister, EID) async -> Void)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x000000010a50ea9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a50ccf0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a50f068 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018c2dee04 _sigtramp + 56
4  swift-frontend           0x0000000106753e04 swift::FragileFunctionKindRequest::OutputType swift::Evaluator::getResultCached<swift::FragileFunctionKindRequest, swift::FragileFunctionKindRequest::OutputType swift::evaluateOrDefault<swift::FragileFunctionKindRequest>(swift::Evaluator&, swift::FragileFunctionKindRequest, swift::FragileFunctionKindRequest::OutputType)::'lambda'(), (void*)0>(swift::FragileFunctionKindRequest const&, swift::FragileFunctionKindRequest::OutputType swift::evaluateOrDefault<swift::FragileFunctionKindRequest>(swift::Evaluator&, swift::FragileFunctionKindRequest, swift::FragileFunctionKindRequest::OutputType)::'lambda'()) + 1256
5  swift-frontend           0x0000000106753e04 swift::FragileFunctionKindRequest::OutputType swift::Evaluator::getResultCached<swift::FragileFunctionKindRequest, swift::FragileFunctionKindRequest::OutputType swift::evaluateOrDefault<swift::FragileFunctionKindRequest>(swift::Evaluator&, swift::FragileFunctionKindRequest, swift::FragileFunctionKindRequest::OutputType)::'lambda'(), (void*)0>(swift::FragileFunctionKindRequest const&, swift::FragileFunctionKindRequest::OutputType swift::evaluateOrDefault<swift::FragileFunctionKindRequest>(swift::Evaluator&, swift::FragileFunctionKindRequest, swift::FragileFunctionKindRequest::OutputType)::'lambda'()) + 1256
6  swift-frontend           0x00000001061eeaa4 swift::ExportContext::forDeclSignature(swift::Decl*) + 324
7  swift-frontend           0x00000001061a6888 swift::checkAccessControl(swift::Decl*) + 6956
8  swift-frontend           0x0000000106289800 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 6732
9  swift-frontend           0x0000000106287da4 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 152
10 swift-frontend           0x0000000105fc6930 (anonymous namespace)::SyntacticElementSolutionApplication::visitDecl(swift::Decl*) + 396
11 swift-frontend           0x0000000105fc4184 (anonymous namespace)::SyntacticElementSolutionApplication::visitBraceElement(swift::ASTNode) + 148
12 swift-frontend           0x0000000105fc5704 (anonymous namespace)::SyntacticElementSolutionApplication::visit(swift::Stmt*, bool) + 5140
13 swift-frontend           0x0000000105fc2564 (anonymous namespace)::SyntacticElementSolutionApplication::apply() + 184
14 swift-frontend           0x0000000105fc23bc swift::constraints::ConstraintSystem::applySolutionToBody(swift::constraints::Solution&, swift::AnyFunctionRef, swift::DeclContext*&, std::__1::function<std::__1::optional<swift::constraints::SyntacticElementTarget> (swift::constraints::SyntacticElementTarget)>) + 372
15 swift-frontend           0x0000000105f7479c swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SyntacticElementTarget) + 7440
16 swift-frontend           0x0000000106234870 swift::TypeChecker::typeCheckTarget(swift::constraints::SyntacticElementTarget&, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 680
17 swift-frontend           0x00000001062344a4 swift::TypeChecker::typeCheckExpression(swift::constraints::SyntacticElementTarget&, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 416
18 swift-frontend           0x00000001062d0d34 swift::ResolveMacroRequest::evaluate(swift::Evaluator&, swift::UnresolvedMacroReference, swift::DeclContext*) const + 1760
19 swift-frontend           0x00000001062aaa2c swift::ResolveMacroRequest::OutputType swift::Evaluator::getResultUncached<swift::ResolveMacroRequest, swift::ResolveMacroRequest::OutputType swift::evaluateOrDefault<swift::ResolveMacroRequest>(swift::Evaluator&, swift::ResolveMacroRequest, swift::ResolveMacroRequest::OutputType)::'lambda'()>(swift::ResolveMacroRequest const&, swift::ResolveMacroRequest::OutputType swift::evaluateOrDefault<swift::ResolveMacroRequest>(swift::Evaluator&, swift::ResolveMacroRequest, swift::ResolveMacroRequest::OutputType)::'lambda'()) + 600
20 swift-frontend           0x00000001062aa78c swift::ResolveMacroRequest::OutputType swift::Evaluator::getResultCached<swift::ResolveMacroRequest, swift::ResolveMacroRequest::OutputType swift::evaluateOrDefault<swift::ResolveMacroRequest>(swift::Evaluator&, swift::ResolveMacroRequest, swift::ResolveMacroRequest::OutputType)::'lambda'(), (void*)0>(swift::ResolveMacroRequest const&, swift::ResolveMacroRequest::OutputType swift::evaluateOrDefault<swift::ResolveMacroRequest>(swift::Evaluator&, swift::ResolveMacroRequest, swift::ResolveMacroRequest::OutputType)::'lambda'()) + 260
21 swift-frontend           0x0000000106675418 swift::Decl::forEachAttachedMacro(swift::MacroRole, llvm::function_ref<void (swift::CustomAttr*, swift::MacroDecl*)>) const + 372
22 swift-frontend           0x00000001062cceb8 swift::ExpandPeerMacroRequest::evaluate(swift::Evaluator&, swift::Decl*) const + 84
23 swift-frontend           0x0000000106337bc0 swift::ExpandPeerMacroRequest::OutputType swift::Evaluator::getResultUncached<swift::ExpandPeerMacroRequest, swift::ExpandPeerMacroRequest::OutputType swift::evaluateOrDefault<swift::ExpandPeerMacroRequest>(swift::Evaluator&, swift::ExpandPeerMacroRequest, swift::ExpandPeerMacroRequest::OutputType)::'lambda'()>(swift::ExpandPeerMacroRequest const&, swift::ExpandPeerMacroRequest::OutputType swift::evaluateOrDefault<swift::ExpandPeerMacroRequest>(swift::Evaluator&, swift::ExpandPeerMacroRequest, swift::ExpandPeerMacroRequest::OutputType)::'lambda'()) + 612
24 swift-frontend           0x00000001063378c0 swift::ExpandPeerMacroRequest::OutputType swift::Evaluator::getResultCached<swift::ExpandPeerMacroRequest, swift::ExpandPeerMacroRequest::OutputType swift::evaluateOrDefault<swift::ExpandPeerMacroRequest>(swift::Evaluator&, swift::ExpandPeerMacroRequest, swift::ExpandPeerMacroRequest::OutputType)::'lambda'(), (void*)0>(swift::ExpandPeerMacroRequest const&, swift::ExpandPeerMacroRequest::OutputType swift::evaluateOrDefault<swift::ExpandPeerMacroRequest>(swift::Evaluator&, swift::ExpandPeerMacroRequest, swift::ExpandPeerMacroRequest::OutputType)::'lambda'()) + 328
25 swift-frontend           0x000000010632d8d8 computeLoweredProperties(swift::NominalTypeDecl*, swift::IterableDeclContext*, (anonymous namespace)::LoweredPropertiesReason) + 800
26 swift-frontend           0x000000010632c1f4 swift::StoredPropertiesRequest::evaluate(swift::Evaluator&, swift::NominalTypeDecl*) const + 348
27 swift-frontend           0x00000001066d0f88 swift::StoredPropertiesRequest::OutputType swift::Evaluator::getResultCached<swift::StoredPropertiesRequest, swift::StoredPropertiesRequest::OutputType swift::evaluateOrDefault<swift::StoredPropertiesRequest>(swift::Evaluator&, swift::StoredPropertiesRequest, swift::StoredPropertiesRequest::OutputType)::'lambda'(), (void*)0>(swift::StoredPropertiesRequest const&, swift::StoredPropertiesRequest::OutputType swift::evaluateOrDefault<swift::StoredPropertiesRequest>(swift::Evaluator&, swift::StoredPropertiesRequest, swift::StoredPropertiesRequest::OutputType)::'lambda'()) + 1268
28 swift-frontend           0x0000000106288b30 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 3452
29 swift-frontend           0x0000000106292890 (anonymous namespace)::DeclChecker::visitClassDecl(swift::ClassDecl*) + 1592
30 swift-frontend           0x0000000106288c34 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 3712
31 swift-frontend           0x0000000106287da4 swift::TypeChecker::typeCheckDecl(swift::Decl*) + 152
32 swift-frontend           0x000000010636f01c swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 660
33 swift-frontend           0x0000000106376680 swift::TypeCheckSourceFileRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()>(swift::TypeCheckSourceFileRequest const&, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()) + 620
34 swift-frontend           0x000000010636ed6c swift::performTypeChecking(swift::SourceFile&) + 328
35 swift-frontend           0x000000010528be48 swift::CompilerInstance::performSema() + 332
36 swift-frontend           0x0000000104eb8df0 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1532
37 swift-frontend           0x0000000104eb7bb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
38 swift-frontend           0x0000000104e3ea5c swift::mainEntry(int, char const**) + 3680
39 dyld                     0x000000018bf28274 start + 2840

line 618

I don't see the issue : P

Closures can't be used with @Test. We found this out with test traits, but I think it applies to arguments too. We filed an issue on this awhile ago, and looks like it might be fixed for Swift 6.1.

1 Like

@mbrandonw is there any way I can already use Swift 6.1 through some beta of something? Or what's the best location to look out for a beta release of Swift 6.1?

Yes, I expect that crash may be fixed by this Swift compiler change:

But you could work around it before that fix arrives by factoring your arguments array into a static property or a function and pass that to @Test(arguments: …) instead of passing the array as a literal.

@smontgomery I'm trying to refactor as per your advice but my function relies on a @MainActor bound singleton (enum), and it seems the arguments won't allow a closure bound to @MainActor? :sob:

Type '(Magister, EID) async -> Void' (aka '(Magister, DbSchema1_3_0.EID) async -> ()') does not conform to the 'Sendable' protocol

My entire suite is bound to the @MainActor with which I made sure my tests all run on @MainActor anyway (because I'm testing RealityKit related code). So the requirement for Sendable arguments seems odd to me.

Do you know any other workaround?

Try changing the return type of your function from [(Magister, EID) async -> Void] to [@Sendable (Magister, EID) async -> Void].

I tried so many things and was getting many errors, but I finally found something that worked.

    typealias MoveFn = @Sendable (_ m: Magister, _ eid: EID) async -> Void
    static func getArgs() -> [MoveFn] {
      [
        { m, eid in await Task { @MainActor in /** ... */ }.value },
        // ... other closures
      ]
    }
    @Test(arguments: await getArgs()) func aPileBringsHuggers(
      moveFn: MoveFn
    ) async throws {
      // ...
    }

The parts I needed to make it work were mainly:

  1. make sure the MoveFn is its own typealias used for both the args static func AND the test func, because it gave me odd compile errors otherwise
  2. even though the args static func is not async it would only compile if I awaited it like so: await getArgs()

Thanks for all the help and let me know if you want me to delve into 1 or 2 above to share the errors I was hitting without those two.

-Luca

You should be able to simplify this to:

{ @MainActor m, eid in ... },

Yes, we should figure out what the errors were, because it really doesn't make sense for the compiler or Swift Testing to require you to write await getArgs() if getArgs() is not isolated.

getArgs() is a static function—is the type it's contained in actor-isolated? If so, then it would require await because the context in which the @Test macro's arguments are evaluated is nonisolated.

@grynspan

if getArgs() is not isolated.
// and
is the type it's contained in actor-isolated?

I'm not sure exactly I understand what you mean by this.

Given I need to run the closures on @MainActor as you can see, that means they are actor-isolated, right? or rather main-actor-isolated.

And so, is it because Swift Testing requires closures passed as arguments to be @Sendable that I must await my array of closures? Because each closure runs on @MainActor? :thinking:

If so that means that await getArgs() is what its supposed to be and I don't need to give you any further error details? Or am I misunderstanding something. : S


As for simplifying to { @MainActor m, eid in ... }, that worked as well, thanks!!
Now my code looks like this:

@Suite(.serialized) @MainActor struct magnetLogic {
	typealias MoveFn = @Sendable (_ m: Magister, _ eid: EID) async -> Void
	static func getArgs() -> [MoveFn] {
		[
			{ @MainActor m, eid in /** ... */ },
			{ @MainActor m, eid in /** ... */ },
		]
	}
	@Test(arguments: await getArgs()) func aPileBringsHuggers(
		moveFn: MoveFn
	) async throws {
		// ...
	}
}

You are misunderstanding, yes.

These functions are not called by Swift Testing nor by getArgs(), so there is no need for Swift Testing to await the call to getArgs()—unless getArgs() itself is async. Since it does not have the async keyword on it, that means that something else is forcing it to be called asynchronously, and that is presumably actor isolation.

Since your magnetLogic suite type is marked @MainActor, that means that members of magnetLogic are, by default, isolated to the main actor. Swift Testing evaluates arguments to @Test in a nonisolated context, not in the immediate context in which you typed @Test, which means that the call to getArgs() needs to hop back to the main actor to run—which is an asynchronous operation, hence why getArgs() needs the await keyword.

Depending on the actual implementation of getArgs(), it may be possible to mark it nonisolated, in which case it can be called without await.

Separately, all arguments to a test function must currently be sendable, because the collection in which they are stored is constructed in a nonisolated context and we cannot statically guarantee that the elements of that collection will not need to be sent across an isolation boundary. That means that, if the arguments are closures, they must either be @Sendable or isolated to some actor. Since you've marked them @MainActor, then as far as Swift Testing is concerned, they are indeed sendable.

If you redefine MoveFn as typealias MoveFn = @MainActor (_ m: Magister, _ eid: EID) -> Void, then you ought to be able to call those functions without needing to await them. You'll still need await on getArgs(), but not on the calls to moveFn inside aPileBringsHuggers() (because that function is also main-actor-isolated.)

I understand completely now. Thanks.
So the reason that I had to await getArgs() is because the @Suite was @MainActor isolated.

After adding nonisolated to the static func getArgs() it worked to call getArgs() without await! :tada:


As for my moveFn, I want to await it either way, because I do asynchronous stuff that needs to finish before doing #expect checks after.

But I see now that if can just mark an argument closure with @MainActor to lift this requirement if I ever need to do so : )

Thanks again!!