github.com/yasushi-saito/gometalinter@v2.0.13-0.20190118091058-bb04f89050ef+incompatible/regressiontests/vet_shadow_test.go (about)

     1  package regressiontests
     2  
     3  import (
     4  	"runtime"
     5  	"strings"
     6  	"testing"
     7  )
     8  
     9  func TestVetShadow(t *testing.T) {
    10  	if strings.HasPrefix(runtime.Version(), "go1.8") {
    11  		t.Skip("go vet does not have a --shadow flag in go1.8")
    12  	}
    13  
    14  	t.Parallel()
    15  	source := `package test
    16  
    17  type MyStruct struct {}
    18  func test(mystructs []*MyStruct) *MyStruct {
    19  	var foo *MyStruct
    20  	for _, mystruct := range mystructs {
    21  		foo := mystruct
    22  	}
    23  	return foo
    24  }
    25  `
    26  	expected := Issues{
    27  		{Linter: "vetshadow", Severity: "warning", Path: "test.go", Line: 7, Col: 3, Message: "foo declared and not used"},
    28  	}
    29  
    30  	if version := runtime.Version(); strings.HasPrefix(version, "go1.9") {
    31  		expected = Issues{
    32  			{Linter: "vetshadow", Severity: "warning", Path: "test.go", Line: 7, Col: 0, Message: `declaration of "foo" shadows declaration at test.go:5`},
    33  		}
    34  	}
    35  
    36  	ExpectIssues(t, "vetshadow", source, expected)
    37  }