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

fix: testify operand not recognized #280

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lua/neotest-golang/features/testify/query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ M.namespace_query = [[
type: (pointer_type
(type_identifier) @namespace.name )))) @namespace.definition
name: (field_identifier) @test_function (#match? @test_function "^(Test|Example)") (#not-match? @test.name "^TestMain$")

; query for subtest, like t.Run()
(call_expression
function: (selector_expression
operand: (identifier) @test.operand (#match? @test.operand "^(s|suite)$")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain complete backward compatibility from what we used to have, this line should not even be in here.

Suggested change
operand: (identifier) @test.operand (#match? @test.operand "^(s|suite)$")

But if we remove it, tree-sitter can become confused if it encounters e.g. gin.Run or somethingelse.Run.

field: (field_identifier) @test.method) (#match? @test.method "^Run$")
arguments: (argument_list . (interpreted_string_literal) @test.name))
@test.definition

]]

M.test_method_query = [[
Expand Down
34 changes: 34 additions & 0 deletions tests/go/internal/testify/positions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,40 @@ describe("With testify_enabled=true", function()
type = "test",
},
},
{
{
id = test_filepath .. "::TestExampleTestSuite::TestSubTestOperand1",
name = "TestSubTestOperand1",
path = test_filepath .. "",
type = "test",
},
{
{
id = test_filepath
.. '::TestExampleTestSuite::TestSubTestOperand1::"subtest"',
name = '"subtest"',
path = test_filepath .. "",
type = "test",
},
},
},
{
{
id = test_filepath .. "::TestExampleTestSuite::TestSubTestOperand2",
name = "TestSubTestOperand2",
path = test_filepath .. "",
type = "test",
},
{
{
id = test_filepath
.. '::TestExampleTestSuite::TestSubTestOperand2::"subtest"',
name = '"subtest"',
path = test_filepath .. "",
type = "test",
},
},
},
},
{
{
Expand Down
18 changes: 18 additions & 0 deletions tests/go/internal/testify/positions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,21 @@ func TestTrivial(t *testing.T) {
func (suite *OtherTestSuite) TestOther() {
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
}

// --------------------------------------------------------------------

// // A test method with a subttest, using operand suite.
func (suite *ExampleTestSuite) TestSubTestOperand1() {
suite.Run("subtest", func() {
suite.VariableThatShouldStartAtFive = 10
assert.Equal(suite.T(), 10, suite.VariableThatShouldStartAtFive)
})
}

// // A test method with a subttest, using operand s.
func (s *ExampleTestSuite) TestSubTestOperand2() {
s.Run("subtest", func() {
s.VariableThatShouldStartAtFive = 10
assert.Equal(s.T(), 10, s.VariableThatShouldStartAtFive)
})
}
Loading