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
|
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 {
|
||||||
|
err := a.Flags.Set(k, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
analysistest.Run(t, testdata, an, "./common")
|
analysistest.Run(t, analysistest.TestData(), a, test.dir)
|
||||||
analysistest.Run(t, testdata, an, "./structpointer")
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue