From 0bd5bf248280e10b2303ba10a8592c58338b198b Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Fri, 25 Sep 2020 00:19:14 -0700 Subject: [PATCH 01/16] Ignore crlf on windows --- .gitattributes | 2 ++ .github/workflows/pr.yml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 32f1001be0a5..68e025fca667 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ go.sum linguist-generated +* text=auto eol=lf +*.ps1 text eol=crlf \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 484394b0dc2d..2c7b84661840 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -44,7 +44,6 @@ jobs: go-version: 1.15 # test only the latest go version to speed up CI - name: Run tests run: make.exe test - continue-on-error: true tests-on-macos: needs: golangci-lint # run after golangci-lint action to not produce duplicated errors runs-on: macos-latest From cdf106adf0d58b2c75fc0ee45cd858182f11451e Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Fri, 25 Sep 2020 23:13:04 -0700 Subject: [PATCH 02/16] fix invalid path --- test/testshared/testshared.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index 8effe2bad0bf..d9107d4a8a46 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "os" "os/exec" + "path/filepath" "strings" "sync" "syscall" @@ -99,7 +100,7 @@ func (r *LintRunner) RunCommand(command string, args ...string) *RunResult { r.log.Infof("ran [../golangci-lint %s] in %s", strings.Join(runArgs, " "), time.Since(startedAt)) }(time.Now()) - cmd := exec.Command("../golangci-lint", runArgs...) + cmd := exec.Command(filepath.Join("..", "golangci-lint"), runArgs...) cmd.Env = append(os.Environ(), r.env...) out, err := cmd.CombinedOutput() if err != nil { From b7c5e9086bca401771d3dacafbb5da6f7101849c Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Fri, 25 Sep 2020 23:18:00 -0700 Subject: [PATCH 03/16] fix G204 --- test/testshared/testshared.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index d9107d4a8a46..12af88ddd509 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -100,7 +100,8 @@ func (r *LintRunner) RunCommand(command string, args ...string) *RunResult { r.log.Infof("ran [../golangci-lint %s] in %s", strings.Join(runArgs, " "), time.Since(startedAt)) }(time.Now()) - cmd := exec.Command(filepath.Join("..", "golangci-lint"), runArgs...) + binPath := filepath.Join("..", "golangci-lint") + cmd := exec.Command(binPath, runArgs...) cmd.Env = append(os.Environ(), r.env...) out, err := cmd.CombinedOutput() if err != nil { From 90c0e8f30c15aeb8395414702166214016b55d8e Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Fri, 25 Sep 2020 23:41:28 -0700 Subject: [PATCH 04/16] try to switch to require instead of assert --- test/testshared/testshared.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index 12af88ddd509..9c6fc68d15de 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -11,19 +11,20 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/logutils" ) type LintRunner struct { - t assert.TestingT + t require.TestingT log logutils.Log env []string installOnce sync.Once } -func NewLintRunner(t assert.TestingT, environ ...string) *LintRunner { +func NewLintRunner(t require.TestingT, environ ...string) *LintRunner { log := logutils.NewStderrLog("test") log.SetLevel(logutils.LogLevelInfo) return &LintRunner{ @@ -40,7 +41,7 @@ func (r *LintRunner) Install() { } cmd := exec.Command("make", "-C", "..", "build") - assert.NoError(r.t, cmd.Run(), "Can't go install golangci-lint") + require.NoError(r.t, cmd.Run(), "Can't go install golangci-lint") }) } @@ -95,12 +96,12 @@ func (r *LintRunner) Run(args ...string) *RunResult { func (r *LintRunner) RunCommand(command string, args ...string) *RunResult { r.Install() + binPath := filepath.Join("..", "golangci-lint") runArgs := append([]string{command}, args...) defer func(startedAt time.Time) { - r.log.Infof("ran [../golangci-lint %s] in %s", strings.Join(runArgs, " "), time.Since(startedAt)) + r.log.Infof("ran [%s %s] in %s", binPath, strings.Join(runArgs, " "), time.Since(startedAt)) }(time.Now()) - binPath := filepath.Join("..", "golangci-lint") cmd := exec.Command(binPath, runArgs...) cmd.Env = append(os.Environ(), r.env...) out, err := cmd.CombinedOutput() From 4d26b77738749e73a21b14ea76544da193835018 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Fri, 25 Sep 2020 23:50:59 -0700 Subject: [PATCH 05/16] prevent tests to panic on failure --- test/enabled_linters_test.go | 8 +++++--- test/testshared/testshared.go | 7 +++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/enabled_linters_test.go b/test/enabled_linters_test.go index 70cb4ffc47c2..0700739942bb 100644 --- a/test/enabled_linters_test.go +++ b/test/enabled_linters_test.go @@ -184,10 +184,12 @@ func TestEnabledLinters(t *testing.T) { runArgs = append(runArgs, strings.Split(c.args, " ")...) } r := runner.RunCommandWithYamlConfig(c.cfg, "linters", runArgs...) - sort.StringSlice(c.el).Sort() + if r != nil { + sort.StringSlice(c.el).Sort() - expectedLine := fmt.Sprintf("Active %d linters: [%s]", len(c.el), strings.Join(c.el, " ")) - r.ExpectOutputContains(expectedLine) + expectedLine := fmt.Sprintf("Active %d linters: [%s]", len(c.el), strings.Join(c.el, " ")) + r.ExpectOutputContains(expectedLine) + } }) } } diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index 9c6fc68d15de..b153eecdb4f6 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -11,20 +11,19 @@ import ( "time" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/logutils" ) type LintRunner struct { - t require.TestingT + t assert.TestingT log logutils.Log env []string installOnce sync.Once } -func NewLintRunner(t require.TestingT, environ ...string) *LintRunner { +func NewLintRunner(t assert.TestingT, environ ...string) *LintRunner { log := logutils.NewStderrLog("test") log.SetLevel(logutils.LogLevelInfo) return &LintRunner{ @@ -41,7 +40,7 @@ func (r *LintRunner) Install() { } cmd := exec.Command("make", "-C", "..", "build") - require.NoError(r.t, cmd.Run(), "Can't go install golangci-lint") + assert.NoError(r.t, cmd.Run(), "Can't go install golangci-lint") }) } From 92f6607a4ce3e49b12a25e11b078dfce704ce621 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Fri, 25 Sep 2020 23:51:22 -0700 Subject: [PATCH 06/16] go mod tidy --- go.sum | 6 ------ 1 file changed, 6 deletions(-) diff --git a/go.sum b/go.sum index f1d927b333e8..2782c2f8d552 100644 --- a/go.sum +++ b/go.sum @@ -205,7 +205,6 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= @@ -364,8 +363,6 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ= github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM= -github.com/tetafro/godot v0.4.8 h1:h61+hQraWhdI6WYqMwAwZYCE5yxL6a9/Orw4REbabSU= -github.com/tetafro/godot v0.4.8/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0= github.com/tetafro/godot v0.4.9 h1:dSOiuasshpevY73eeI3+zaqFnXSBKJ3mvxbyhh54VRo= github.com/tetafro/godot v0.4.9/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0= github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q= @@ -381,10 +378,7 @@ github.com/uudashr/gocognit v1.0.1 h1:MoG2fZ0b/Eo7NXoIwCVFLG5JED3qgQz5/NEE+rOsjP github.com/uudashr/gocognit v1.0.1/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.15.1/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= -github.com/valyala/quicktemplate v1.6.2 h1:k0vgK7zlmFzqAoIBIOrhrfmZ6JoTGJlLRPLbkPGr2/M= -github.com/valyala/quicktemplate v1.6.2/go.mod h1:mtEJpQtUiBV0SHhMX6RtiJtqxncgrfmjcUy5T68X8TM= github.com/valyala/quicktemplate v1.6.3 h1:O7EuMwuH7Q94U2CXD6sOX8AYHqQqWtmIk690IhmpkKA= github.com/valyala/quicktemplate v1.6.3/go.mod h1:fwPzK2fHuYEODzJ9pkw0ipCPNHZ2tD5KW4lOuSdPKzY= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= From a642c2e33bea5206a02d9c56b0f0d3139e93c2a1 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sat, 26 Sep 2020 00:04:52 -0700 Subject: [PATCH 07/16] add debug --- test/data.go | 7 +++++-- test/testshared/testshared.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/data.go b/test/data.go index 63a6076bb981..75c9806f5cb0 100644 --- a/test/data.go +++ b/test/data.go @@ -1,11 +1,14 @@ package test import ( + "os" "path/filepath" ) -const testdataDir = "testdata" -const binName = "../golangci-lint" +const ( + testdataDir = "testdata" + binName = ".." + string(os.PathSeparator) + "golangci-lint" +) var minimalPkg = getTestDataDir("minimalpkg") diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index b153eecdb4f6..0462735965ca 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -40,6 +40,8 @@ func (r *LintRunner) Install() { } cmd := exec.Command("make", "-C", "..", "build") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr assert.NoError(r.t, cmd.Run(), "Can't go install golangci-lint") }) } From 9826f1932b897f6e8394fe83701fc6af9434921c Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sat, 26 Sep 2020 00:30:07 -0700 Subject: [PATCH 08/16] prevent more panics --- test/linters_test.go | 19 +++++++++++++------ test/testshared/testshared.go | 3 +-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/test/linters_test.go b/test/linters_test.go index 30734e3beb58..cb632efb368b 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -79,8 +79,9 @@ func TestGoimportsLocal(t *testing.T) { cfg, err := yaml.Marshal(rc.config) assert.NoError(t, err) - testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...). - ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed") + r := testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...) + assert.NotNil(t, res, "command failed to run") + r.ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed") } func TestGciLocal(t *testing.T) { @@ -95,8 +96,9 @@ func TestGciLocal(t *testing.T) { cfg, err := yaml.Marshal(rc.config) assert.NoError(t, err) - testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...). - ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed") + r := testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...) + assert.NotNil(t, res, "command failed to run") + r.ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed") } func saveConfig(t *testing.T, cfg map[string]interface{}) (cfgPath string, finishFunc func()) { @@ -257,6 +259,11 @@ func TestGolintConsumesXTestFiles(t *testing.T) { const expIssue = "`if` block ends with a `return` statement, so drop this `else` and outdent its block" r := testshared.NewLintRunner(t) - r.Run("--no-config", "--disable-all", "-Egolint", dir).ExpectHasIssue(expIssue) - r.Run("--no-config", "--disable-all", "-Egolint", filepath.Join(dir, "p_test.go")).ExpectHasIssue(expIssue) + res := r.Run("--no-config", "--disable-all", "-Egolint", dir) + assert.NotNil(t, res, "command failed to run") + res.ExpectHasIssue(expIssue) + + res = r.Run("--no-config", "--disable-all", "-Egolint", filepath.Join(dir, "p_test.go")) + assert.NotNil(t, res, "command failed to run") + res.ExpectHasIssue(expIssue) } diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index 0462735965ca..352efb673ba5 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "sync" "syscall" @@ -40,8 +41,6 @@ func (r *LintRunner) Install() { } cmd := exec.Command("make", "-C", "..", "build") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr assert.NoError(r.t, cmd.Run(), "Can't go install golangci-lint") }) } From 5410081001c4f526eaefeff2eb1d47c1a8e653b1 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sat, 26 Sep 2020 00:32:20 -0700 Subject: [PATCH 09/16] remove unused import --- test/testshared/testshared.go | 1 - 1 file changed, 1 deletion(-) diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index 352efb673ba5..b153eecdb4f6 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -5,7 +5,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strings" "sync" "syscall" From f9bf2391e604bc9b40c6ee15edbbf3722e0ed269 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sat, 26 Sep 2020 00:34:46 -0700 Subject: [PATCH 10/16] fix wrong variable --- test/linters_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/linters_test.go b/test/linters_test.go index cb632efb368b..702a9ead7ef1 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -80,7 +80,7 @@ func TestGoimportsLocal(t *testing.T) { assert.NoError(t, err) r := testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...) - assert.NotNil(t, res, "command failed to run") + assert.NotNil(t, r, "command failed to run") r.ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed") } @@ -97,7 +97,7 @@ func TestGciLocal(t *testing.T) { assert.NoError(t, err) r := testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...) - assert.NotNil(t, res, "command failed to run") + assert.NotNil(t, r, "command failed to run") r.ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed") } From a4ebff1781b3e17a1341e54e25dac204e2958098 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sat, 26 Sep 2020 01:10:16 -0700 Subject: [PATCH 11/16] switch to require, prevent panics --- test/testshared/testshared.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index b153eecdb4f6..672dfda7e5a6 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -10,7 +10,7 @@ import ( "syscall" "time" - "github.com/stretchr/testify/assert" + assert "github.com/stretchr/testify/require" "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/logutils" @@ -116,7 +116,11 @@ func (r *LintRunner) RunCommand(command string, args ...string) *RunResult { } r.t.Errorf("can't get error code from %s", err) - return nil + return &RunResult{ + t: r.t, + output: err.Error(), + exitCode: -1, + } } // success, exitCode should be 0 if go is ok From 791ddc065c258ef819e969ff90c93b7035238959 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sat, 26 Sep 2020 01:14:02 -0700 Subject: [PATCH 12/16] revert a couple of files --- test/enabled_linters_test.go | 8 +++----- test/linters_test.go | 19 ++++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/test/enabled_linters_test.go b/test/enabled_linters_test.go index 0700739942bb..70cb4ffc47c2 100644 --- a/test/enabled_linters_test.go +++ b/test/enabled_linters_test.go @@ -184,12 +184,10 @@ func TestEnabledLinters(t *testing.T) { runArgs = append(runArgs, strings.Split(c.args, " ")...) } r := runner.RunCommandWithYamlConfig(c.cfg, "linters", runArgs...) - if r != nil { - sort.StringSlice(c.el).Sort() + sort.StringSlice(c.el).Sort() - expectedLine := fmt.Sprintf("Active %d linters: [%s]", len(c.el), strings.Join(c.el, " ")) - r.ExpectOutputContains(expectedLine) - } + expectedLine := fmt.Sprintf("Active %d linters: [%s]", len(c.el), strings.Join(c.el, " ")) + r.ExpectOutputContains(expectedLine) }) } } diff --git a/test/linters_test.go b/test/linters_test.go index 702a9ead7ef1..30734e3beb58 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -79,9 +79,8 @@ func TestGoimportsLocal(t *testing.T) { cfg, err := yaml.Marshal(rc.config) assert.NoError(t, err) - r := testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...) - assert.NotNil(t, r, "command failed to run") - r.ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed") + testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...). + ExpectHasIssue("testdata/goimports/goimports.go:8: File is not `goimports`-ed") } func TestGciLocal(t *testing.T) { @@ -96,9 +95,8 @@ func TestGciLocal(t *testing.T) { cfg, err := yaml.Marshal(rc.config) assert.NoError(t, err) - r := testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...) - assert.NotNil(t, r, "command failed to run") - r.ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed") + testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...). + ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed") } func saveConfig(t *testing.T, cfg map[string]interface{}) (cfgPath string, finishFunc func()) { @@ -259,11 +257,6 @@ func TestGolintConsumesXTestFiles(t *testing.T) { const expIssue = "`if` block ends with a `return` statement, so drop this `else` and outdent its block" r := testshared.NewLintRunner(t) - res := r.Run("--no-config", "--disable-all", "-Egolint", dir) - assert.NotNil(t, res, "command failed to run") - res.ExpectHasIssue(expIssue) - - res = r.Run("--no-config", "--disable-all", "-Egolint", filepath.Join(dir, "p_test.go")) - assert.NotNil(t, res, "command failed to run") - res.ExpectHasIssue(expIssue) + r.Run("--no-config", "--disable-all", "-Egolint", dir).ExpectHasIssue(expIssue) + r.Run("--no-config", "--disable-all", "-Egolint", filepath.Join(dir, "p_test.go")).ExpectHasIssue(expIssue) } From 96440b1757019d3a76324ece4a00966b084b49c4 Mon Sep 17 00:00:00 2001 From: Melvin Date: Sat, 2 Jan 2021 00:23:19 -0800 Subject: [PATCH 13/16] debug From 3fee759525583b6a86dbcd3265442d98149c3d89 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sun, 3 Jan 2021 00:02:26 -0800 Subject: [PATCH 14/16] Add .exe on windows (not tested) --- Makefile | 15 ++++++++++----- test/testshared/testshared.go | 11 ++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 6757a1a675a2..c813eb23bceb 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,22 @@ # enable consistent Go 1.12/1.13 GOPROXY behavior. export GOPROXY = https://proxy.golang.org +BINARY = golangci-lint +ifeq ($(OS),Windows_NT) + BINARY := $(BINARY).exe +endif + # Build build: golangci-lint .PHONY: build build_race: - go build -race -o golangci-lint ./cmd/golangci-lint + go build -race -o $(BINARY) ./cmd/golangci-lint .PHONY: build_race clean: - rm -f golangci-lint + rm -f $(BINARY) rm -f test/path rm -f tools/Dracula.itermcolors rm -f tools/godownloader @@ -26,12 +31,12 @@ clean: # Test test: export GOLANGCI_LINT_INSTALLED = true test: build - GL_TEST_RUN=1 ./golangci-lint run -v + GL_TEST_RUN=1 ./$(BINARY) run -v GL_TEST_RUN=1 go test -v -parallel 2 ./... .PHONY: test test_race: build_race - GL_TEST_RUN=1 ./golangci-lint run -v --timeout=5m + GL_TEST_RUN=1 ./$(BINARY) run -v --timeout=5m .PHONY: test_race test_linters: @@ -70,7 +75,7 @@ snapshot: .goreleaser.yml tools/goreleaser # Non-PHONY targets (real files) golangci-lint: FORCE - go build -o $@ ./cmd/golangci-lint + go build -o $(BINARY) ./cmd/golangci-lint tools/godownloader: export GOFLAGS = -mod=readonly tools/godownloader: tools/go.mod tools/go.sum diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index 672dfda7e5a6..1f052693802c 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "sync" "syscall" @@ -16,6 +17,14 @@ import ( "github.com/golangci/golangci-lint/pkg/logutils" ) +func binaryName() string { + name := "golangci-lint" + if runtime.GOOS == "windows" { + name += ".exe" + } + return name +} + type LintRunner struct { t assert.TestingT log logutils.Log @@ -95,7 +104,7 @@ func (r *LintRunner) Run(args ...string) *RunResult { func (r *LintRunner) RunCommand(command string, args ...string) *RunResult { r.Install() - binPath := filepath.Join("..", "golangci-lint") + binPath := filepath.Join("..", binaryName()) runArgs := append([]string{command}, args...) defer func(startedAt time.Time) { r.log.Infof("ran [%s %s] in %s", binPath, strings.Join(runArgs, " "), time.Since(startedAt)) From d10f9907cb76501b6124749e3fa750c5ef248a27 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sun, 3 Jan 2021 00:33:21 -0800 Subject: [PATCH 15/16] fix extension at more places --- test/data.go | 2 -- test/linters_test.go | 2 +- test/testshared/testshared.go | 9 ++++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/data.go b/test/data.go index 75c9806f5cb0..6f4fffc98d1f 100644 --- a/test/data.go +++ b/test/data.go @@ -1,13 +1,11 @@ package test import ( - "os" "path/filepath" ) const ( testdataDir = "testdata" - binName = ".." + string(os.PathSeparator) + "golangci-lint" ) var minimalPkg = getTestDataDir("minimalpkg") diff --git a/test/linters_test.go b/test/linters_test.go index 836777b61720..d100a8cb655a 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -154,7 +154,7 @@ func testOneSource(t *testing.T, sourcePath string) { caseArgs = append(caseArgs, sourcePath) - cmd := exec.Command(binName, caseArgs...) + cmd := exec.Command(testshared.BinaryName(), caseArgs...) t.Log(caseArgs) runGoErrchk(cmd, []string{sourcePath}, t) } diff --git a/test/testshared/testshared.go b/test/testshared/testshared.go index 1f052693802c..e4a7da70ab72 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -17,8 +17,8 @@ import ( "github.com/golangci/golangci-lint/pkg/logutils" ) -func binaryName() string { - name := "golangci-lint" +func BinaryName() string { + name := filepath.Join("..", "golangci-lint") if runtime.GOOS == "windows" { name += ".exe" } @@ -104,13 +104,12 @@ func (r *LintRunner) Run(args ...string) *RunResult { func (r *LintRunner) RunCommand(command string, args ...string) *RunResult { r.Install() - binPath := filepath.Join("..", binaryName()) runArgs := append([]string{command}, args...) defer func(startedAt time.Time) { - r.log.Infof("ran [%s %s] in %s", binPath, strings.Join(runArgs, " "), time.Since(startedAt)) + r.log.Infof("ran [%s %s] in %s", BinaryName(), strings.Join(runArgs, " "), time.Since(startedAt)) }(time.Now()) - cmd := exec.Command(binPath, runArgs...) + cmd := exec.Command(BinaryName(), runArgs...) cmd.Env = append(os.Environ(), r.env...) out, err := cmd.CombinedOutput() if err != nil { From 2207eece2a3e18dd190f63b4daf9fdb4796aa2b4 Mon Sep 17 00:00:00 2001 From: Melvin Laplanche Date: Sun, 3 Jan 2021 00:34:40 -0800 Subject: [PATCH 16/16] fix resources conflict --- test/linters_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/linters_test.go b/test/linters_test.go index d100a8cb655a..fcfa5ba4fad9 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -102,16 +102,17 @@ func TestGciLocal(t *testing.T) { func saveConfig(t *testing.T, cfg map[string]interface{}) (cfgPath string, finishFunc func()) { f, err := ioutil.TempFile("", "golangci_lint_test") assert.NoError(t, err) + name := f.Name() + assert.NoError(t, f.Close()) - cfgPath = f.Name() + ".yml" - err = os.Rename(f.Name(), cfgPath) + cfgPath = name + ".yml" + err = os.Rename(name, cfgPath) assert.NoError(t, err) err = yaml.NewEncoder(f).Encode(cfg) assert.NoError(t, err) return cfgPath, func() { - assert.NoError(t, f.Close()) if os.Getenv("GL_KEEP_TEMP_FILES") != "1" { assert.NoError(t, os.Remove(cfgPath)) }