mirror of
https://github.com/golang/go
synced 2024-11-22 14:04:48 -07:00
go/build: make TestDependencies work again
CL 243940 accidentally broke TestDependencies such that it always passed. Make it work again, and add a test so that it won't break in the same way. This revealed that the new embed package was missing from TestDepencies, so add it. Fixes #43249 Change-Id: I02b3e38dd35ad88880c4344d46de13b7639aa4c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/279073 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
2de7866470
commit
139cd0e12f
@ -10,6 +10,7 @@ package build
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/token"
|
||||
"internal/testenv"
|
||||
"io/fs"
|
||||
"os"
|
||||
@ -162,6 +163,9 @@ var depsRules = `
|
||||
< os
|
||||
< os/signal;
|
||||
|
||||
io/fs
|
||||
< embed;
|
||||
|
||||
unicode, fmt !< os, os/signal;
|
||||
|
||||
os/signal, STR
|
||||
@ -602,6 +606,7 @@ func findImports(pkg string) ([]string, error) {
|
||||
}
|
||||
var imports []string
|
||||
var haveImport = map[string]bool{}
|
||||
fset := token.NewFileSet()
|
||||
for _, file := range files {
|
||||
name := file.Name()
|
||||
if name == "slice_go14.go" || name == "slice_go18.go" {
|
||||
@ -611,8 +616,10 @@ func findImports(pkg string) ([]string, error) {
|
||||
if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
|
||||
continue
|
||||
}
|
||||
var info fileInfo
|
||||
info.name = filepath.Join(dir, name)
|
||||
info := fileInfo{
|
||||
name: filepath.Join(dir, name),
|
||||
fset: fset,
|
||||
}
|
||||
f, err := os.Open(info.name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -840,3 +847,22 @@ func TestStdlibLowercase(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestFindImports tests that findImports works. See #43249.
|
||||
func TestFindImports(t *testing.T) {
|
||||
imports, err := findImports("go/build")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("go/build imports %q", imports)
|
||||
want := []string{"bytes", "os", "path/filepath", "strings"}
|
||||
wantLoop:
|
||||
for _, w := range want {
|
||||
for _, imp := range imports {
|
||||
if imp == w {
|
||||
continue wantLoop
|
||||
}
|
||||
}
|
||||
t.Errorf("expected to find %q in import list", w)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user