add tests for abs path args
This commit is contained in:
parent
baa2415ddf
commit
4f0fddf4fe
@ -32,3 +32,7 @@ linters:
|
||||
- prealloc
|
||||
- gosec
|
||||
- gochecknoglobals
|
||||
|
||||
run:
|
||||
skip-dirs:
|
||||
- test/testdata_etc
|
4
Makefile
4
Makefile
@ -1,8 +1,8 @@
|
||||
test:
|
||||
go build -o golangci-lint ./cmd/golangci-lint
|
||||
GL_TEST_RUN=1 ./golangci-lint run -v
|
||||
GL_TEST_RUN=1 ./golangci-lint run --fast --no-config -v
|
||||
GL_TEST_RUN=1 ./golangci-lint run --no-config -v
|
||||
GL_TEST_RUN=1 ./golangci-lint run --fast --no-config -v --skip-dirs test/testdata_etc
|
||||
GL_TEST_RUN=1 ./golangci-lint run --no-config -v --skip-dirs test/testdata_etc
|
||||
GL_TEST_RUN=1 go test -v ./...
|
||||
|
||||
test_race:
|
||||
|
@ -1,15 +1,22 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/golangci/golangci-lint/test/testshared"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
||||
)
|
||||
|
||||
func TestNoIssues(t *testing.T) {
|
||||
testshared.NewLintRunner(t).Run(getProjectRoot()).ExpectNoIssues()
|
||||
func getCommonRunArgs() []string {
|
||||
return []string{"--skip-dirs", "testdata_etc/"}
|
||||
}
|
||||
|
||||
func withCommonRunArgs(args ...string) []string {
|
||||
return append(getCommonRunArgs(), args...)
|
||||
}
|
||||
|
||||
func TestAutogeneratedNoIssues(t *testing.T) {
|
||||
@ -92,8 +99,8 @@ func TestConfigFileIsDetected(t *testing.T) {
|
||||
|
||||
func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
|
||||
r := testshared.NewLintRunner(t)
|
||||
r.Run("--fast", "--enable-all", "--enable=typecheck").ExpectNoIssues()
|
||||
r.Run("--enable-all", "--enable=typecheck").ExpectExitCode(exitcodes.Failure)
|
||||
r.Run(withCommonRunArgs("--fast", "--enable-all", "--enable=typecheck")...).ExpectNoIssues()
|
||||
r.Run(withCommonRunArgs("--enable-all", "--enable=typecheck")...).ExpectExitCode(exitcodes.Failure)
|
||||
}
|
||||
|
||||
func TestEnabledPresetsAreNotDuplicated(t *testing.T) {
|
||||
@ -101,6 +108,24 @@ func TestEnabledPresetsAreNotDuplicated(t *testing.T) {
|
||||
ExpectOutputContains("Active presets: [bugs style]")
|
||||
}
|
||||
|
||||
func TestAbsPathDirAnalysis(t *testing.T) {
|
||||
dir := filepath.Join("testdata_etc", "abspath") // abs paths don't work with testdata dir
|
||||
absDir, err := filepath.Abs(dir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
r := testshared.NewLintRunner(t).Run("--print-issued-lines=false", "--no-config", "-Egolint", absDir)
|
||||
r.ExpectHasIssue("if block ends with a return statement")
|
||||
}
|
||||
|
||||
func TestAbsPathFileAnalysis(t *testing.T) {
|
||||
dir := filepath.Join("testdata_etc", "abspath", "with_issue.go") // abs paths don't work with testdata dir
|
||||
absDir, err := filepath.Abs(dir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
r := testshared.NewLintRunner(t).Run("--print-issued-lines=false", "--no-config", "-Egolint", absDir)
|
||||
r.ExpectHasIssue("if block ends with a return statement")
|
||||
}
|
||||
|
||||
func TestDisallowedOptionsInConfig(t *testing.T) {
|
||||
type tc struct {
|
||||
cfg string
|
||||
@ -141,7 +166,7 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
|
||||
r := testshared.NewLintRunner(t)
|
||||
for _, c := range cases {
|
||||
// Run with disallowed option set only in config
|
||||
r.RunWithYamlConfig(c.cfg).ExpectExitCode(exitcodes.Failure)
|
||||
r.RunWithYamlConfig(c.cfg, getCommonRunArgs()...).ExpectExitCode(exitcodes.Failure)
|
||||
|
||||
if c.option == "" {
|
||||
continue
|
||||
@ -150,9 +175,9 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
|
||||
args := []string{c.option, "--fast"}
|
||||
|
||||
// Run with disallowed option set only in command-line
|
||||
r.Run(args...).ExpectExitCode(exitcodes.Success)
|
||||
r.Run(withCommonRunArgs(args...)...).ExpectExitCode(exitcodes.Success)
|
||||
|
||||
// Run with disallowed option set both in command-line and in config
|
||||
r.RunWithYamlConfig(c.cfg, args...).ExpectExitCode(exitcodes.Failure)
|
||||
r.RunWithYamlConfig(c.cfg, withCommonRunArgs(args...)...).ExpectExitCode(exitcodes.Failure)
|
||||
}
|
||||
}
|
||||
|
11
test/testdata_etc/abspath/with_issue.go
Normal file
11
test/testdata_etc/abspath/with_issue.go
Normal file
@ -0,0 +1,11 @@
|
||||
package abspath
|
||||
|
||||
import "fmt"
|
||||
|
||||
func f() {
|
||||
if true {
|
||||
return
|
||||
} else {
|
||||
fmt.Printf("")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user