1; Functions names start with `Test`
2(
3 (
4 (function_declaration name: (_) @run
5 (#match? @run "^Test.*"))
6 ) @_
7 (#set! tag go-test)
8)
9
10; `go:generate` comments
11(
12 ((comment) @_comment @run
13 (#match? @_comment "^//go:generate"))
14 (#set! tag go-generate)
15)
16
17; `t.Run`
18(
19 (
20 (call_expression
21 function: (
22 selector_expression
23 field: _ @run @_name
24 (#eq? @_name "Run")
25 )
26 arguments: (
27 argument_list
28 .
29 (interpreted_string_literal) @_subtest_name
30 .
31 (func_literal
32 parameters: (
33 parameter_list
34 (parameter_declaration
35 name: (identifier) @_param_name
36 type: (pointer_type
37 (qualified_type
38 package: (package_identifier) @_pkg
39 name: (type_identifier) @_type
40 (#eq? @_pkg "testing")
41 (#eq? @_type "T")
42 )
43 )
44 )
45 )
46 ) @_second_argument
47 )
48 )
49 ) @_
50 (#set! tag go-subtest)
51)
52
53; Functions names start with `Benchmark`
54(
55 (
56 (function_declaration name: (_) @run @_name
57 (#match? @_name "^Benchmark.+"))
58 ) @_
59 (#set! tag go-benchmark)
60)
61
62; Functions names start with `Fuzz`
63(
64 (
65 (function_declaration name: (_) @run @_name
66 (#match? @_name "^Fuzz"))
67 ) @_
68 (#set! tag go-fuzz)
69)
70
71; go run
72(
73 (
74 (function_declaration name: (_) @run
75 (#eq? @run "main"))
76 ) @_
77 (#set! tag go-main)
78)