Missing unit test output when also calling `print()` (swift-testing, vscode)

I'm trying to debug a unit test but the test result output is missing a lot of content if I call print() instead of using #expect(). I am trying to print a single string with the data that I want to see with line breaks separating the different content (the single string is about 5850 characters).

I couldn't find an issue on the vscode-swift or swift-testing repos relating to this.

Am I holding it wrong or is this an issue I should open?

Setup details

Swift
Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu

swift-tools-version: 5.10

How are you running your tests? Using VS Code? @plemarquand may be able to help.

Yes, using VS Code and the green check mark button for the unit test (not the suite). Looks like the problem isn't there if I execute swift test from a terminal.

@RandomHashTags Do you have a minimal repro case? I tried adding prints() in my swift-testing tests and saw the output, though granted it isn't always in the order we'd like due to the way we're mixing the terminal output with the events we get from swift-testing.

I did some testing and the following test reproduces it. It only shows up to 825 and cuts it off when showing 826.


@Test func yup() {
        var string:String = ""
        for i in 1...2000 {
            string += "\(i)\n"
        }
        print(string)
    }

Screenshot_2025-02-12_09-59-57

I've opened an issue: Missing Test Result output on Linux when using `print` · Issue #1393 · swiftlang/vscode-swift · GitHub

Thanks for the GitHub issue report. The missing ingredient for me to reproduce was trying it on Linux, and now I'm seeing the issue. It looks like it tracks back to data events can be fired after exit is fired · Issue #72 · microsoft/node-pty · GitHub, which is a longstanding issue we'll have to see if we can work around.

1 Like