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

When trying to debug_test a suite case it wrongfully assumes there are no tests #98

Open
brunobmello25 opened this issue Sep 16, 2024 · 5 comments

Comments

@brunobmello25
Copy link

brunobmello25 commented Sep 16, 2024

Steps to reproduce:

  1. initialize a new go module with go mod init ...
  2. create an src folder with a main_test.go file
  3. add this content to the main_test.go file:
package main

import (
	"github.com/stretchr/testify/suite"
)

type SomeTestSuite struct {
	suite.Suite
}

func TestSuite(t *testing.T) {
	suite.Run(t, new(SomeTestSuite))
}

func (st *SomeTestSuite) TestSomething() {
	st.Run("some test here", func() {
		st.Equal(2, 1)
	})

	st.Run("another test here", func() {
		st.Equal(3, 2)
	})
}
  1. try running require('dap-go').debug_test() with the cursor inside one of the two st.Run(...) suites. For example, assuming you run on the second st.Run, note that there will be a vim message like starting debug session './src : another_test_here', which is the correct name, but then in the repl window you will see that it didn't find any test.
@leoluz
Copy link
Owner

leoluz commented Oct 3, 2024

Not sure but it seems that something is wrong with your test. I created the same folder structure than you and validated that the following test works fine:

package main

import (
	"fmt"
	"testing"
)

func TestSuite(t *testing.T) {
	t.Run("subtest with function literal", func(t *testing.T) {
		t.FailNow()
	})
}

func TestSomething(t *testing.T) {
	t.Run("some test here", func(t *testing.T) {
		t.SkipNow()
	})

	t.Run("another test here", func(t *testing.T) {
		fmt.Println("here")
	})
}

I added breakpoints in all 3 tests the was able to debug as expected.

@brunobmello25
Copy link
Author

Not sure but it seems that something is wrong with your test. I created the same folder structure than you and validated that the following test works fine:

but where are you placing your cursor when running debug_test? if my cursor is placed inside a specific t.Run it log a warning that there are no tests to run. see this first screenshot:
image

however, if you place your cursor inside the TestSuite function, then it will run, but it will run all t.Run suite methods inside the TestSomething function, where we actually only want to run one (first case)
image

@leoluz
Copy link
Owner

leoluz commented Oct 4, 2024

It is probably caused by the signature of your
TestSomething() function. Try to declare it as TestSomething(t *testing.T) instead.

@brunobmello25
Copy link
Author

still the same problem, it doesn't find any tests to run .

It would work if I used the t object instead of the suite, but then I'd not be respecting the suite way of writing tests

image

@leoluz
Copy link
Owner

leoluz commented Oct 5, 2024

It could be something related with the treesitter queries used to identify tests and sub-tests. It needs investigation in that part of the code:

local tests_query = [[
(function_declaration
name: (identifier) @testname
parameters: (parameter_list
. (parameter_declaration
type: (pointer_type) @type) .)
(#match? @type "*testing.(T|M)")
(#match? @testname "^Test.+$")) @parent
]]
local subtests_query = [[
(call_expression
function: (selector_expression
operand: (identifier)
field: (field_identifier) @run)
arguments: (argument_list
(interpreted_string_literal) @testname
[
(func_literal)
(identifier)
])
(#eq? @run "Run")) @parent
]]

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

No branches or pull requests

2 participants