swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
745 stars 52 forks source link

Unable to debug unit tests on VSCode Windows #728

Closed softwarehangar7 closed 5 months ago

softwarehangar7 commented 6 months ago

I'm trying to debug a unit test on Windows, but I'm receiving the message unable to find executable for <path for file>.xctest.exe (see swift forum discussion )

My build folder doesn't present any file with the .xctest.exe extension. Only .xctest.

Also, it is missing a part of the path. It should be .build\x86_64-unknown-windows-msvc\debug. It's missing the x86_64-unknown-windows-msvc part.

I am able to debug executables, but not unit libraries.

To Reproduce Create any unit test for a swift lib. Open VSCode, build all with --build-tests Click the debug button on the Test Explorer

Environment

adam-fowler commented 6 months ago

@compnerd is this a recent change to not include .exe at the end of xctest executable filenames? I was sure it was there previously.

tristanlabelle commented 6 months ago

I don't think it was ever there, but it really should be.

adam-fowler commented 6 months ago

This is odd, as I did have it working. I'm currently nowhere near my machine with the Windows VM so can't verify this. I'll probably have to rebuild it again as I haven't touched it in a few months as well.

If I try to fix this blind can you verify this for me @tristanlabelle or @softwarehangar7

adam-fowler commented 6 months ago

I've had a look through the code and there is nowhere where the extension adds .exe to xctest executables. @softwarehangar7 Just to verify are you running/debugging tests through the TestExplorer? Also does running tests as opposed to debugging tests work ok?

adam-fowler commented 6 months ago

@softwarehangar7 Also finally if you enable setting Swift: Diagnostics in the the Advanced section of the Swift settings. When you run a TestExplorer debug session the launch config used by test explorer is output to the Swift output pane. If you could paste it here that'd be great.

tristanlabelle commented 5 months ago

I verified that I'm able to debug a test for a Package.swift-driven project.

Also, it is missing a part of the path. It should be .build\x86_64-unknown-windows-msvc\debug. It's missing the x86_64-unknown-windows-msvc part.

On my machine, .build\debug is created as a symbolic link to .build\x86_64-unknown-windows-msvc\debug. Is this not what you see @softwarehangar7 ? If you're missing the symlink, do you have developer mode turned on on your machine? I believe this enables symlinks.

softwarehangar7 commented 5 months ago

Hi @adam-fowler and @tristanlabelle. I will test that.

softwarehangar7 commented 5 months ago

On my machine, .build\debug is created as a symbolic link to .build\x86_64-unknown-windows-msvc\debug. Is this not what you see @softwarehangar7 ? If you're missing the symlink, do you have developer mode turned on on your machine? I believe this enables symlinks.

That fixed all the issues. The path issue and also the .xctest.exe issue.

softwarehangar7 commented 5 months ago

I didn't undestand why without symlink it was searching for .xctest.exe though

adam-fowler commented 5 months ago

I think this is something internal to vscode. If you try to run an executable and it cannot find it then it tries the same name but with “.exe” appended

On Fri, 12 Apr 2024 at 11:00, Luigi Spacino Scarminio < @.***> wrote:

I didn't undestand why without symlink it was searching for .xctest.exe though

— Reply to this email directly, view it on GitHub https://github.com/swift-server/vscode-swift/issues/728#issuecomment-2051450326, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACHSVJ35XIXYKOI7OYEYCZ3Y46WEXAVCNFSM6AAAAABFE5A5TGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJRGQ2TAMZSGY . You are receiving this because you were mentioned.Message ID: @.***>

tristanlabelle commented 5 months ago

@softwarehangar7 Nice to hear the issue is fixed. Was it specifically turning on developer mode in settings that did it?

softwarehangar7 commented 5 months ago

@tristanlabelle Yes

compnerd commented 5 months ago

Perhaps we should verify that the user has the SeCreateSymbolicLinkPrivilege privilege before supporting test execution on Windows?

tristanlabelle commented 5 months ago

@compnerd I like the idea, but a few questions:

  1. Does the debug symbolic link exist only to support testing or could it also affect just building / other uses of SPM?
  2. Would testing work if using the full x86_64-unknown-windows-msvc\debug path?
  3. Would it also fail if using swift test directly? What I'm getting at is: is lack of symbolic link a problem for SPM itself, such that it should report the error, or is it only a problem for the VS Code test integration?
adam-fowler commented 5 months ago
  1. It affects the generated launch.json files as well
  2. Including the triple in the launch.json means it will be different across platforms. For someone who jumps between macOS and Linux using dev containers this could get annoying as the launch.json gets rebuilt and they lose changes
  3. Running swift test would mean you are debugging swift not the test executable.
tristanlabelle commented 5 months ago

Thanks. It seems reasonable to warn and possibly disable testing if symbolic links are disabled then.