github.phpd.cn/thought-machine/please@v12.2.0+incompatible/tools/please_go_test/gotest/find_cover_vars_test.go (about) 1 package gotest 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 // The library here is a (very) reduced version of core that only has one file in it. 10 var coverageVars = []CoverVar{{ 11 Dir: "tools/please_go_test/gotest/test_data", 12 ImportPath: "tools/please_go_test/gotest/test_data/core", 13 Var: "GoCover_lock_go", 14 File: "tools/please_go_test/gotest/test_data/lock.go", 15 }} 16 17 func TestFindCoverVars(t *testing.T) { 18 vars, err := FindCoverVars("tools/please_go_test/gotest/test_data", []string{"tools/please_go_test/gotest/test_data/x", "tools/please_go_test/gotest/test_data/binary"}, nil) 19 assert.NoError(t, err) 20 assert.Equal(t, coverageVars, vars) 21 } 22 23 func TestFindCoverVarsFailsGracefully(t *testing.T) { 24 _, err := FindCoverVars("wibble", nil, nil) 25 assert.Error(t, err) 26 } 27 28 func TestFindCoverVarsReturnsNothingForEmptyPath(t *testing.T) { 29 vars, err := FindCoverVars("", nil, nil) 30 assert.NoError(t, err) 31 assert.Equal(t, 0, len(vars)) 32 } 33 34 func TestFindBinaryCoverVars(t *testing.T) { 35 // Test for Go 1.7 binary format. 36 expected := []CoverVar{{ 37 Dir: "tools/please_go_test/gotest/test_data/binary", 38 ImportPath: "tools/please_go_test/gotest/test_data/binary/core", 39 Var: "GoCover_lock_go", 40 File: "tools/please_go_test/gotest/test_data/binary/lock.go", 41 }} 42 vars, err := FindCoverVars("tools/please_go_test/gotest/test_data/binary", nil, nil) 43 assert.NoError(t, err) 44 assert.Equal(t, expected, vars) 45 } 46 47 func TestFindCoverVarsExcludesSrcs(t *testing.T) { 48 vars, err := FindCoverVars("tools/please_go_test/gotest/test_data/binary", nil, []string{"tools/please_go_test/gotest/test_data/binary/lock.go"}) 49 assert.NoError(t, err) 50 assert.Equal(t, []CoverVar{}, vars) 51 }