зеркало из https://github.com/golang/tools.git
go.tools/ssa: tweaks to CreateTestMainPackage.
Move mutation of program to the final step. + 2 assertions; + switches.go: comment fix. LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/61510044
This commit is contained in:
Родитель
ddfef020d1
Коммит
ee92efc193
|
@ -2,9 +2,9 @@
|
|||
|
||||
package main
|
||||
|
||||
// This file is the input to TestFindSwitches in switch_test.go.
|
||||
// This file is the input to TestSwitches in switch_test.go.
|
||||
// Each multiway conditional with constant or type cases (Switch)
|
||||
// discovered by FindSwitches is printed, and compared with the
|
||||
// discovered by Switches is printed, and compared with the
|
||||
// comments.
|
||||
//
|
||||
// The body of each case is printed as the value of its first
|
||||
|
|
|
@ -25,13 +25,15 @@ import (
|
|||
// It returns nil if the program contains no tests.
|
||||
//
|
||||
func (prog *Program) CreateTestMainPackage(pkgs ...*Package) *Package {
|
||||
if len(pkgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
testmain := &Package{
|
||||
Prog: prog,
|
||||
Members: make(map[string]Member),
|
||||
values: make(map[types.Object]Value),
|
||||
Object: types.NewPackage("testmain", "testmain", nil),
|
||||
}
|
||||
prog.packages[testmain.Object] = testmain
|
||||
|
||||
// Build package's init function.
|
||||
init := &Function{
|
||||
|
@ -42,8 +44,12 @@ func (prog *Program) CreateTestMainPackage(pkgs ...*Package) *Package {
|
|||
Prog: prog,
|
||||
}
|
||||
init.startBody()
|
||||
// TODO(adonovan): use lexical order.
|
||||
var expfuncs []*Function // all exported functions of *_test.go in pkgs, unordered
|
||||
for _, pkg := range pkgs {
|
||||
if pkg.Prog != prog {
|
||||
panic("wrong Program")
|
||||
}
|
||||
// Initialize package to test.
|
||||
var v Call
|
||||
v.Call.Value = pkg.init
|
||||
|
@ -135,6 +141,8 @@ func (prog *Program) CreateTestMainPackage(pkgs ...*Package) *Package {
|
|||
sanityCheckPackage(testmain)
|
||||
}
|
||||
|
||||
prog.packages[testmain.Object] = testmain
|
||||
|
||||
return testmain
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче