Skip to content

Commit 4f0fddf

Browse files
committed
add tests for abs path args
1 parent baa2415 commit 4f0fddf

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ linters:
3232
- prealloc
3333
- gosec
3434
- gochecknoglobals
35+
36+
run:
37+
skip-dirs:
38+
- test/testdata_etc

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
test:
22
go build -o golangci-lint ./cmd/golangci-lint
33
GL_TEST_RUN=1 ./golangci-lint run -v
4-
GL_TEST_RUN=1 ./golangci-lint run --fast --no-config -v
5-
GL_TEST_RUN=1 ./golangci-lint run --no-config -v
4+
GL_TEST_RUN=1 ./golangci-lint run --fast --no-config -v --skip-dirs test/testdata_etc
5+
GL_TEST_RUN=1 ./golangci-lint run --no-config -v --skip-dirs test/testdata_etc
66
GL_TEST_RUN=1 go test -v ./...
77

88
test_race:

test/run_test.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package test
22

33
import (
4+
"path/filepath"
45
"testing"
56

7+
"github.com/stretchr/testify/assert"
8+
69
"github.com/golangci/golangci-lint/test/testshared"
710

811
"github.com/golangci/golangci-lint/pkg/exitcodes"
912
)
1013

11-
func TestNoIssues(t *testing.T) {
12-
testshared.NewLintRunner(t).Run(getProjectRoot()).ExpectNoIssues()
14+
func getCommonRunArgs() []string {
15+
return []string{"--skip-dirs", "testdata_etc/"}
16+
}
17+
18+
func withCommonRunArgs(args ...string) []string {
19+
return append(getCommonRunArgs(), args...)
1320
}
1421

1522
func TestAutogeneratedNoIssues(t *testing.T) {
@@ -92,15 +99,33 @@ func TestConfigFileIsDetected(t *testing.T) {
9299

93100
func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
94101
r := testshared.NewLintRunner(t)
95-
r.Run("--fast", "--enable-all", "--enable=typecheck").ExpectNoIssues()
96-
r.Run("--enable-all", "--enable=typecheck").ExpectExitCode(exitcodes.Failure)
102+
r.Run(withCommonRunArgs("--fast", "--enable-all", "--enable=typecheck")...).ExpectNoIssues()
103+
r.Run(withCommonRunArgs("--enable-all", "--enable=typecheck")...).ExpectExitCode(exitcodes.Failure)
97104
}
98105

99106
func TestEnabledPresetsAreNotDuplicated(t *testing.T) {
100107
testshared.NewLintRunner(t).Run("--no-config", "-v", "-p", "style,bugs").
101108
ExpectOutputContains("Active presets: [bugs style]")
102109
}
103110

111+
func TestAbsPathDirAnalysis(t *testing.T) {
112+
dir := filepath.Join("testdata_etc", "abspath") // abs paths don't work with testdata dir
113+
absDir, err := filepath.Abs(dir)
114+
assert.NoError(t, err)
115+
116+
r := testshared.NewLintRunner(t).Run("--print-issued-lines=false", "--no-config", "-Egolint", absDir)
117+
r.ExpectHasIssue("if block ends with a return statement")
118+
}
119+
120+
func TestAbsPathFileAnalysis(t *testing.T) {
121+
dir := filepath.Join("testdata_etc", "abspath", "with_issue.go") // abs paths don't work with testdata dir
122+
absDir, err := filepath.Abs(dir)
123+
assert.NoError(t, err)
124+
125+
r := testshared.NewLintRunner(t).Run("--print-issued-lines=false", "--no-config", "-Egolint", absDir)
126+
r.ExpectHasIssue("if block ends with a return statement")
127+
}
128+
104129
func TestDisallowedOptionsInConfig(t *testing.T) {
105130
type tc struct {
106131
cfg string
@@ -141,7 +166,7 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
141166
r := testshared.NewLintRunner(t)
142167
for _, c := range cases {
143168
// Run with disallowed option set only in config
144-
r.RunWithYamlConfig(c.cfg).ExpectExitCode(exitcodes.Failure)
169+
r.RunWithYamlConfig(c.cfg, getCommonRunArgs()...).ExpectExitCode(exitcodes.Failure)
145170

146171
if c.option == "" {
147172
continue
@@ -150,9 +175,9 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
150175
args := []string{c.option, "--fast"}
151176

152177
// Run with disallowed option set only in command-line
153-
r.Run(args...).ExpectExitCode(exitcodes.Success)
178+
r.Run(withCommonRunArgs(args...)...).ExpectExitCode(exitcodes.Success)
154179

155180
// Run with disallowed option set both in command-line and in config
156-
r.RunWithYamlConfig(c.cfg, args...).ExpectExitCode(exitcodes.Failure)
181+
r.RunWithYamlConfig(c.cfg, withCommonRunArgs(args...)...).ExpectExitCode(exitcodes.Failure)
157182
}
158183
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package abspath
2+
3+
import "fmt"
4+
5+
func f() {
6+
if true {
7+
return
8+
} else {
9+
fmt.Printf("")
10+
}
11+
}

0 commit comments

Comments
 (0)