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 be1fc0d8cc09..ecdc40228d17 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 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/go.sum b/go.sum index 0603a79a49f5..1917a036b389 100644 --- a/go.sum +++ b/go.sum @@ -453,7 +453,6 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -476,13 +475,11 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -564,8 +561,6 @@ golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200622203043-20e05c1c8ffa/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200624225443-88f3c62a19ff/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200624225443-88f3c62a19ff/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200625211823-6506e20df31f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200625211823-6506e20df31f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200724022722-7017fd6b1305/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200812195022-5ae4c3c160a0/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= @@ -576,7 +571,6 @@ golang.org/x/tools v0.0.0-20201002184944-ecd9fd270d5d/go.mod h1:z6u4i615ZeAfBE4X golang.org/x/tools v0.0.0-20201007032633-0806396f153e/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20201011145850-ed2f50202694/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20201114224030-61ea331ec02b/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201118003311-bd56c0adb394 h1:O3VD5Fds21mB1WVRTbkiz/HTXESx6Jql5ucPZi69oiM= golang.org/x/tools v0.0.0-20201118003311-bd56c0adb394/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201121010211-780cb80bd7fb h1:z5+u0pkAUPUWd3taoTialQ2JAMo4Wo1Z3L25U4ZV9r0= golang.org/x/tools v0.0.0-20201121010211-780cb80bd7fb/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -631,7 +625,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/test/data.go b/test/data.go index 63a6076bb981..6f4fffc98d1f 100644 --- a/test/data.go +++ b/test/data.go @@ -4,8 +4,9 @@ import ( "path/filepath" ) -const testdataDir = "testdata" -const binName = "../golangci-lint" +const ( + testdataDir = "testdata" +) var minimalPkg = getTestDataDir("minimalpkg") diff --git a/test/linters_test.go b/test/linters_test.go index 836777b61720..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)) } @@ -154,7 +155,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 8effe2bad0bf..e4a7da70ab72 100644 --- a/test/testshared/testshared.go +++ b/test/testshared/testshared.go @@ -4,17 +4,27 @@ import ( "io/ioutil" "os" "os/exec" + "path/filepath" + "runtime" "strings" "sync" "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" ) +func BinaryName() string { + name := filepath.Join("..", "golangci-lint") + if runtime.GOOS == "windows" { + name += ".exe" + } + return name +} + type LintRunner struct { t assert.TestingT log logutils.Log @@ -96,10 +106,10 @@ func (r *LintRunner) RunCommand(command string, args ...string) *RunResult { 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", BinaryName(), strings.Join(runArgs, " "), time.Since(startedAt)) }(time.Now()) - cmd := exec.Command("../golangci-lint", runArgs...) + cmd := exec.Command(BinaryName(), runArgs...) cmd.Env = append(os.Environ(), r.env...) out, err := cmd.CombinedOutput() if err != nil { @@ -114,7 +124,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