Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Debug test feature doesn't work for modules in gopath #2828

Closed
SteelPhase opened this issue Oct 11, 2019 · 7 comments
Closed

Debug test feature doesn't work for modules in gopath #2828

SteelPhase opened this issue Oct 11, 2019 · 7 comments
Labels

Comments

@SteelPhase
Copy link
Contributor

SteelPhase commented Oct 11, 2019

Example is here

Running Run Unit Test while this module is outside of the gopath will result in the test debugging correctly.
Running Run Unit Test while this module is in the gopath will result in the test failing.

It appears that the execution of dlv test differs for modules outside of the gopath

  • Module outside gopath Running: /Users/steelphase/Code/Go/bin/dlv test --headless=true --listen=127.0.0.1:37823 --api-version=2 --log=true
  • Module in gopath Running: /Users/steelphase/Code/Go/bin/dlv test github.com/steelphase/vscode-go-2828/pkg/printer --headless=true --listen=127.0.0.1:47612 --api-version=2 --log=true

The offending code appears to be here. I think there needs to be an additional check that the workspace we are in even if in gopath is a module. This is was changed in go 1.13 when the default for GO111MODULE determines if project is a module differently.

const currentGOWorkspace = getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], dirname);
dlvArgs.push(mode || 'debug');
if (mode === 'exec') {
dlvArgs.push(program);
} else if (currentGOWorkspace && env['GO111MODULE'] !== 'on') {
dlvArgs.push(dirname.substr(currentGOWorkspace.length + 1));
}

@SteelPhase SteelPhase changed the title Debug test doesn't work Debug test feature doesn't work for modules in gopath Oct 11, 2019
@SteelPhase
Copy link
Contributor Author

From #modules on the Gophers slack, it appears that relying on the output of go env GOMOD returning the go.mod file for the current working directory could be a decent solution to this. It would also support all the settings of GO111MODULE.

@ramya-rao-a
Copy link
Contributor

This only affects the time when GO111MODULE is set to auto right?

@SteelPhase
Copy link
Contributor Author

SteelPhase commented Oct 14, 2019

It only appears to affect auto

@ramya-rao-a
Copy link
Contributor

This is was changed in go 1.13 when the default for GO111MODULE determines if project is a module differently.

@SteelPhase Can you elaborate on what changed in go 1.13 for GO111MODULE?
cc @stamblerre

@stamblerre
Copy link
Contributor

I do believe the correct approach would be to use the result of go env GOMOD. This way, you don't have to worry about the changing meanings of GO111MODULE--you can rely on the go command to tell you that you are in a module.

https://golang.org/doc/go1.13#modules explains the changes to the meaning of auto for Go 1.13.

@ramya-rao-a
Copy link
Contributor

Please try the latest beta version of this extension has the fix for this

@ramya-rao-a
Copy link
Contributor

The latest update to this extension (0.11.8) has the fix for this.

Thanks for reporting @SteelPhase

Happy Coding!

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants