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