* tree-ssa-reassoc.c (reassociate_bb): Clarify code slighly.
[official-gcc.git] / libgo / go / go / types / self_test.go
blob528fc173f88680a0b8da76d525a2b14ecd479cee
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.
5 package types_test
7 import (
8 "flag"
9 "fmt"
10 "go/ast"
11 "go/importer"
12 "go/parser"
13 "go/token"
14 "path/filepath"
15 "testing"
16 "time"
18 . "go/types"
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, ".")
28 if err != nil {
29 t.Fatal(err)
32 conf := Config{Importer: importer.Default()}
33 _, err = conf.Check("go/types", fset, files, nil)
34 if err != 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.
38 // TODO(gri) fix this
39 t.Log(err) // replace w/ t.Fatal eventually
40 return
44 func TestBenchmark(t *testing.T) {
45 if !*benchmark {
46 return
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)
56 fmt.Println()
60 func runbench(t *testing.T, path string, ignoreFuncBodies bool) {
61 fset := token.NewFileSet()
62 files, err := pkgFiles(fset, path)
63 if err != nil {
64 t.Fatal(err)
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
75 lines := 0
76 fset.Iterate(func(f *token.File) bool {
77 lines += f.LineCount()
78 return true
81 d := time.Duration(b.NsPerOp())
82 fmt.Printf(
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
90 if err != nil {
91 return nil, err
94 var files []*ast.File
95 for _, filename := range filenames {
96 file, err := parser.ParseFile(fset, filename, nil, 0)
97 if err != nil {
98 return nil, err
100 files = append(files, file)
103 return files, nil