mirror of https://github.com/golang/go.git
ssautil: Add unit tests that set ssa.InstantiateGenerics
Updates golang/go#52463 Updates golang/go#48525 Change-Id: I07cac2c9ad8d08a96cd14d4c729b14cf224d7f2e Reviewed-on: https://go-review.googlesource.com/c/tools/+/402055 Run-TryBot: Tim King <taking@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Tim King <taking@google.com> Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
This commit is contained in:
parent
ae12e8f2c7
commit
2548a8b1f5
|
|
@ -40,18 +40,23 @@ func TestBuildPackage(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pkg := types.NewPackage("hello", "")
|
||||
mode := ssa.InstantiateGenerics
|
||||
ssapkg, _, err := ssautil.BuildPackage(&types.Config{Importer: importer.Default()}, fset, pkg, []*ast.File{f}, mode)
|
||||
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")
|
||||
for _, mode := range []ssa.BuilderMode{
|
||||
ssa.SanityCheckFunctions,
|
||||
ssa.InstantiateGenerics | ssa.SanityCheckFunctions,
|
||||
} {
|
||||
pkg := types.NewPackage("hello", "")
|
||||
ssapkg, _, err := ssautil.BuildPackage(&types.Config{Importer: importer.Default()}, fset, pkg, []*ast.File{f}, mode)
|
||||
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")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,19 +72,23 @@ func TestPackages(t *testing.T) {
|
|||
t.Fatal("there were errors")
|
||||
}
|
||||
|
||||
prog, pkgs := ssautil.Packages(initial, ssa.InstantiateGenerics)
|
||||
bytesNewBuffer := pkgs[0].Func("NewBuffer")
|
||||
bytesNewBuffer.Pkg.Build()
|
||||
for _, mode := range []ssa.BuilderMode{
|
||||
ssa.SanityCheckFunctions,
|
||||
ssa.SanityCheckFunctions | ssa.InstantiateGenerics,
|
||||
} {
|
||||
prog, pkgs := ssautil.Packages(initial, mode)
|
||||
bytesNewBuffer := pkgs[0].Func("NewBuffer")
|
||||
bytesNewBuffer.Pkg.Build()
|
||||
|
||||
// We'll dump the SSA of bytes.NewBuffer because it is small and stable.
|
||||
out := new(bytes.Buffer)
|
||||
bytesNewBuffer.WriteTo(out)
|
||||
// We'll dump the SSA of bytes.NewBuffer because it is small and stable.
|
||||
out := new(bytes.Buffer)
|
||||
bytesNewBuffer.WriteTo(out)
|
||||
|
||||
// For determinism, sanitize the location.
|
||||
location := prog.Fset.Position(bytesNewBuffer.Pos()).String()
|
||||
got := strings.Replace(out.String(), location, "$GOROOT/src/bytes/buffer.go:1", -1)
|
||||
// For determinism, sanitize the location.
|
||||
location := prog.Fset.Position(bytesNewBuffer.Pos()).String()
|
||||
got := strings.Replace(out.String(), location, "$GOROOT/src/bytes/buffer.go:1", -1)
|
||||
|
||||
want := `
|
||||
want := `
|
||||
# Name: bytes.NewBuffer
|
||||
# Package: bytes
|
||||
# Location: $GOROOT/src/bytes/buffer.go:1
|
||||
|
|
@ -91,8 +100,9 @@ func NewBuffer(buf []byte) *Buffer:
|
|||
return t0
|
||||
|
||||
`[1:]
|
||||
if got != want {
|
||||
t.Errorf("bytes.NewBuffer SSA = <<%s>>, want <<%s>>", got, want)
|
||||
if got != want {
|
||||
t.Errorf("bytes.NewBuffer SSA = <<%s>>, want <<%s>>", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue