mirror of
https://github.com/Crocmagnon/fatcontext.git
synced 2025-02-05 12:12:32 +01:00
tests: rewrite tests
This commit is contained in:
parent
f887074f5d
commit
7b0afb1f92
4 changed files with 40 additions and 20 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue