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 b2ff803
Show file tree
Hide file tree
Showing 2 changed files with 35 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 "^(t|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
26 changes: 26 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,29 @@ 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)
})
}

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

0 comments on commit b2ff803

Please sign in to comment.