mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-07-29 15:38:53 -04:00
Add support for multiple outputs (#2386)
This commit is contained in:
parent
669852edbb
commit
d209389625
12 changed files with 191 additions and 61 deletions
test
|
@ -2,8 +2,10 @@ package test
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -97,6 +99,64 @@ func TestGciLocal(t *testing.T) {
|
|||
ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed")
|
||||
}
|
||||
|
||||
func TestMultipleOutputs(t *testing.T) {
|
||||
sourcePath := filepath.Join(testdataDir, "gci", "gci.go")
|
||||
args := []string{
|
||||
"--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number,json:stdout",
|
||||
sourcePath,
|
||||
}
|
||||
rc := extractRunContextFromComments(t, sourcePath)
|
||||
args = append(args, rc.args...)
|
||||
|
||||
cfg, err := yaml.Marshal(rc.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...).
|
||||
ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed").
|
||||
ExpectOutputContains(`"Issues":[`)
|
||||
}
|
||||
|
||||
func TestStderrOutput(t *testing.T) {
|
||||
sourcePath := filepath.Join(testdataDir, "gci", "gci.go")
|
||||
args := []string{
|
||||
"--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number,json:stderr",
|
||||
sourcePath,
|
||||
}
|
||||
rc := extractRunContextFromComments(t, sourcePath)
|
||||
args = append(args, rc.args...)
|
||||
|
||||
cfg, err := yaml.Marshal(rc.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...).
|
||||
ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed").
|
||||
ExpectOutputContains(`"Issues":[`)
|
||||
}
|
||||
|
||||
func TestFileOutput(t *testing.T) {
|
||||
resultPath := path.Join(t.TempDir(), "golangci_lint_test_result")
|
||||
|
||||
sourcePath := filepath.Join(testdataDir, "gci", "gci.go")
|
||||
args := []string{
|
||||
"--disable-all", "--print-issued-lines=false", "--print-linter-name=false",
|
||||
fmt.Sprintf("--out-format=json:%s,line-number", resultPath),
|
||||
sourcePath,
|
||||
}
|
||||
rc := extractRunContextFromComments(t, sourcePath)
|
||||
args = append(args, rc.args...)
|
||||
|
||||
cfg, err := yaml.Marshal(rc.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...).
|
||||
ExpectHasIssue("testdata/gci/gci.go:7: File is not `gci`-ed").
|
||||
ExpectOutputNotContains(`"Issues":[`)
|
||||
|
||||
b, err := os.ReadFile(resultPath)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(b), `"Issues":[`)
|
||||
}
|
||||
|
||||
func saveConfig(t *testing.T, cfg map[string]interface{}) (cfgPath string, finishFunc func()) {
|
||||
f, err := os.CreateTemp("", "golangci_lint_test")
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue