Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: ability to generate launch configs for debugging particular tests #1845

Closed
mattwelke opened this issue Oct 15, 2021 · 6 comments
Closed
Assignees
Labels
debug/config Issues for config discrepancies b/n settings.json, launch.json, launch with F5, run test, debug test Debug Issues related to the debugging functionality of the extension. FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@mattwelke
Copy link

Is your feature request related to a problem? Please describe.

I like to debug tests by clicking on the "debug test" text:

image

Debugging tests as opposed to just running them (with "run test") is useful because I can set breakpoints to observe the state of the program at arbitrary points during the test, or allow the program to continue one line at a time during a test to see what causes a panic.

The problem I encountered today is that I needed to run a test, while debugging, and I needed environment variables set for that particular test. It's more of an integration test, so it involves interacting with GCP APIs, and I needed to be able to set the GOOGLE_APPLICATION_CREDENTIALS environment variable that the test requires.

My current understanding of debugging in VS Code is that if you want to set up things like environment variables to be used by the program, you need to use a launch config. I do that by clicking on "create a launch.json file" from a Go project:

image

Then, I'm presented with the types of Go launch configs that VS Code can generate for me:

image

The problem is that none of these will work for my use case. I need to run a specific test, not run an entire Go package. I could read into how the go CLI tool works to learn for myself what I can set up, but it'd be convenient if VS Code could help me with this and keep me in the zone.

Describe the solution you'd like

I would like an easy way to generate launch configs for running particular tests in a Go project. As a bonus, it'd be nice if we could choose launch configs for all types of testing one usually does in Go (all tests, all tests in a package, all tests in a file, or just one particular test). It would be nice if I could create the launch config by clicking on some UI element near the "debug test" UI element, in which case the launch config would automatically include the right go command to run just that test.

Alternatively, if launch configs aren't the best way to solve my use case (including environment variables while running a test), something else could be implemented that would allow one to set environment variables for a test easily. Then, they could run them by clicking "debug test" or "run test" without having to set up a launch config.

Describe alternatives you've considered

Starting from the "Go: Launch Package" launch config template, consulting the go CLI tool documentation to learn how to use it to run just one test, and then adding my environment variable config to that launch config. Repeating this step for every test I need to manually debug with environment variables.

@gopherbot gopherbot added this to the Untriaged milestone Oct 15, 2021
@mattwelke
Copy link
Author

Follow up...

What I'm asking for seems to already exist. I didn't see it the first time I tried to do it. But after already having a launch.json file, and trying to add a second launch config, I see it as one of the Go options presented to me:

image

image

So maybe the solution here is to change the options presented to the user as they create their first launch config.

@suzmue suzmue modified the milestones: Untriaged, On Deck Oct 18, 2021
@suzmue suzmue added the Debug Issues related to the debugging functionality of the extension. label Oct 21, 2021
@polinasok
Copy link
Contributor

@mattwelke Thank you for detailed report.
There are indeed different sets of sample configurations offered from no-launch.json state and from Add Configuration in launch.json. And I agree that it would be helpful to have test related configurations in both.

That said, these configurations will not apply debug test (see #855). You will have to use the Run and Debug drop-down to use the launch.json configuration you need.

There is also the option of using settings.json for applying flags globally. You can utilize go.testFlags, go.buildFlags and go.delveConfig. A word of warning though: the flags won't always work the same with run test and debut test (e.g. #1636) and the set oof options is more limited than those in launch.json although we have been recently extending it.

@polinasok polinasok changed the title Ability to generate launch configs for running particular tests debug: ability to generate launch configs for debugging particular tests Nov 5, 2021
@polinasok
Copy link
Contributor

polinasok commented Nov 5, 2021

As a bonus, it'd be nice if we could choose launch configs for all types of testing one usually does in Go (all tests, all tests in a package, all tests in a file, or just one particular test)

@mattwelke Do you mean to run or debug multiple tests? There are already shortcuts to "run package tests" and "run file tests" at the top of your test file. Usually once you identify a bad test, you benefit from debugging just that test, so I am not sure how necessary the equivalent "debug package tests" shortcut would be. You can also tweak "Launch test function" configuration to run over all functions (none specified in the args) and the program argument to use a specific test file or package. Do you think that's too hard of a leap, and we need all flavors ("Launch test file", "Launch test package") separately?

@mattwelke
Copy link
Author

@polinasok Thanks for the reply. It's been a while since I created this so I want to review it, gather my thoughts, and respond back soon.

@polinasok
Copy link
Contributor

polinasok commented Nov 6, 2021

@mattwelke Thank you. Sounds good.
I also wanted to add that there are two ways to set environment variables:

  1. settings.json: "go.toolsEnvVars": { "FOO": "bar" }, => applies to run test, debug test and launch configurations
  2. launch.json: "env": { "FOO": "launch.json"}, => applies to launch configurations only, overrides global value in settings.json

@hyangah hyangah modified the milestones: On Deck, Untriaged Dec 3, 2021
@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 3, 2021
@polinasok polinasok added the debug/config Issues for config discrepancies b/n settings.json, launch.json, launch with F5, run test, debug test label Mar 30, 2022
@gopherbot
Copy link
Collaborator

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug/config Issues for config discrepancies b/n settings.json, launch.json, launch with F5, run test, debug test Debug Issues related to the debugging functionality of the extension. FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants