diff --git a/.golangci.yml b/.golangci.yml index ac1ed39e..b6fcaa96 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,3 +32,7 @@ linters: - prealloc - gosec - gochecknoglobals + +run: + skip-dirs: + - test/testdata_etc \ No newline at end of file diff --git a/Makefile b/Makefile index 5ff27222..4c2fc74d 100644 --- a/Makefile +++ b/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: diff --git a/test/run_test.go b/test/run_test.go index c5c4818f..96a54909 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -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) } } diff --git a/test/testdata_etc/abspath/with_issue.go b/test/testdata_etc/abspath/with_issue.go new file mode 100644 index 00000000..e68f3ab0 --- /dev/null +++ b/test/testdata_etc/abspath/with_issue.go @@ -0,0 +1,11 @@ +package abspath + +import "fmt" + +func f() { + if true { + return + } else { + fmt.Printf("") + } +}