Skip to content

Commit

Permalink
fix: only detect t.Run
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Dec 29, 2024
1 parent 09b29c4 commit 7238662
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lua/neotest-golang/query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ M.test_function = [[
; query for subtest, like t.Run()
(call_expression
function: (selector_expression
operand: (identifier) @test.operand (#match? @test.operand "^[t]$")
field: (field_identifier) @test.method) (#match? @test.method "^Run$")
arguments: (argument_list . (interpreted_string_literal) @test.name))
@test.definition
Expand Down Expand Up @@ -47,6 +48,7 @@ M.table_tests = [[
(expression_statement
(call_expression
function: (selector_expression
operand: (identifier) @test.operand (#match? @test.operand "^[t]$")
field: (field_identifier) @test.method)
(#match? @test.method "^Run$")
arguments: (argument_list
Expand Down Expand Up @@ -112,6 +114,7 @@ M.table_tests = [[
(expression_statement
(call_expression
function: (selector_expression
operand: (identifier) @test.operand (#match? @test.operand "^[t]$")
field: (field_identifier) @test.method)
(#match? @test.method "^Run$")
arguments: (argument_list
Expand Down Expand Up @@ -143,6 +146,7 @@ M.table_tests = [[
(expression_statement
(call_expression
function: (selector_expression
operand: (identifier) @test.operand (#match? @test.operand "^[t]$")
field: (field_identifier) @test.method)
(#match? @test.method "^Run$")
arguments: (argument_list
Expand Down Expand Up @@ -176,6 +180,7 @@ M.table_tests = [[
(expression_statement
(call_expression
function: (selector_expression
operand: (identifier) @test.operand (#match? @test.operand "^[t]$")
field: (field_identifier) @test.method)
(#match? @test.method "^Run$")
arguments: (argument_list
Expand Down
45 changes: 45 additions & 0 deletions tests/go/internal/operand/operand_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package operand

import "testing"

type dummy struct{}

func (dummy) Run(string, func(t *testing.T)) {}

func Test_Run(t *testing.T) {
t.Run("find me", func(t *testing.T) {
})

x := dummy{}
x.Run("don't find me", func(t *testing.T) {
})

router := dummy{}
router.Run("don't find me", func(t *testing.T) {
})
}

func Benchmark_Run(b *testing.B) {
// NOTE: support for benchmarks could potentially be added.
b.Run("benchmark case", func(b *testing.B) {
for i := 0; i < b.N; i++ {
// Add benchmark logic here
dummy{}.Run("test", func(t *testing.T) {})
}
})
}

func FuzzRun(f *testing.F) {
// NOTE: support for fuzz tests could potentially be added.

// Add seed corpus
f.Add("test input")

// Actual fuzz test
f.Fuzz(func(t2 *testing.T, input string) {
t := dummy{}
t.Run(input, func(t *testing.T) {
// Add fuzzing logic here
})
})
}
4 changes: 4 additions & 0 deletions tests/go/lookup_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ describe("Lookup", function()
local folderpath = vim.uv.cwd() .. "/tests/go"
local filepaths = lib.find.go_test_filepaths(vim.uv.cwd())
local expected_lookup = {
[folderpath .. "/internal/operand/operand_test.go"] = {
package = "operand",
replacements = {},
},
[folderpath .. "/internal/positions/positions_test.go"] = {
package = "positions",
replacements = {},
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/golist_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("go list output from internal", function()
local tests_filepath = vim.uv.cwd() .. "/tests/go"
local internal_filepath = vim.uv.cwd() .. "/tests/go/internal"
local output = lib.cmd.golist_data(internal_filepath)
local first_entry = output[1]
local first_entry = output[2]
local expected = {

Deps = {
Expand Down

0 comments on commit 7238662

Please sign in to comment.