mirror of
https://github.com/golang/go
synced 2024-11-18 12:34:42 -07:00
5ebbcd132f
Rewrite performed with this command: sed -i '' 's_code.google.com/p/go\._golang.org/x/_g' \ $(grep -lr 'code.google.com/p/go.' *) LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/170920043
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
// Copyright 2014 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 lexical
|
|
|
|
import (
|
|
"go/build"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/go/buildutil"
|
|
"golang.org/x/tools/go/loader"
|
|
)
|
|
|
|
func TestStdlib(t *testing.T) {
|
|
defer func(saved func(format string, args ...interface{})) {
|
|
logf = saved
|
|
}(logf)
|
|
logf = t.Errorf
|
|
|
|
ctxt := build.Default // copy
|
|
|
|
// Enumerate $GOROOT packages.
|
|
saved := ctxt.GOPATH
|
|
ctxt.GOPATH = "" // disable GOPATH during AllPackages
|
|
pkgs := buildutil.AllPackages(&ctxt)
|
|
ctxt.GOPATH = saved
|
|
|
|
// Throw in a number of go.tools packages too.
|
|
pkgs = append(pkgs,
|
|
"golang.org/x/tools/cmd/godoc",
|
|
"golang.org/x/tools/refactor/lexical")
|
|
|
|
// Load, parse and type-check the program.
|
|
conf := loader.Config{
|
|
Build: &ctxt,
|
|
SourceImports: true,
|
|
}
|
|
for _, path := range pkgs {
|
|
if err := conf.ImportWithTests(path); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
iprog, err := conf.Load()
|
|
if err != nil {
|
|
t.Fatalf("Load failed: %v", err)
|
|
}
|
|
|
|
// This test ensures that Structure doesn't panic and that
|
|
// its internal sanity-checks against go/types don't fail.
|
|
for pkg, info := range iprog.AllPackages {
|
|
_ = Structure(iprog.Fset, pkg, &info.Info, info.Files)
|
|
}
|
|
}
|