Skip to content

Commit

Permalink
fix: testify operand not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jan 24, 2025
1 parent 059c575 commit e4789b2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
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)$")
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
32 changes: 32 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,38 @@ describe("With testify_enabled=true", function()
type = "test",
},
},
{
{
id = test_filepath .. "::TestExampleTestSuite::TestSubTestOperand1",
name = "TestSubTestOperand1",
path = test_filepath .. "",
type = "test",
},
{
{
id = '/Users/fredrik/code/public/neotest-golang/tests/go/internal/testify/positions_test.go::TestExampleTestSuite::TestSubTestOperand1::"subtest"',
name = '"subtest"',
path = test_filepath .. "",
type = "test",
},
},
},
{
{
id = test_filepath .. "::TestExampleTestSuite::TestSubTestOperand2",
name = "TestSubTestOperand2",
path = test_filepath .. "",
type = "test",
},
{
{
id = '/Users/fredrik/code/public/neotest-golang/tests/go/internal/testify/positions_test.go::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)
})
}

0 comments on commit e4789b2

Please sign in to comment.