mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
0dda50d42a
Before this change, many kinds of error would cause the loader to stop. making it brittle when analyzing large codebases, as in "godoc -analysis". This change moves operations that used to occur during configuration---(*build.Context).Import, loading, and parsing of initial packages---into the Load call, and ensures that all failures during Loading are reported at the end so that the maximum amount of progress is made. Also: redesign the tests and add many new cases. Change-Id: Ia8cd99416af7c5d4a5fe133908adfa83676d401f Reviewed-on: https://go-review.googlesource.com/3626 Reviewed-by: Robert Griesemer <gri@golang.org>
53 lines
1.2 KiB
Go
53 lines
1.2 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 {
|
|
conf.ImportWithTests(path)
|
|
}
|
|
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)
|
|
}
|
|
}
|