2024-03-27 19:24:38 +01:00
|
|
|
package analyzer_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2024-11-20 15:14:07 +02:00
|
|
|
|
|
|
|
"golang.org/x/tools/go/analysis/analysistest"
|
|
|
|
|
|
|
|
"github.com/Crocmagnon/fatcontext/pkg/analyzer"
|
2024-03-27 19:24:38 +01:00
|
|
|
)
|
|
|
|
|
2025-01-13 15:46:00 +01:00
|
|
|
func TestAnalyzer(t *testing.T) {
|
2025-01-17 00:37:25 +01:00
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
dir string
|
|
|
|
options map[string]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "no func decl",
|
|
|
|
dir: "common",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "no func decl",
|
|
|
|
dir: "no_structpointer",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "func decl",
|
|
|
|
dir: "common",
|
|
|
|
options: map[string]string{
|
|
|
|
analyzer.FlagCheckStructPointers: "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "func decl",
|
|
|
|
dir: "structpointer",
|
|
|
|
options: map[string]string{
|
|
|
|
analyzer.FlagCheckStructPointers: "true",
|
|
|
|
},
|
|
|
|
},
|
2024-03-27 19:24:38 +01:00
|
|
|
}
|
|
|
|
|
2025-01-17 00:37:25 +01:00
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc+"_"+test.dir, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2025-01-13 15:46:00 +01:00
|
|
|
|
2025-01-17 00:37:25 +01:00
|
|
|
a := analyzer.NewAnalyzer()
|
2025-01-13 15:46:00 +01:00
|
|
|
|
2025-01-17 00:37:25 +01:00
|
|
|
for k, v := range test.options {
|
|
|
|
err := a.Flags.Set(k, v)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2025-01-13 15:46:00 +01:00
|
|
|
|
2025-01-17 00:37:25 +01:00
|
|
|
analysistest.Run(t, analysistest.TestData(), a, test.dir)
|
|
|
|
})
|
|
|
|
}
|
2024-03-27 19:24:38 +01:00
|
|
|
}
|