add staticcheck GoTool test

This commit is contained in:
Shawn Smith
2022-03-26 16:50:28 +09:00
parent df65088286
commit a22b7c5858
3 changed files with 39 additions and 5 deletions

12
check/testfiles/d.go Normal file
View File

@@ -0,0 +1,12 @@
package testfiles
import (
"fmt"
"time"
)
func foo() {
a := time.Now()
b := a.Sub(time.Now())
fmt.Println(a, b)
}

View File

@@ -335,7 +335,10 @@ outer:
// GoTool runs a given go command (for example gofmt, go tool vet)
// on a directory
func GoTool(dir string, filenames, command []string) (float64, []FileSummary, error) {
enabledCheck := command[len(command)-1]
var enabledCheck = command[0]
if command[0] == "gometalinter" {
enabledCheck = command[len(command)-1]
}
// temporary disabling of misspell as it's the slowest
// command right now
@@ -350,7 +353,10 @@ func GoTool(dir string, filenames, command []string) (float64, []FileSummary, er
}
params := command[1:]
params = addSkipDirs(params)
if command[0] == "gometalinter" {
params = addSkipDirs(params)
}
switch {
case strings.Contains(enabledCheck, "cyclo"):

View File

@@ -10,7 +10,7 @@ func TestGoFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := []string{"testfiles/a.go", "testfiles/b.go", "testfiles/c.go"}
want := []string{"testfiles/a.go", "testfiles/b.go", "testfiles/c.go", "testfiles/d.go"}
if !reflect.DeepEqual(files, want) {
t.Errorf("GoFiles(%q) = %v, want %v", "testfiles/", files, want)
}
@@ -30,7 +30,23 @@ var goToolTests = []struct {
failed []FileSummary
wantErr bool
}{
{"go vet", "testfiles/", []string{"testfiles/a.go", "testfiles/b.go", "testfiles/c.go"}, []string{"go", "tool", "vet"}, 1, []FileSummary{}, false},
{"go vet", "testfiles", []string{"testfiles/a.go", "testfiles/b.go", "testfiles/c.go"}, []string{"go", "vet"}, 1, []FileSummary{}, false},
{
"staticcheck",
"testfiles/",
[]string{"testfiles/a.go", "testfiles/b.go", "testfiles/c.go", "testfiles/d.go"},
[]string{"staticcheck", "./..."},
0.75,
[]FileSummary{
{
Filename: "testfiles/d.go", FileURL: "",
Errors: []Error{
{LineNumber: 8, ErrorString: " func foo is unused (U1000)"},
{LineNumber: 10, ErrorString: " should use time.Until instead of t.Sub(time.Now()) (S1024)"}},
},
},
false,
},
}
func TestGoTool(t *testing.T) {
@@ -43,7 +59,7 @@ func TestGoTool(t *testing.T) {
t.Errorf("[%s] GoTool percent = %f, want %f", tt.name, f, tt.percent)
}
if !reflect.DeepEqual(fs, tt.failed) {
t.Errorf("[%s] GoTool failed = %v, want %v", tt.name, fs, tt.failed)
t.Errorf("[%s] GoTool failed = %#v, want %v", tt.name, fs, tt.failed)
}
}
}