From cc55bd9129a3b17c267f2209bfeb39d42bf989b9 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 23 Jul 2013 18:30:06 -0700 Subject: [PATCH] go.tools/go/types: add self test R=adonovan CC=golang-dev https://golang.org/cl/11739043 --- go/types/self_test.go | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 go/types/self_test.go diff --git a/go/types/self_test.go b/go/types/self_test.go new file mode 100644 index 00000000..94e5a5b5 --- /dev/null +++ b/go/types/self_test.go @@ -0,0 +1,60 @@ +// Copyright 2013 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 types + +import ( + "fmt" + "go/ast" + "go/parser" + "go/token" + "testing" + "time" +) + +func TestSelf(t *testing.T) { + filenames := pkgfiles(t, ".") // from stdlib_test.go + + // parse package files + fset := token.NewFileSet() + var files []*ast.File + for _, filename := range filenames { + file, err := parser.ParseFile(fset, filename, nil, 0) + if err != nil { + t.Fatal(err) + } + files = append(files, file) + } + + _, err := Check("go/types", fset, files) + if err != nil { + t.Fatal(err) + } + + if testing.Short() { + return // skip benchmark in short mode + } + + b := testing.Benchmark(func(b *testing.B) { + for i := 0; i < b.N; i++ { + Check("go/types", fset, files) + } + }) + + // determine line count + lineCount := 0 + fset.Iterate(func(f *token.File) bool { + lineCount += f.LineCount() + return true + }) + + d := time.Duration(b.NsPerOp()) + fmt.Printf( + "%s/op, %d lines/s, %d KB/op (%d iterations)\n", + d, + int64(float64(lineCount)/d.Seconds()), + b.AllocedBytesPerOp()>>10, + b.N, + ) +}