未验证 提交 038cd99b 编写于 作者: A Alessandro Arzilli 提交者: GitHub

tests: run staticcheck during tests (#2705)

上级 041eedd1
pkg/dwarf/dwarfbuilder/info.go:122:2: redundant return statement (S1023)
pkg/dwarf/dwarfbuilder/info.go:127:5: builtin function len does not return negative values (SA4024)
pkg/dwarf/line/line_parser.go:249:6: every value of type uint64 is >= 0 (SA4003)
pkg/dwarf/line/line_parser.go:286:15: should omit type int from declaration; it will be inferred from the right-hand side (ST1023)
pkg/dwarf/line/state_machine.go:151:2: redundant return statement (S1023)
pkg/dwarf/line/state_machine.go:154:5: error var NoSourceError should have name of the form ErrFoo (ST1012)
pkg/dwarf/line/state_machine.go:193:2: should merge variable declaration with assignment on next line (S1021)
pkg/dwarf/reader/reader.go:77:5: error var TypeNotFoundErr should have name of the form ErrFoo (ST1012)
pkg/goversion/compat.go:12:2: error var goTooOldErr should have name of the form errFoo (ST1012)
pkg/goversion/compat.go:12:33: error strings should not be capitalized (ST1005)
pkg/goversion/compat.go:13:2: error var dlvTooOldErr should have name of the form errFoo (ST1012)
pkg/goversion/compat.go:13:33: error strings should not be capitalized (ST1005)
pkg/locspec/locations.go:71:10: error strings should not be capitalized (ST1005)
pkg/locspec/locations.go:110:10: error strings should not be capitalized (ST1005)
pkg/locspec/locations.go:423:16: error strings should not be capitalized (ST1005)
pkg/proc/bininfo.go:249:18: unnecessary assignment to the blank identifier (S1005)
pkg/proc/bininfo.go:253:19: unnecessary assignment to the blank identifier (S1005)
pkg/proc/bininfo.go:257:19: unnecessary assignment to the blank identifier (S1005)
pkg/proc/bininfo.go:1268:2: unnecessary nil check around range (S1031)
pkg/proc/core/minidump/fileflags_string.go:62:7: every value of type uint16 is >= 0 (SA4003)
pkg/proc/core/minidump/minidump.go:424:3: should merge variable declaration with assignment on next line (S1021)
pkg/proc/eval.go:324:10: error strings should not be capitalized (ST1005)
pkg/proc/eval.go:395:10: error strings should not be capitalized (ST1005)
pkg/proc/eval.go:399:10: error strings should not be capitalized (ST1005)
pkg/proc/native/threads_linux_amd64.go:42:3: redundant return statement (S1023)
pkg/proc/stack.go:398:2: this value of err is never used (SA4006)
pkg/proc/stack.go:424:12: error strings should not be capitalized (ST1005)
pkg/proc/target_exec.go:161:6: this value of err is never used (SA4006)
pkg/proc/target_exec.go:810:3: when isexists is true, err can't be nil (S1020)
pkg/proc/variables.go:1481:21: error strings should not be capitalized (ST1005)
pkg/proc/variables.go:1569:18: error strings should not be capitalized (ST1005)
pkg/proc/variables.go:2243:44: should use !strings.Contains(typename, ".") instead (S1003)
pkg/proc/variables.go:2385:4: should replace this if statement with an unconditional strings.TrimPrefix (S1017)
pkg/proc/winutil/regs.go:167:2: should merge variable declaration with assignment on next line (S1021)
pkg/terminal/command.go:650:5: error var noCmdError should have name of the form errFoo (ST1012)
pkg/terminal/command.go:986:9: unnecessary assignment to the blank identifier (S1005)
pkg/terminal/command.go:1062:10: error strings should not be capitalized (ST1005)
pkg/terminal/command.go:1069:10: error strings should not be capitalized (ST1005)
pkg/terminal/command.go:1337:15: error strings should not be capitalized (ST1005)
pkg/terminal/command.go:1521:15: error strings should not be capitalized (ST1005)
pkg/terminal/command.go:1544:5: error var notOnFrameZeroErr should have name of the form errFoo (ST1012)
pkg/terminal/command.go:1600:10: error strings should not be capitalized (ST1005)
pkg/terminal/command.go:1915:11: error strings should not be capitalized (ST1005)
pkg/terminal/command.go:2420:25: error strings should not be capitalized (ST1005)
pkg/terminal/command.go:2479:5: error var disasmUsageError should have name of the form errFoo (ST1012)
pkg/terminal/starbind/conv.go:243:40: 'bitSize' argument is invalid, must be either 32 or 64 (SA1030)
pkg/terminal/starbind/conv.go:292:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025)
pkg/terminal/starbind/conv.go:352:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025)
pkg/terminal/starbind/conv.go:418:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025)
pkg/terminal/starbind/conv.go:497:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025)
pkg/terminal/terminal.go:282:14: error strings should not be capitalized (ST1005)
pkg/terminal/terminal.go:282:14: error strings should not end with punctuation or a newline (ST1005)
service/api/prettyprint.go:156:9: should omit type bool from declaration; it will be inferred from the right-hand side (ST1023)
service/api/prettyprint.go:190:9: should omit type complex128 from declaration; it will be inferred from the right-hand side (ST1023)
service/dap/server.go:1448:11: should omit type AttachConfig from declaration; it will be inferred from the right-hand side (ST1023)
service/dap/utils.go:5:6: func min is unused (U1000)
service/debugger/debugger.go:946:5: builtin function len does not return negative values (SA4024)
service/debugger/debugger_linux.go:20:12: error strings should not be capitalized (ST1005)
service/debugger/debugger_linux.go:27:12: error strings should not be capitalized (ST1005)
service/rpc1/client.go:23:5: error var unsupportedApiError should have name of the form errFoo (ST1012)
service/rpc1/client.go:78:17: error strings should not be capitalized (ST1005)
service/rpc2/client.go:111:17: error strings should not be capitalized (ST1005)
......@@ -42,6 +42,7 @@ GOPATH=$(pwd)/go
export GOPATH
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
go version
go install honnef.co/go/tools/cmd/staticcheck@2021.1.1 || true
uname -a
echo "$PATH"
......
......@@ -7,7 +7,7 @@ param (
#Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install MinGW.
choco install -y mingw
choco install -y mingw --version 10.2.0
# Install Procdump
if (-Not(Test-Path "C:\procdump"))
......
......@@ -362,6 +362,7 @@ func checkAutogenDoc(t *testing.T, filename, gencommand string, generated []byte
if checkAutogenDocLongOutput {
t.Logf("generated %q saved %q\n", generated, saved)
}
diffMaybe(t, filename, generated)
t.Fatalf("%s: needs to be regenerated; run %s", filename, gencommand)
}
......@@ -370,6 +371,7 @@ func checkAutogenDoc(t *testing.T, filename, gencommand string, generated []byte
if checkAutogenDocLongOutput {
t.Logf("generated %q saved %q\n", generated, saved)
}
diffMaybe(t, filename, generated)
t.Fatalf("%s: needs to be regenerated; run %s", filename, gencommand)
}
}
......@@ -383,6 +385,22 @@ func slurpFile(t *testing.T, filename string) []byte {
return saved
}
func diffMaybe(t *testing.T, filename string, generated []byte) {
_, err := exec.LookPath("diff")
if err != nil {
return
}
cmd := exec.Command("diff", filename, "-")
cmd.Dir = projectRoot()
stdin, _ := cmd.StdinPipe()
go func() {
stdin.Write(generated)
stdin.Close()
}()
out, _ := cmd.CombinedOutput()
t.Logf("diff:\n%s", string(out))
}
// TestGeneratedDoc tests that the autogenerated documentation has been
// updated.
func TestGeneratedDoc(t *testing.T) {
......@@ -863,3 +881,17 @@ func TestVersion(t *testing.T) {
t.Errorf("got %s\nwant %v and %v in the output", got, want1, want2)
}
}
func TestStaticcheck(t *testing.T) {
_, err := exec.LookPath("staticcheck")
if err != nil {
t.Skip("staticcheck not installed")
}
// default checks minus SA1019 which complains about deprecated identifiers, which change between versions of Go.
args := []string{"-tests=false", "-checks=all,-SA1019,-ST1000,-ST1003,-ST1016,-ST1020,-ST1021,-ST1022", "github.com/go-delve/delve/..."}
cmd := exec.Command("staticcheck", args...)
cmd.Dir = projectRoot()
cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64")
out, _ := cmd.CombinedOutput()
checkAutogenDoc(t, "_scripts/staticcheck-out.txt", fmt.Sprintf("staticcheck %s > _scripts/staticcheck-out.txt", strings.Join(args, " ")), out)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册