gotype_test.go 1.5 KB
Newer Older
1 2
package regressiontests

3 4 5 6 7 8 9
import (
	"fmt"
	"testing"

	"github.com/gotestyourself/gotestyourself/fs"
	"github.com/stretchr/testify/assert"
)
10 11 12 13

func TestGoType(t *testing.T) {
	t.Parallel()

14 15 16 17 18 19 20 21 22 23 24 25 26 27
	dir := fs.NewDir(t, "test-gotype",
		fs.WithFile("file.go", goTypeFile("root")),
		fs.WithDir("sub",
			fs.WithFile("file.go", goTypeFile("sub"))),
		fs.WithDir("excluded",
			fs.WithFile("file.go", goTypeFile("excluded"))))
	defer dir.Remove()

	expected := Issues{
		{Linter: "gotype", Severity: "error", Path: "file.go", Line: 4, Col: 6, Message: "foo declared but not used"},
		{Linter: "gotype", Severity: "error", Path: "sub/file.go", Line: 4, Col: 6, Message: "foo declared but not used"},
	}
	actual := RunLinter(t, "gotype", dir.Path(), "--skip=excluded")
	assert.Equal(t, expected, actual)
28
}
29 30 31 32 33 34 35 36 37

func TestGoTypeWithMultiPackageDirectoryTest(t *testing.T) {
	t.Parallel()

	dir := fs.NewDir(t, "test-gotype",
		fs.WithFile("file.go", goTypeFile("root")),
		fs.WithFile("file_test.go", goTypeFile("root_test")))
	defer dir.Remove()

38
	expected := Issues{
39 40
		{Linter: "gotype", Severity: "error", Path: "file.go", Line: 4, Col: 6, Message: "foo declared but not used"},
		{Linter: "gotypex", Severity: "error", Path: "file_test.go", Line: 4, Col: 6, Message: "foo declared but not used"},
41
	}
42 43 44 45 46 47 48 49 50 51 52 53 54
	actual := RunLinter(t, "gotype", dir.Path())
	actual = append(actual, RunLinter(t, "gotypex", dir.Path())...)
	assert.Equal(t, expected, actual)
}


func goTypeFile(pkg string) string {
	return fmt.Sprintf(`package %s

func badFunction() {
	var foo string
}
	`, pkg)
55
}