imports: stub out dirPackageInfo function in tests
TestFixImports did not have to explicitly add "strings" to the simplePkgs map - this only happened because sibling files were searched and the strings import was found through them. If we stub out the dirPackageInfo function, we have to explicitly add the strings import. Change-Id: I149e522fad37039fc790e6a855834d86ff050674 Reviewed-on: https://go-review.googlesource.com/129036 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
7883bde2a5
commit
cf99646d84
|
@ -8,6 +8,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -1066,16 +1067,22 @@ func TestFixImports(t *testing.T) {
|
|||
"regexp": "regexp",
|
||||
"snappy": "code.google.com/p/snappy-go/snappy",
|
||||
"str": "strings",
|
||||
"strings": "strings",
|
||||
"user": "appengine/user",
|
||||
"zip": "archive/zip",
|
||||
}
|
||||
old := findImport
|
||||
oldFindImport := findImport
|
||||
oldDirPackageInfo := dirPackageInfo
|
||||
defer func() {
|
||||
findImport = old
|
||||
findImport = oldFindImport
|
||||
dirPackageInfo = oldDirPackageInfo
|
||||
}()
|
||||
findImport = func(_ context.Context, pkgName string, symbols map[string]bool, filename string) (string, bool, error) {
|
||||
return simplePkgs[pkgName], pkgName == "str", nil
|
||||
}
|
||||
dirPackageInfo = func(_, _, _ string) (*packageInfo, error) {
|
||||
return nil, fmt.Errorf("no directory package info in tests")
|
||||
}
|
||||
|
||||
options := &Options{
|
||||
TabWidth: 8,
|
||||
|
|
Loading…
Reference in New Issue