github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gotools/go/buildutil/util_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package buildutil_test 6 7 import ( 8 "go/build" 9 "os" 10 "path/filepath" 11 "runtime" 12 "testing" 13 14 "llvm.org/llgo/third_party/gotools/go/buildutil" 15 ) 16 17 func TestContainingPackage(t *testing.T) { 18 // unvirtualized: 19 goroot := runtime.GOROOT() 20 gopath := filepath.SplitList(os.Getenv("GOPATH"))[0] 21 22 for _, test := range [][2]string{ 23 {goroot + "/src/fmt/print.go", "fmt"}, 24 {goroot + "/src/encoding/json/foo.go", "encoding/json"}, 25 {goroot + "/src/encoding/missing/foo.go", "(not found)"}, 26 {gopath + "/src/golang.org/x/tools/go/buildutil/util_test.go", 27 "llvm.org/llgo/third_party/gotools/go/buildutil"}, 28 } { 29 file, want := test[0], test[1] 30 bp, err := buildutil.ContainingPackage(&build.Default, ".", file) 31 got := bp.ImportPath 32 if err != nil { 33 got = "(not found)" 34 } 35 if got != want { 36 t.Errorf("ContainingPackage(%q) = %s, want %s", file, got, want) 37 } 38 } 39 40 // TODO(adonovan): test on virtualized GOPATH too. 41 }