Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 139cd0e

Browse files
committedDec 18, 2020
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 2de7866 commit 139cd0e

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed
 

‎src/go/build/deps_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package build
1010
import (
1111
"bytes"
1212
"fmt"
13+
"go/token"
1314
"internal/testenv"
1415
"io/fs"
1516
"os"
@@ -162,6 +163,9 @@ var depsRules = `
162163
< os
163164
< os/signal;
164165
166+
io/fs
167+
< embed;
168+
165169
unicode, fmt !< os, os/signal;
166170
167171
os/signal, STR
@@ -602,6 +606,7 @@ func findImports(pkg string) ([]string, error) {
602606
}
603607
var imports []string
604608
var haveImport = map[string]bool{}
609+
fset := token.NewFileSet()
605610
for _, file := range files {
606611
name := file.Name()
607612
if name == "slice_go14.go" || name == "slice_go18.go" {
@@ -611,8 +616,10 @@ func findImports(pkg string) ([]string, error) {
611616
if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
612617
continue
613618
}
614-
var info fileInfo
615-
info.name = filepath.Join(dir, name)
619+
info := fileInfo{
620+
name: filepath.Join(dir, name),
621+
fset: fset,
622+
}
616623
f, err := os.Open(info.name)
617624
if err != nil {
618625
return nil, err
@@ -840,3 +847,22 @@ func TestStdlibLowercase(t *testing.T) {
840847
}
841848
}
842849
}
850+
851+
// TestFindImports tests that findImports works. See #43249.
852+
func TestFindImports(t *testing.T) {
853+
imports, err := findImports("go/build")
854+
if err != nil {
855+
t.Fatal(err)
856+
}
857+
t.Logf("go/build imports %q", imports)
858+
want := []string{"bytes", "os", "path/filepath", "strings"}
859+
wantLoop:
860+
for _, w := range want {
861+
for _, imp := range imports {
862+
if imp == w {
863+
continue wantLoop
864+
}
865+
}
866+
t.Errorf("expected to find %q in import list", w)
867+
}
868+
}

0 commit comments

Comments
 (0)
Please sign in to comment.