1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
21 var benchmark
= flag
.Bool("b", false, "run benchmarks")
23 func TestSelf(t
*testing
.T
) {
24 t
.Skip("skipping for gccgo--no importer")
26 fset
:= token
.NewFileSet()
27 files
, err
:= pkgFiles(fset
, ".")
32 conf
:= Config
{Importer
: importer
.Default()}
33 _
, err
= conf
.Check("go/types", fset
, files
, nil)
35 // Importing go/constant doesn't work in the
36 // build dashboard environment. Don't report an error
37 // for now so that the build remains green.
39 t
.Log(err
) // replace w/ t.Fatal eventually
44 func TestBenchmark(t
*testing
.T
) {
49 // We're not using testing's benchmarking mechanism directly
50 // because we want custom output.
52 for _
, p
:= range []string{"types", "constant", filepath
.Join("internal", "gcimporter")} {
53 path
:= filepath
.Join("..", p
)
54 runbench(t
, path
, false)
55 runbench(t
, path
, true)
60 func runbench(t
*testing
.T
, path
string, ignoreFuncBodies
bool) {
61 fset
:= token
.NewFileSet()
62 files
, err
:= pkgFiles(fset
, path
)
67 b
:= testing
.Benchmark(func(b
*testing
.B
) {
68 for i
:= 0; i
< b
.N
; i
++ {
69 conf
:= Config
{IgnoreFuncBodies
: ignoreFuncBodies
}
70 conf
.Check(path
, fset
, files
, nil)
74 // determine line count
76 fset
.Iterate(func(f
*token
.File
) bool {
77 lines
+= f
.LineCount()
81 d
:= time
.Duration(b
.NsPerOp())
83 "%s: %s for %d lines (%d lines/s), ignoreFuncBodies = %v\n",
84 filepath
.Base(path
), d
, lines
, int64(float64(lines
)/d
.Seconds()), ignoreFuncBodies
,
88 func pkgFiles(fset
*token
.FileSet
, path
string) ([]*ast
.File
, error
) {
89 filenames
, err
:= pkgFilenames(path
) // from stdlib_test.go
95 for _
, filename
:= range filenames
{
96 file
, err
:= parser
.ParseFile(fset
, filename
, nil, 0)
100 files
= append(files
, file
)