tests: rewrite tests

This commit is contained in:
Fernandez Ludovic 2025-01-17 00:37:25 +01:00 committed by Gabriel Augendre
parent f887074f5d
commit 7b0afb1f92
4 changed files with 40 additions and 20 deletions

View file

@ -1,8 +1,6 @@
package analyzer_test
import (
"os"
"path/filepath"
"testing"
"golang.org/x/tools/go/analysis/analysistest"
@ -11,27 +9,49 @@ import (
)
func TestAnalyzer(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get wd: %s", err)
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",
},
},
}
testdata := filepath.Join(wd, "testdata")
t.Run("no func decl", func(t *testing.T) {
an := analyzer.NewAnalyzer()
analysistest.Run(t, testdata, an, "./common")
analysistest.Run(t, testdata, an, "./no_structpointer")
})
for _, test := range testCases {
t.Run(test.desc+"_"+test.dir, func(t *testing.T) {
t.Parallel()
t.Run("func decl", func(t *testing.T) {
an := analyzer.NewAnalyzer()
a := analyzer.NewAnalyzer()
err := an.Flags.Set(analyzer.FlagCheckStructPointers, "true")
for k, v := range test.options {
err := a.Flags.Set(k, v)
if err != nil {
t.Fatal(err)
}
}
analysistest.Run(t, testdata, an, "./common")
analysistest.Run(t, testdata, an, "./structpointer")
analysistest.Run(t, analysistest.TestData(), a, test.dir)
})
}
}