Skip to content

Commit 4160e8c

Browse files
authored
dev: fix output tests (#3118)
1 parent d57145d commit 4160e8c

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

test/output_test.go

+25-9
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,48 @@ import (
99

1010
"github.com/stretchr/testify/require"
1111

12+
"github.com/golangci/golangci-lint/pkg/exitcodes"
1213
"github.com/golangci/golangci-lint/test/testshared"
1314
)
1415

1516
//nolint:misspell,lll
16-
const expectedJSONOutput = `{"Issues":[{"FromLinter":"misspell","Text":"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `","Severity":"","SourceLines":["\t// comment with incorrect spelling: occured // want \"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `\""],"Replacement":{"NeedOnlyDelete":false,"NewLines":null,"Inline":{"StartCol":37,"Length":7,"NewString":"occurred"}},"Pos":{"Filename":"testdata/misspell.go","Offset":0,"Line":6,"Column":38},"ExpectNoLint":false,"ExpectedNoLintLinter":""}],"Report":{"Linters":[{"Name":"asasalint"},{"Name":"asciicheck"},{"Name":"bidichk"},{"Name":"bodyclose"},{"Name":"containedctx"},{"Name":"contextcheck"},{"Name":"cyclop"},{"Name":"decorder"},{"Name":"deadcode","EnabledByDefault":true},{"Name":"depguard"},{"Name":"dogsled"},{"Name":"dupl"},{"Name":"durationcheck"},{"Name":"errcheck","EnabledByDefault":true},{"Name":"errchkjson"},{"Name":"errname"},{"Name":"errorlint"},{"Name":"execinquery"},{"Name":"exhaustive"},{"Name":"exhaustivestruct"},{"Name":"exhaustruct"},{"Name":"exportloopref"},{"Name":"forbidigo"},{"Name":"forcetypeassert"},{"Name":"funlen"},{"Name":"gci"},{"Name":"gochecknoglobals"},{"Name":"gochecknoinits"},{"Name":"gocognit"},{"Name":"goconst"},{"Name":"gocritic"},{"Name":"gocyclo"},{"Name":"godot"},{"Name":"godox"},{"Name":"goerr113"},{"Name":"gofmt"},{"Name":"gofumpt"},{"Name":"goheader"},{"Name":"goimports"},{"Name":"golint"},{"Name":"gomnd"},{"Name":"gomoddirectives"},{"Name":"gomodguard"},{"Name":"goprintffuncname"},{"Name":"gosec"},{"Name":"gosimple","EnabledByDefault":true},{"Name":"govet","EnabledByDefault":true},{"Name":"grouper"},{"Name":"ifshort"},{"Name":"importas"},{"Name":"ineffassign","EnabledByDefault":true},{"Name":"interfacer"},{"Name":"ireturn"},{"Name":"lll"},{"Name":"maintidx"},{"Name":"makezero"},{"Name":"maligned"},{"Name":"misspell","Enabled":true},{"Name":"nakedret"},{"Name":"nestif"},{"Name":"nilerr"},{"Name":"nilnil"},{"Name":"nlreturn"},{"Name":"noctx"},{"Name":"nonamedreturns"},{"Name":"nosnakecase"},{"Name":"nosprintfhostport"},{"Name":"paralleltest"},{"Name":"prealloc"},{"Name":"predeclared"},{"Name":"promlinter"},{"Name":"revive"},{"Name":"rowserrcheck"},{"Name":"scopelint"},{"Name":"sqlclosecheck"},{"Name":"staticcheck","EnabledByDefault":true},{"Name":"structcheck"},{"Name":"stylecheck"},{"Name":"tagliatelle"},{"Name":"tenv"},{"Name":"testpackage"},{"Name":"thelper"},{"Name":"tparallel"},{"Name":"typecheck","EnabledByDefault":true},{"Name":"unconvert"},{"Name":"unparam"},{"Name":"unused","EnabledByDefault":true},{"Name":"usestdlibvars"},{"Name":"varcheck","EnabledByDefault":true},{"Name":"varnamelen"},{"Name":"wastedassign"},{"Name":"whitespace"},{"Name":"wrapcheck"},{"Name":"wsl"},{"Name":"nolintlint"}]}}`
17+
const expectedJSONOutput = `{"Issues":[{"FromLinter":"misspell","Text":"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `","Severity":"","SourceLines":["\t// comment with incorrect spelling: occured // want \"` + "`" + `occured` + "`" + ` is a misspelling of ` + "`" + `occurred` + "`" + `\""],"Replacement":{"NeedOnlyDelete":false,"NewLines":null,"Inline":{"StartCol":37,"Length":7,"NewString":"occurred"}},"Pos":{"Filename":"testdata/misspell.go","Offset":0,"Line":6,"Column":38},"ExpectNoLint":false,"ExpectedNoLintLinter":""}]`
1718

18-
func TestOutput_Stderr(t *testing.T) {
19+
func TestOutput_lineNumber(t *testing.T) {
1920
sourcePath := filepath.Join(testdataDir, "misspell.go")
20-
fmt.Println(filepath.Abs(sourcePath))
2121

2222
testshared.NewRunnerBuilder(t).
2323
WithArgs(
2424
"--disable-all",
2525
"--print-issued-lines=false",
2626
"--print-linter-name=false",
27-
"--out-format=line-number,json:stderr",
27+
"--out-format=line-number",
2828
).
2929
WithDirectives(sourcePath).
3030
WithTargetPath(sourcePath).
3131
Runner().
3232
Install().
3333
Run().
3434
//nolint:misspell
35-
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`").
36-
ExpectOutputContains(expectedJSONOutput)
35+
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`")
36+
}
37+
38+
func TestOutput_Stderr(t *testing.T) {
39+
sourcePath := filepath.Join(testdataDir, "misspell.go")
40+
41+
testshared.NewRunnerBuilder(t).
42+
WithArgs(
43+
"--disable-all",
44+
"--print-issued-lines=false",
45+
"--print-linter-name=false",
46+
"--out-format=json:stderr",
47+
).
48+
WithDirectives(sourcePath).
49+
WithTargetPath(sourcePath).
50+
Runner().
51+
Install().
52+
Run().
53+
ExpectHasIssue(expectedJSONOutput)
3754
}
3855

3956
func TestOutput_File(t *testing.T) {
@@ -46,15 +63,14 @@ func TestOutput_File(t *testing.T) {
4663
"--disable-all",
4764
"--print-issued-lines=false",
4865
"--print-linter-name=false",
49-
fmt.Sprintf("--out-format=json:%s,line-number", resultPath),
66+
fmt.Sprintf("--out-format=json:%s", resultPath),
5067
).
5168
WithDirectives(sourcePath).
5269
WithTargetPath(sourcePath).
5370
Runner().
5471
Install().
5572
Run().
56-
//nolint:misspell
57-
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`")
73+
ExpectExitCode(exitcodes.IssuesFound)
5874

5975
b, err := os.ReadFile(resultPath)
6076
require.NoError(t, err)

0 commit comments

Comments
 (0)