add tests for abs path args

This commit is contained in:
Denis Isaev 2018-12-22 14:16:02 +03:00
parent baa2415ddf
commit 4f0fddf4fe
No known key found for this signature in database
GPG Key ID: A36A0EC8E27A1A01
4 changed files with 49 additions and 9 deletions

View File

@ -32,3 +32,7 @@ linters:
- prealloc - prealloc
- gosec - gosec
- gochecknoglobals - gochecknoglobals
run:
skip-dirs:
- test/testdata_etc

View File

@ -1,8 +1,8 @@
test: test:
go build -o golangci-lint ./cmd/golangci-lint go build -o golangci-lint ./cmd/golangci-lint
GL_TEST_RUN=1 ./golangci-lint run -v 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 --fast --no-config -v --skip-dirs test/testdata_etc
GL_TEST_RUN=1 ./golangci-lint run --no-config -v GL_TEST_RUN=1 ./golangci-lint run --no-config -v --skip-dirs test/testdata_etc
GL_TEST_RUN=1 go test -v ./... GL_TEST_RUN=1 go test -v ./...
test_race: test_race:

View File

@ -1,15 +1,22 @@
package test package test
import ( import (
"path/filepath"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/golangci/golangci-lint/test/testshared" "github.com/golangci/golangci-lint/test/testshared"
"github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/exitcodes"
) )
func TestNoIssues(t *testing.T) { func getCommonRunArgs() []string {
testshared.NewLintRunner(t).Run(getProjectRoot()).ExpectNoIssues() return []string{"--skip-dirs", "testdata_etc/"}
}
func withCommonRunArgs(args ...string) []string {
return append(getCommonRunArgs(), args...)
} }
func TestAutogeneratedNoIssues(t *testing.T) { func TestAutogeneratedNoIssues(t *testing.T) {
@ -92,8 +99,8 @@ func TestConfigFileIsDetected(t *testing.T) {
func TestEnableAllFastAndEnableCanCoexist(t *testing.T) { func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
r := testshared.NewLintRunner(t) r := testshared.NewLintRunner(t)
r.Run("--fast", "--enable-all", "--enable=typecheck").ExpectNoIssues() r.Run(withCommonRunArgs("--fast", "--enable-all", "--enable=typecheck")...).ExpectNoIssues()
r.Run("--enable-all", "--enable=typecheck").ExpectExitCode(exitcodes.Failure) r.Run(withCommonRunArgs("--enable-all", "--enable=typecheck")...).ExpectExitCode(exitcodes.Failure)
} }
func TestEnabledPresetsAreNotDuplicated(t *testing.T) { func TestEnabledPresetsAreNotDuplicated(t *testing.T) {
@ -101,6 +108,24 @@ func TestEnabledPresetsAreNotDuplicated(t *testing.T) {
ExpectOutputContains("Active presets: [bugs style]") 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) { func TestDisallowedOptionsInConfig(t *testing.T) {
type tc struct { type tc struct {
cfg string cfg string
@ -141,7 +166,7 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
r := testshared.NewLintRunner(t) r := testshared.NewLintRunner(t)
for _, c := range cases { for _, c := range cases {
// Run with disallowed option set only in config // 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 == "" { if c.option == "" {
continue continue
@ -150,9 +175,9 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
args := []string{c.option, "--fast"} args := []string{c.option, "--fast"}
// Run with disallowed option set only in command-line // 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 // 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)
} }
} }

View File

@ -0,0 +1,11 @@
package abspath
import "fmt"
func f() {
if true {
return
} else {
fmt.Printf("")
}
}