Skip to content

Commit 2aeaecc

Browse files
committed
tests: hide warn during tests
1 parent c7e7543 commit 2aeaecc

File tree

7 files changed

+21
-12
lines changed

7 files changed

+21
-12
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ issues:
175175

176176
run:
177177
timeout: 5m
178-
skip-dirs:
178+
skip-dirs: # TODO(ldez): should be replaced by `issues.exclude-dirs` after the next release.
179179
- test/testdata_etc # test files
180180
- internal/cache # extracted from Go code
181181
- internal/renameio # extracted from Go code

pkg/commands/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func (c *runCommand) setupExitCode(ctx context.Context) {
460460
return
461461
}
462462

463-
needFailOnWarnings := os.Getenv(lintersdb.EnvTestRun) == "1" || os.Getenv(envFailOnWarnings) == "1"
463+
needFailOnWarnings := os.Getenv(logutils.EnvTestRun) == "1" || os.Getenv(envFailOnWarnings) == "1"
464464
if needFailOnWarnings && len(c.reportData.Warnings) != 0 {
465465
c.exitCode = exitcodes.WarningInTest
466466
return

pkg/config/loader.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,24 @@ func (l *Loader) handleGoVersion() {
118118

119119
func (l *Loader) handleDeprecation() {
120120
if len(l.cfg.Run.SkipFiles) > 0 {
121-
l.log.Warnf("The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.")
121+
l.warn("The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.")
122122
l.cfg.Issues.ExcludeFiles = l.cfg.Run.SkipFiles
123123
}
124124

125125
if len(l.cfg.Run.SkipDirs) > 0 {
126-
l.log.Warnf("The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`.")
126+
l.warn("The configuration option `run.skip-dirs` is deprecated, please use `issues.exclude-dirs`.")
127127
l.cfg.Issues.ExcludeDirs = l.cfg.Run.SkipDirs
128128
}
129129

130130
// The 2 options are true by default.
131131
if !l.cfg.Run.UseDefaultSkipDirs {
132-
l.log.Warnf("The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`.")
132+
l.warn("The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`.")
133133
}
134134
l.cfg.Issues.UseDefaultExcludeDirs = l.cfg.Run.UseDefaultSkipDirs && l.cfg.Issues.UseDefaultExcludeDirs
135135

136136
// The 2 options are false by default.
137137
if l.cfg.Run.ShowStats {
138-
l.log.Warnf("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`")
138+
l.warn("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`")
139139
}
140140
l.cfg.Output.ShowStats = l.cfg.Run.ShowStats || l.cfg.Output.ShowStats
141141
}
@@ -319,6 +319,14 @@ func (l *Loader) appendStringSlice(name string, current *[]string) {
319319
}
320320
}
321321

322+
func (l *Loader) warn(format string) {
323+
if l.cfg.InternalTest || l.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" {
324+
return
325+
}
326+
327+
l.log.Warnf(format)
328+
}
329+
322330
func fileDecoderHook() viper.DecoderConfigOption {
323331
return viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
324332
// Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).

pkg/lint/lintersdb/manager.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import (
1414
"github.com/golangci/golangci-lint/pkg/logutils"
1515
)
1616

17-
// EnvTestRun value: "1"
18-
const EnvTestRun = "GL_TEST_RUN"
19-
2017
type Builder interface {
2118
Build(cfg *config.Config) ([]*linter.Config, error)
2219
}
@@ -97,7 +94,7 @@ func (m *Manager) GetAllLinterConfigsForPreset(p string) []*linter.Config {
9794
func (m *Manager) GetEnabledLintersMap() (map[string]*linter.Config, error) {
9895
enabledLinters := m.build(m.GetAllEnabledByDefaultLinters())
9996

100-
if os.Getenv(EnvTestRun) == "1" {
97+
if os.Getenv(logutils.EnvTestRun) == "1" {
10198
m.verbosePrintLintersStatus(enabledLinters)
10299
}
103100

pkg/logutils/logutils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"strings"
66
)
77

8+
// EnvTestRun value: "1"
9+
const EnvTestRun = "GL_TEST_RUN"
10+
811
// envDebug value: one or several debug keys.
912
// examples:
1013
// - Remove output to `/dev/null`: `GL_DEBUG=linters_output ./golangci-lint run`

test/enabled_linters_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
"github.com/stretchr/testify/require"
1111

1212
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
13+
"github.com/golangci/golangci-lint/pkg/logutils"
1314
"github.com/golangci/golangci-lint/test/testshared"
1415
)
1516

1617
func TestEnabledLinters(t *testing.T) {
1718
// require to display the message "Active x linters: [x,y]"
18-
t.Setenv(lintersdb.EnvTestRun, "1")
19+
t.Setenv(logutils.EnvTestRun, "1")
1920

2021
cases := []struct {
2122
name string

test/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func TestSkippedDirsNoMatchArg(t *testing.T) {
370370
WithNoConfig().
371371
WithArgs(
372372
"--print-issued-lines=false",
373-
"--skip-dirs", dir,
373+
"--exclude-dirs", dir,
374374
"-Erevive",
375375
).
376376
WithTargetPath(dir).

0 commit comments

Comments
 (0)