Repository: swiftlang/swift-testing

Issue #480: Using recording an issue inside of a detached task causes a crash.
Created: 2024-06-13T14:04:54Z
Description
This is something I learned while researching potential ways to address #475. Which, at the time I wrote that issue, I thought would have just resulted in the failure being silently dropped.
The current way of determining what the current reporting tests natively in Swift-Testing is broken when you run an expect inside of a detached task. Technically, you get a failing test result, but it's because the test runner crashed. I haven't yet spelunked enough through the codebase to figure out where that crash is.
This is because Test.current is stored as a task-local value. Which means that when you make an expect inside of a detached task, Swift Testing has lost that context, which means that Test.current is incorrectly (from the semantics of the current running test) as nil.
I don't know the concurrency system well enough to be able to suggest a good solution. The issue is that, because Swift Testing supports task-based parallelization, the value of Test.current strongly depends on the task it's running on. Which makes having a global Test.current like what's in swift-corelibs-xctest the wrong solution.
Expected behavior
No response
Actual behavior
No response
Steps to reproduce
This test should pass. The test runner crashes with a non-zero error instead.
import Testing

@Test func CheckingExpectWithDetachedTasks() async {
    await Task.detached {
        #expect(Bool(false))
    }.value
}

swift-testing version/commit hash
Testing Library Version: 75.7 (arm64e-apple-macos13.0)
Swift & OS version (output of swift --version ; uname -a)
No response

Duplicate issue #749: Fatal error: Internal inconsistency: No test reporter for test case argumentIDs:
Created: 2024-10-07T07:24:52Z
Description
Related issue: swiftlang/swift#76637 (comment)
Using the trick mentioned above can solve most of my needs.
But it seems I just hit another corner case in swift-tesing.
Expected behavior
No fatal error.
Actual behavior
XCTest/HarnessEventHandler.swift:282: Fatal error: Internal inconsistency: No test reporter for test case argumentIDs: Optional([Testing.Test.Case.Argument.ID(bytes: [48]), Testing.Test.Case.Argument.ID(bytes: [34, 35, 52, 102, 55, 56, 97, 50, 101, 100, 102, 54, 52, 51, 48, 101, 52, 50, 100, 55, 50, 49, 98, 53, 53, 50, 51, 102, 102, 57, 99, 102, 98, 48, 57, 100, 51, 99, 97, 57, 53, 98, 34])]) in test DemoKitTests.STests/PTypeConformance(value:expected:)/DemoKitTests.swift:5:6

Steps to reproduce
Use provided DemoKit package to reproduce it.
DemoKit.zip
swift-testing version/commit hash
None
Swift & OS version (output of swift --version ; uname -a)
Xcode 16.0.0 with Swift 5 language mode

Closing comment (2024-10-07T22:16:46Z): This is effectively a dupe of #480, yes. But this manifestation of the problem is different than what was described in that issue. Here, the problem is that two arguments of a parameterized test have identical ID representations (even though their specific arguments: are different.) Either way, I do believe the fixes will be related, so we can dupe this.
Duplicate of #480