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

Support debugging for tests #1855

Open
JasonRosenberg opened this issue Sep 10, 2015 · 52 comments
Open

Support debugging for tests #1855

JasonRosenberg opened this issue Sep 10, 2015 · 52 comments
Assignees
Labels

Comments

@JasonRosenberg
Copy link

I have just tried using the new delve debugger integration, which appears to be a great start. I am using IntelliJ 141.1532, and version 0.9.491 of the plugin (which claims to be an alpha version for 1.0.0). I am using Go 1.4.2 sdk.

Anyway, it is possible to debug files and packages that have a 'main' method. But there does not appear to be a way yet to debug tests, via the test integration within IntelliJ.

Is this something that could be added easily enough (or are there technical reasons preventing it?)

@dlsniper
Copy link
Member

Is it possible to debug tests with delve? If so, then this is a valid use case.

@zolotov
Copy link
Contributor

zolotov commented Sep 10, 2015

@dlsniper yes, it's possible

@JasonRosenberg there are no technical reasons, just matter of time. We'll implement it eventually.

@zolotov zolotov added this to the 1.0.0 milestone Sep 10, 2015
@zolotov zolotov self-assigned this Sep 10, 2015
@dlsniper
Copy link
Member

dlsniper commented Nov 2, 2015

@zolotov I'd be happy to give this one a try but I've tried to do the Go Single File configuration debugable first, as I guess the test runner should be changeable following the same principle, and I've got deeply stuck. I've managed to make dlv launch but I don't have the debugging interface active for some reason. The commit is here: https://github.com/dlsniper/google-go-lang-idea-plugin/commit/98b060eb0c13b04a13eb4e93d6f5ee595e006ff8
If I'm not mistaken, I need to rewrite the runners so that they are built like the GoBuildingRunner on top of the AsyncGenericProgramRunner, but I'd rather not do it before I get a confirmation.

Can I have any pointers please? Thank you.

@jimhorng
Copy link

+1

@horkhe
Copy link
Contributor

horkhe commented Jan 14, 2016

I wolud say that I much more frequently run and debug tests than applications. So it is a very important feature for people that workflow is similar to mine.

@freehan
Copy link

freehan commented Jan 26, 2016

+1

1 similar comment
@inotnako
Copy link

+1

@weizhu
Copy link

weizhu commented Feb 15, 2016

+1
It seems counterintuitive to not enable debugging of tests first. In a good programming practice, developers would write and run unit tests first. Not able to debug tests make life a lot of more difficult :-(.

@msaldanha
Copy link

+1

@dlsniper dlsniper assigned dlsniper and unassigned zolotov Feb 16, 2016
@dlsniper
Copy link
Member

So, before anyone else +1's this anymore, I have a working version of this, however, https://github.com/derekparker/delve/issues/423 is being a major blocker for it imo. I'll submit the PR soon for review but imho the hacks I've done there should be solved before merging.

@tnine
Copy link

tnine commented Mar 1, 2016

Any updates on this?

@dlsniper
Copy link
Member

dlsniper commented Mar 1, 2016

@tnine not really, I currently lack the time to do the refactoring and finish it out but I'm trying to make some progress. Please follow the PR for this (and feel free to help out).

@varunpatro
Copy link

Any update on this?

@ramigg
Copy link

ramigg commented Jun 16, 2016

any update?

@cmartin0077
Copy link

@dlsniper, what is the best way to help with this? I tried cloning your fork but could not find any existing code for debugging a test.

@slowenthal
Copy link

I'm confused as to the status. I see #2750 is closed. Is there a way to grab a pre-release and debug tests?

@ghost
Copy link

ghost commented Oct 27, 2016

@slowenthal It's still WIP.

Contributions are welcomed, otherwise, no update for now, sorry.

See commits above which reference this issue.

#2750 is simply one of many duplicates of this issue and was closed as such. It's closure has no bearing on the status of this issue.

@pylover
Copy link

pylover commented Oct 27, 2016

This is not a real plugin. it's just cheap monkey-patch for idea for golang

@costinm
Copy link

costinm commented Nov 4, 2016

A quick (working for me) hack:

  1. Move the dlv binary to a different location
    DLV=$HOME/.IdeaIXXX/config/plugins/Go/lib/dlv/linux/dlv
    mv $DLV ~/bin/dlv
  2. Replace it with a script:
    #!/bin/bash
    export GOPATH=.... (probably not needed)
    if [ "$6" == "test" ] ; then
    go test -c -o $4 -gcflags "-N -l" $7
    $HOME/bin/dlv $1 $2 exec $4 -- --test.v
    else
    $HOME/bin/dlv $*
    fi
  3. Create a normal app config ( the app must exist ), and pass as parameters:
    test FULL_PATH_TO_TEST_FILE

The script will take the first param (test) to switch mode, will build the test (replacing the app binary), and call dlv. Idea and the golang plugin will believe it's debugging the app.

Breakpoints in the test work.

Variations possible - to run individual methods, etc.

@costinm
Copy link

costinm commented Nov 8, 2016

For the app config: just a dummy app ( package main, nothing inside ).
Make sure you can debug it first - than modify the launcher to add the
'test ...' params.

I suppose naming the dummy app "test_hack" and changing the script to use
that instead would
be cleaner.

What happens is that golang plugin believes it's debugging an app - and the
dlv script is
swapped so it passes different params to the real dlv.

On Tue, Nov 8, 2016 at 10:00 AM Fredrik Blomqvist notifications@github.com
wrote:

@costinm https://github.com/costinm Could you elaborate on how to
create the app config? This is what gets run if I pass it as the program
arguments:
dlv --listen=localhost:42657 --headless=true exec "/tmp/test" -- test
/home/fgblomqvist/IntelliJProjects/myapp/mypackage/mypackage_test.go

But in the end it tries to run my program with that argument and fails,
since I do not have a test argument.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1855 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFI6jDFbOw7eX8PR-47_1Cwl1c9zQGqks5q8LiugaJpZM4F6uDj
.

@fgblomqvist
Copy link

Got it working, thanks! Will do until proper support is implemented. For some reason it was not able to resolve dependencies within the same package, so I had to put the tests in "mypackage_test" and import "mypackage", but after that it worked.

@strootman
Copy link

This seems like a solid work around, but I'm missing something.

I swapped out the dlv file with the script above, but kept having the strange permission denied errors mentioned in derekparker/delve#538.
The big "aha" moment came when I set the working directory in the run config (it defaulted to $GOPATH).
Then, this helped me get one step further.
I was able to create a run config, and made sure the breakpoints worked.
But when I added the extra parameters, I get the following

  ./main_test.go:20: undefined: main

Ideas?

@costinm
Copy link

costinm commented Nov 10, 2016

The work around has 3 steps, and it helps to add 'echo' statements to the
script to see the actual
commands/workdir/env, and do the steps manually:

  1. figure out the right command to compile a test to a binary, and verify
    the binary runs as a test
  2. have dlv run the test binary manually
  3. Trick golang plugin into believing it runs a "main" program, and make
    sure the binary generated in
    (1) is in the expected dir, and dlv in (2) has the expected port/flags.

The last step can be customized as you want - but before tricking the
plugin you must make sure it
works, i.e. it can compile and run a normal minimal binary. I used the
'magic' first param in config, you
can also use the program name as a way to have the dlv script change
behavior.

An interesting trick is to compile a normal binary by hand, run it - and
use the hacked "dlv" script to call
'dlv attach' ( the config will need to be edited before run to add a
"attach PID", with the pid of the
running binary).

@ryancouto
Copy link

ryancouto commented Dec 13, 2016

@fgblomqvist I had the same issue, but was able to get around that by changing @costinm 's step 3 instruction to:

  1. Create a normal app config ( the app must exist ), and pass as parameters:
    test PACKAGE_NAME

@dave-r12
Copy link

dave-r12 commented Jan 4, 2017

@zolotov any pointers or direction for adding this to the plugin? I'd like to take a pass at it. I was going to start from this commit https://github.com/dlsniper/google-go-lang-idea-plugin/commit/101fce199d83277a6295dc0f981bccaa730cffc9

@richpoirier
Copy link

@dave-r12 Try the Gogland EAP -- debugging tests works great in there.

@dave-r12
Copy link

dave-r12 commented Jan 4, 2017

Oh wonderful, thanks for the heads up!

@wjx0912
Copy link

wjx0912 commented Jan 6, 2017

@richpoirier , good job!

@gheibia
Copy link

gheibia commented Jan 11, 2017

@richpoirier Brilliant! Although after debugging a few rounds the option was disabled.

@dlsniper
Copy link
Member

@gheibia if you have any issues with the debugger in Gogland please open an issue here: https://youtrack.jetbrains.com/issues/Go It should not disable itself at any given time but without further details I can't help out. Thank you!

@SerkanSipahi
Copy link

SerkanSipahi commented Feb 5, 2017

The problem still exists in Gogland when you setup "edit configuration" as "Go Single File". Setup your project-file as "Go Application" :)

@dlsniper
Copy link
Member

dlsniper commented Feb 5, 2017

@SerkanSipahi how you define applications run configurations doesn't have an effect how test configurations are defined.

@SerkanSipahi
Copy link

SerkanSipahi commented Feb 6, 2017

@dlsniper sorry i forgot to complete my sentense. I think it was to late :) I mean: Setup your project-file as "Go Application" will work but not when it configured as "Go Single File"

@dlsniper
Copy link
Member

dlsniper commented Feb 9, 2017

@SerkanSipahi that is correct. Only Go Application type is supported for now in the debugger, both in the plugin and Gogland. Gogland has support for debugging tests. What you are asking for is not related to tests.

@kevinleecarr
Copy link

If this is already implemented in EAP, can it get ported to the golang IDEA plugin?

@dlsniper
Copy link
Member

The EAP and https://plugins.jetbrains.com/plugin/9568-go plugin are maintained by JetBrains. This plugin is currently not actively maintained and I have no intention to port the functionality any time in the foreseeable future.

@MEGApixel23
Copy link

Any updates?

@dlsniper
Copy link
Member

dlsniper commented Dec 4, 2017

@MEGApixel23 nobody contributed anything for this functionality in this plugin. Meanwhile JetBrains released GoLand, their Go IDE and it has full support for this. You can use the IDE from here: https://www.jetbrains.com/go/ or as a plugin in IntelliJ Ultimate (2017.3+).

@antonlisovenko
Copy link

antonlisovenko commented Apr 24, 2018

Debugging tests in go plugin is still quite strange. I cannot evaluation most of calls ("function calls are not supported"), the inner state of maps is not showing in many situations:
image
image

I'm using the latest version of Idea and plugin (2018.1.1 Ultimate and 181.4445.53.182)

@dlsniper
Copy link
Member

Hi @antonlisovenko, this is the wrong place to report issues about the Go plugin maintained by JetBrains. Please report issues in the future here: https://youtrack.jetbrains.com/issues/Go

As for the particular issues you mentioned:

@dlsniper
Copy link
Member

@antonlisovenko I've created https://youtrack.jetbrains.com/issue/GO-5602 to specifically track the second issue. For the first issue see: https://youtrack.jetbrains.com/issue/GO-3433. Please vote/start them go get updates for them. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests