GoPLS Viewer

Home|gopls/godoc/dirtrees_test.go
1// Copyright 2018 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.
4
5package godoc
6
7import (
8    "go/build"
9    "path/filepath"
10    "runtime"
11    "sort"
12    "testing"
13
14    "golang.org/x/tools/godoc/vfs"
15    "golang.org/x/tools/godoc/vfs/gatefs"
16)
17
18func TestNewDirTree(t *testing.T) {
19    fsGate := make(chan bool20)
20    rootfs := gatefs.New(vfs.OS(runtime.GOROOT()), fsGate)
21    fs := vfs.NameSpace{}
22    fs.Bind("/"rootfs"/"vfs.BindReplace)
23
24    c := NewCorpus(fs)
25    // 3 levels deep is enough for testing
26    dir := c.newDirectory("/"3)
27
28    processDir(tdir)
29}
30
31func processDir(t *testing.Tdir *Directory) {
32    var list []string
33    for _d := range dir.Dirs {
34        list = append(listd.Name)
35        // recursively process the lower level
36        processDir(td)
37    }
38
39    if sort.StringsAreSorted(list) == false {
40        t.Errorf("list: %v is not sorted\n"list)
41    }
42}
43
44func BenchmarkNewDirectory(b *testing.B) {
45    if testing.Short() {
46        b.Skip("not running tests requiring large file scan in short mode")
47    }
48
49    fsGate := make(chan bool20)
50
51    goroot := runtime.GOROOT()
52    rootfs := gatefs.New(vfs.OS(goroot), fsGate)
53    fs := vfs.NameSpace{}
54    fs.Bind("/"rootfs"/"vfs.BindReplace)
55    for _p := range filepath.SplitList(build.Default.GOPATH) {
56        fs.Bind("/src/golang.org"gatefs.New(vfs.OS(p), fsGate), "/src/golang.org"vfs.BindAfter)
57    }
58    b.ResetTimer()
59    b.ReportAllocs()
60    for tries := 0tries < b.Ntries++ {
61        corpus := NewCorpus(fs)
62        corpus.newDirectory("/", -1)
63    }
64}
65
MembersX
gatefs
TestNewDirTree.c
processDir.RangeStmt_693.d
BenchmarkNewDirectory
BenchmarkNewDirectory.b
BenchmarkNewDirectory.RangeStmt_1223.p
BenchmarkNewDirectory.BlockStmt.corpus
build
testing
TestNewDirTree
TestNewDirTree.t
TestNewDirTree.fs
processDir.t
processDir.dir
BenchmarkNewDirectory.goroot
BenchmarkNewDirectory.rootfs
BenchmarkNewDirectory.fs
BenchmarkNewDirectory.tries
filepath
TestNewDirTree.fsGate
processDir
TestNewDirTree.rootfs
TestNewDirTree.dir
processDir.list
BenchmarkNewDirectory.fsGate
Members
X