github.com/alecthomas/golangci-lint@v1.4.2-0.20180609094924-581a3564ff68/test/linters_test.go (about) 1 package test 2 3 import ( 4 "bytes" 5 "os/exec" 6 "path/filepath" 7 "runtime" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func runGoErrchk(c *exec.Cmd, t *testing.T) { 14 output, err := c.CombinedOutput() 15 assert.NoError(t, err, "Output:\n%s", output) 16 17 // Can't check exit code: tool only prints to output 18 assert.False(t, bytes.Contains(output, []byte("BUG")), "Output:\n%s", output) 19 } 20 21 const testdataDir = "testdata" 22 const binName = "golangci-lint" 23 24 func TestSourcesFromTestdataWithIssuesDir(t *testing.T) { 25 t.Log(filepath.Join(testdataDir, "*.go")) 26 sources, err := filepath.Glob(filepath.Join(testdataDir, "*.go")) 27 assert.NoError(t, err) 28 assert.NotEmpty(t, sources) 29 30 installBinary(t) 31 32 for _, s := range sources { 33 s := s 34 t.Run(s, func(t *testing.T) { 35 t.Parallel() 36 testOneSource(t, s) 37 }) 38 } 39 } 40 41 func testOneSource(t *testing.T, sourcePath string) { 42 goErrchkBin := filepath.Join(runtime.GOROOT(), "test", "errchk") 43 cmd := exec.Command(goErrchkBin, binName, "run", 44 "--no-config", 45 "--enable-all", 46 "--dupl.threshold=20", 47 "--gocyclo.min-complexity=20", 48 "--print-issued-lines=false", 49 "--print-linter-name=false", 50 "--out-format=line-number", 51 "--print-welcome=false", 52 "--govet.check-shadowing=true", 53 "--depguard.include-go-root", 54 "--depguard.packages='log'", 55 sourcePath) 56 runGoErrchk(cmd, t) 57 }