11package test
22
33import (
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
1522func TestAutogeneratedNoIssues (t * testing.T ) {
@@ -92,15 +99,33 @@ func TestConfigFileIsDetected(t *testing.T) {
9299
93100func 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
99106func 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+
104129func 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}
0 commit comments