diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2019-01-12 18:39:45 +0100 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2019-01-17 12:30:32 +0100 |
commit | b1247d2d0d51108c910a73891ff3116e5f032ab1 (patch) | |
tree | e9948964f0bfb1ad2df3bc7bad02aa1f41ccfbd8 /vendor/golang.org/x/tools/go/ssa/ssautil/load_test.go | |
parent | efcb8312e31b5c2261b1a1e95ace55b322cfcc27 (diff) |
[pkg] all your deps are vendored to us
Diffstat (limited to 'vendor/golang.org/x/tools/go/ssa/ssautil/load_test.go')
-rw-r--r-- | vendor/golang.org/x/tools/go/ssa/ssautil/load_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/golang.org/x/tools/go/ssa/ssautil/load_test.go b/vendor/golang.org/x/tools/go/ssa/ssautil/load_test.go new file mode 100644 index 0000000..8ccd463 --- /dev/null +++ b/vendor/golang.org/x/tools/go/ssa/ssautil/load_test.go @@ -0,0 +1,64 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ssautil_test + +import ( + "go/ast" + "go/importer" + "go/parser" + "go/token" + "go/types" + "os" + "testing" + + "golang.org/x/tools/go/ssa/ssautil" +) + +const hello = `package main + +import "fmt" + +func main() { + fmt.Println("Hello, world") +} +` + +func TestBuildPackage(t *testing.T) { + // There is a more substantial test of BuildPackage and the + // SSA program it builds in ../ssa/builder_test.go. + + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, "hello.go", hello, 0) + if err != nil { + t.Fatal(err) + } + + pkg := types.NewPackage("hello", "") + ssapkg, _, err := ssautil.BuildPackage(&types.Config{Importer: importer.Default()}, fset, pkg, []*ast.File{f}, 0) + if err != nil { + t.Fatal(err) + } + if pkg.Name() != "main" { + t.Errorf("pkg.Name() = %s, want main", pkg.Name()) + } + if ssapkg.Func("main") == nil { + ssapkg.WriteTo(os.Stderr) + t.Errorf("ssapkg has no main function") + } +} + +func TestBuildPackage_MissingImport(t *testing.T) { + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, "bad.go", `package bad; import "missing"`, 0) + if err != nil { + t.Fatal(err) + } + + pkg := types.NewPackage("bad", "") + ssapkg, _, err := ssautil.BuildPackage(new(types.Config), fset, pkg, []*ast.File{f}, 0) + if err == nil || ssapkg != nil { + t.Fatal("BuildPackage succeeded unexpectedly") + } +} |