github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/printers/tab_test.go (about) 1 package printers 2 3 import ( 4 "bytes" 5 "context" 6 "go/token" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 12 "github.com/golangci/golangci-lint/pkg/logutils" 13 "github.com/golangci/golangci-lint/pkg/result" 14 ) 15 16 func TestTab_Print(t *testing.T) { 17 issues := []result.Issue{ 18 { 19 FromLinter: "linter-a", 20 Severity: "warning", 21 Text: "some issue", 22 Pos: token.Position{ 23 Filename: "path/to/filea.go", 24 Offset: 2, 25 Line: 10, 26 Column: 4, 27 }, 28 }, 29 { 30 FromLinter: "linter-b", 31 Severity: "error", 32 Text: "another issue", 33 SourceLines: []string{ 34 "func foo() {", 35 "\tfmt.Println(\"bar\")", 36 "}", 37 }, 38 Pos: token.Position{ 39 Filename: "path/to/fileb.go", 40 Offset: 5, 41 Line: 300, 42 Column: 9, 43 }, 44 }, 45 } 46 47 buf := new(bytes.Buffer) 48 49 printer := NewTab(true, logutils.NewStderrLog(logutils.DebugKeyEmpty), buf) 50 51 err := printer.Print(context.Background(), issues) 52 require.NoError(t, err) 53 54 expected := `path/to/filea.go:10:4 linter-a some issue 55 path/to/fileb.go:300:9 linter-b another issue 56 ` 57 58 assert.Equal(t, expected, buf.String()) 59 }