4.6 如何测试
func TestTestdata(t *testing.T) { DefPredeclaredTestFuncs(); testDir(t, 75, "testdata") }
func TestExamples(t *testing.T) { testDir(t, 0, "examples") }
func TestFixedbugs(t *testing.T) { testDir(t, 0, "fixedbugs") }func TestTypecheck(t *testing.T) {
code := `
package p
type A struct {}
func (this *A) name() {}
type B *A
func main() {
var b B
b.name()
}
`
f, err := parseSrc("testTypecheckConst", code)
if err != nil {
panic(err)
}
// Dump 出语法树
syntax.Fdump(os.Stdout, f)
var conf Config
conf.Trace = true
conf.Importer = defaultImporter()
conf.Error = func(err error) {
fmt.Printf("Typecheck Error: %v\n", err)
}
info := Info{
Types: make(map[syntax.Expr]TypeAndValue),
Defs: make(map[*syntax.Name]Object),
Uses: make(map[*syntax.Name]Object),
Selections: make(map[*syntax.SelectorExpr]*Selection),
Implicits: make(map[syntax.Node]Object),
Scopes: make(map[syntax.Node]*Scope),
Inferred: make(map[syntax.Expr]Inferred),
}
conf.Check("<no package>", []*syntax.File{f}, &info)
}最后更新于