github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/packages/util_test.go (about)

     1  package packages
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  //nolint:lll
    10  func Test_stackCrusher(t *testing.T) {
    11  	testCases := []struct {
    12  		desc     string
    13  		stack    string
    14  		expected string
    15  	}{
    16  		{
    17  			desc:     "large stack",
    18  			stack:    `/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/result/processors/nolint.go:13:2: /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/result/processors/nolint.go:13:2: could not import github.com/golangci/golangci-lint/pkg/lint/lintersdb (/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/lint/lintersdb/manager.go:13:2: could not import github.com/golangci/golangci-lint/pkg/golinters (/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:21:9: undeclared name: linterName))`,
    19  			expected: "/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:21:9: undeclared name: linterName",
    20  		},
    21  		{
    22  			desc:     "no stack",
    23  			stack:    `/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:45:3: undeclared name: linterName`,
    24  			expected: "/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:45:3: undeclared name: linterName",
    25  		},
    26  		{
    27  			desc:     "no stack but message with parenthesis",
    28  			stack:    `/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:20:32: cannot use mu (variable of type sync.Mutex) as goanalysis.Issue value in argument to append`,
    29  			expected: "/home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/deadcode.go:20:32: cannot use mu (variable of type sync.Mutex) as goanalysis.Issue value in argument to append",
    30  		},
    31  		{
    32  			desc:     "stack with message with parenthesis at the end",
    33  			stack:    `/home/username/childapp/interfaces/IPanel.go:4:2: could not import github.com/gotk3/gotk3/gtk (/home/username/childapp/vendor/github.com/gotk3/gotk3/gtk/aboutdialog.go:5:8: could not import C (cgo preprocessing failed))`,
    34  			expected: "/home/username/childapp/vendor/github.com/gotk3/gotk3/gtk/aboutdialog.go:5:8: could not import C (cgo preprocessing failed)",
    35  		},
    36  		{
    37  			desc:     "no stack but message with parenthesis at the end",
    38  			stack:    `/home/ldez/sources/go/src/github.com/golangci/sandbox/main.go:11:17: ui.test undefined (type App has no field or method test)`,
    39  			expected: "/home/ldez/sources/go/src/github.com/golangci/sandbox/main.go:11:17: ui.test undefined (type App has no field or method test)",
    40  		},
    41  	}
    42  
    43  	for _, test := range testCases {
    44  		test := test
    45  		t.Run(test.desc, func(t *testing.T) {
    46  			t.Parallel()
    47  
    48  			actual := stackCrusher(test.stack)
    49  
    50  			assert.Equal(t, test.expected, actual)
    51  		})
    52  	}
    53  }