Skip to content

Commit 6e756cb

Browse files
committed
improve output tests
1 parent cac2c06 commit 6e756cb

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

test/output_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import (
1212
"github.com/golangci/golangci-lint/test/testshared"
1313
)
1414

15+
//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+
1518
func TestOutput_Stderr(t *testing.T) {
16-
sourcePath := filepath.Join(testdataDir, "gci.go")
19+
sourcePath := filepath.Join(testdataDir, "misspell.go")
1720
fmt.Println(filepath.Abs(sourcePath))
1821

1922
testshared.NewRunnerBuilder(t).
@@ -28,14 +31,15 @@ func TestOutput_Stderr(t *testing.T) {
2831
Runner().
2932
Install().
3033
Run().
31-
ExpectHasIssue("testdata/gci.go:8: File is not `gci`-ed").
32-
ExpectOutputContains(`"Issues":[`)
34+
//nolint:misspell
35+
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`").
36+
ExpectOutputContains(expectedJSONOutput)
3337
}
3438

3539
func TestOutput_File(t *testing.T) {
3640
resultPath := path.Join(t.TempDir(), "golangci_lint_test_result")
3741

38-
sourcePath := filepath.Join(testdataDir, "gci.go")
42+
sourcePath := filepath.Join(testdataDir, "misspell.go")
3943

4044
testshared.NewRunnerBuilder(t).
4145
WithArgs(
@@ -49,16 +53,16 @@ func TestOutput_File(t *testing.T) {
4953
Runner().
5054
Install().
5155
Run().
52-
ExpectHasIssue("testdata/gci.go:8: File is not `gci`-ed").
53-
ExpectOutputNotContains(`"Issues":[`)
56+
//nolint:misspell
57+
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`")
5458

5559
b, err := os.ReadFile(resultPath)
5660
require.NoError(t, err)
57-
require.Contains(t, string(b), `"Issues":[`)
61+
require.Contains(t, string(b), expectedJSONOutput)
5862
}
5963

6064
func TestOutput_Multiple(t *testing.T) {
61-
sourcePath := filepath.Join(testdataDir, "gci.go")
65+
sourcePath := filepath.Join(testdataDir, "misspell.go")
6266

6367
testshared.NewRunnerBuilder(t).
6468
WithArgs(
@@ -72,6 +76,7 @@ func TestOutput_Multiple(t *testing.T) {
7276
Runner().
7377
Install().
7478
Run().
75-
ExpectHasIssue("testdata/gci.go:8: File is not `gci`-ed").
76-
ExpectOutputContains(`"Issues":[`)
79+
//nolint:misspell
80+
ExpectHasIssue("testdata/misspell.go:6:38: `occured` is a misspelling of `occurred`").
81+
ExpectOutputContains(expectedJSONOutput)
7782
}

0 commit comments

Comments
 (0)