1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:24:41 -07:00
go/refactor/lexical/lexical_test.go
Alan Donovan 69db398fe0 go/loader: rename SourceImports flag to ImportFromBinary and invert sense
...since the zero value is more useful by far.

This is a breaking API change, obviously.  (One or two tests in this
CL have intentional been left using the zero value, i.e., they now
load source.)

Change-Id: I42287bfcdb1afef8ee84e5eac12534dd0a1fd5d2
Reviewed-on: https://go-review.googlesource.com/5653
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-02-23 23:01:10 +00:00

50 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}
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)
}
}