1
1
package test
2
2
3
3
import (
4
+ "path/filepath"
4
5
"testing"
5
6
7
+ "github.com/stretchr/testify/assert"
8
+
6
9
"github.com/golangci/golangci-lint/test/testshared"
7
10
8
11
"github.com/golangci/golangci-lint/pkg/exitcodes"
9
12
)
10
13
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 ... )
13
20
}
14
21
15
22
func TestAutogeneratedNoIssues (t * testing.T ) {
@@ -92,15 +99,33 @@ func TestConfigFileIsDetected(t *testing.T) {
92
99
93
100
func TestEnableAllFastAndEnableCanCoexist (t * testing.T ) {
94
101
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 )
97
104
}
98
105
99
106
func TestEnabledPresetsAreNotDuplicated (t * testing.T ) {
100
107
testshared .NewLintRunner (t ).Run ("--no-config" , "-v" , "-p" , "style,bugs" ).
101
108
ExpectOutputContains ("Active presets: [bugs style]" )
102
109
}
103
110
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
+
104
129
func TestDisallowedOptionsInConfig (t * testing.T ) {
105
130
type tc struct {
106
131
cfg string
@@ -141,7 +166,7 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
141
166
r := testshared .NewLintRunner (t )
142
167
for _ , c := range cases {
143
168
// 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 )
145
170
146
171
if c .option == "" {
147
172
continue
@@ -150,9 +175,9 @@ func TestDisallowedOptionsInConfig(t *testing.T) {
150
175
args := []string {c .option , "--fast" }
151
176
152
177
// Run with disallowed option set only in command-line
153
- r .Run (args ... ).ExpectExitCode (exitcodes .Success )
178
+ r .Run (withCommonRunArgs ( args ... ) ... ).ExpectExitCode (exitcodes .Success )
154
179
155
180
// 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 )
157
182
}
158
183
}
0 commit comments