github.com/songrgg/gometalinter@v2.0.6-0.20180425200507-2cbec6168e84+incompatible/regressiontests/gotype_test.go (about)

     1  package regressiontests
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/gotestyourself/gotestyourself/fs"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestGoType(t *testing.T) {
    12  	t.Parallel()
    13  
    14  	dir := fs.NewDir(t, "test-gotype",
    15  		fs.WithFile("file.go", goTypeFile("root")),
    16  		fs.WithDir("sub",
    17  			fs.WithFile("file.go", goTypeFile("sub"))),
    18  		fs.WithDir("excluded",
    19  			fs.WithFile("file.go", goTypeFile("excluded"))))
    20  	defer dir.Remove()
    21  
    22  	expected := Issues{
    23  		{Linter: "gotype", Severity: "error", Path: "file.go", Line: 4, Col: 6, Message: "foo declared but not used"},
    24  		{Linter: "gotype", Severity: "error", Path: "sub/file.go", Line: 4, Col: 6, Message: "foo declared but not used"},
    25  	}
    26  	actual := RunLinter(t, "gotype", dir.Path(), "--skip=excluded")
    27  	assert.Equal(t, expected, actual)
    28  }
    29  
    30  func TestGoTypeWithMultiPackageDirectoryTest(t *testing.T) {
    31  	t.Parallel()
    32  
    33  	dir := fs.NewDir(t, "test-gotype",
    34  		fs.WithFile("file.go", goTypeFile("root")),
    35  		fs.WithFile("file_test.go", goTypeFile("root_test")))
    36  	defer dir.Remove()
    37  
    38  	expected := Issues{
    39  		{Linter: "gotype", Severity: "error", Path: "file.go", Line: 4, Col: 6, Message: "foo declared but not used"},
    40  		{Linter: "gotypex", Severity: "error", Path: "file_test.go", Line: 4, Col: 6, Message: "foo declared but not used"},
    41  	}
    42  	actual := RunLinter(t, "gotype", dir.Path())
    43  	actual = append(actual, RunLinter(t, "gotypex", dir.Path())...)
    44  	assert.Equal(t, expected, actual)
    45  }
    46  
    47  
    48  func goTypeFile(pkg string) string {
    49  	return fmt.Sprintf(`package %s
    50  
    51  func badFunction() {
    52  	var foo string
    53  }
    54  	`, pkg)
    55  }