1
0
mirror of https://github.com/golang/go synced 2024-11-18 23:05:06 -07:00

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:
Alan Donovan 2014-02-11 15:59:20 -05:00
parent ddfef020d1
commit ee92efc193
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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
}