60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package printers
 | |
| 
 | |
| import (
 | |
| 	"bytes"
 | |
| 	"context"
 | |
| 	"go/token"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| 	"github.com/stretchr/testify/require"
 | |
| 
 | |
| 	"github.com/golangci/golangci-lint/pkg/logutils"
 | |
| 	"github.com/golangci/golangci-lint/pkg/result"
 | |
| )
 | |
| 
 | |
| func TestTab_Print(t *testing.T) {
 | |
| 	issues := []result.Issue{
 | |
| 		{
 | |
| 			FromLinter: "linter-a",
 | |
| 			Severity:   "warning",
 | |
| 			Text:       "some issue",
 | |
| 			Pos: token.Position{
 | |
| 				Filename: "path/to/filea.go",
 | |
| 				Offset:   2,
 | |
| 				Line:     10,
 | |
| 				Column:   4,
 | |
| 			},
 | |
| 		},
 | |
| 		{
 | |
| 			FromLinter: "linter-b",
 | |
| 			Severity:   "error",
 | |
| 			Text:       "another issue",
 | |
| 			SourceLines: []string{
 | |
| 				"func foo() {",
 | |
| 				"\tfmt.Println(\"bar\")",
 | |
| 				"}",
 | |
| 			},
 | |
| 			Pos: token.Position{
 | |
| 				Filename: "path/to/fileb.go",
 | |
| 				Offset:   5,
 | |
| 				Line:     300,
 | |
| 				Column:   9,
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 
 | |
| 	buf := new(bytes.Buffer)
 | |
| 
 | |
| 	printer := NewTab(true, logutils.NewStderrLog(logutils.DebugKeyEmpty), buf)
 | |
| 
 | |
| 	err := printer.Print(context.Background(), issues)
 | |
| 	require.NoError(t, err)
 | |
| 
 | |
| 	expected := `path/to/filea.go:10:4   linter-a  some issue
 | |
| path/to/fileb.go:300:9  linter-b  another issue
 | |
| `
 | |
| 
 | |
| 	assert.Equal(t, expected, buf.String())
 | |
| }
 | 
