1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:54:43 -07:00

go.tools/go/types: add self test

R=adonovan
CC=golang-dev
https://golang.org/cl/11739043
This commit is contained in:
Robert Griesemer 2013-07-23 18:30:06 -07:00
parent 09d04edfcf
commit cc55bd9129

60
go/types/self_test.go Normal file
View File

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