]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/build/deps_test.go
[dev.fuzz] all: merge master (7764ee5) into dev.fuzz
[gostls13.git] / src / go / build / deps_test.go
index 16ca675f8c80797f1777732e872efc898f37f11c..3511cf41a6b5992673b2d67b79a3fdd68a10781a 100644 (file)
@@ -10,6 +10,7 @@ package build
 import (
        "bytes"
        "fmt"
+       "go/token"
        "internal/testenv"
        "io/fs"
        "os"
@@ -75,8 +76,12 @@ var depsRules = `
          unicode/utf8, unicode/utf16, unicode,
          unsafe;
 
+       # These packages depend only on unsafe.
+       unsafe
+       < internal/abi;
+
        # RUNTIME is the core runtime group of packages, all of them very light-weight.
-       internal/cpu, unsafe
+       internal/abi, internal/cpu, unsafe
        < internal/bytealg
        < internal/unsafeheader
        < runtime/internal/sys
@@ -162,6 +167,9 @@ var depsRules = `
        < os
        < os/signal;
 
+       io/fs
+       < embed;
+
        unicode, fmt !< os, os/signal;
 
        os/signal, STR
@@ -174,7 +182,7 @@ var depsRules = `
        reflect !< OS;
 
        OS
-       < golang.org/x/sys/cpu, internal/goroot;
+       < golang.org/x/sys/cpu;
 
        # FMT is OS (which includes string routines) plus reflect and fmt.
        # It does not include package log, which should be avoided in core packages.
@@ -190,6 +198,12 @@ var depsRules = `
 
        log !< FMT;
 
+       OS, FMT
+       < internal/execabs;
+
+       OS, internal/execabs
+       < internal/goroot;
+
        # Misc packages needing only FMT.
        FMT
        < flag,
@@ -275,9 +289,12 @@ var depsRules = `
        math/big, go/token
        < go/constant;
 
-       container/heap, go/constant, go/parser
+       container/heap, go/constant, go/parser, regexp
        < go/types;
 
+       FMT
+       < go/build/constraint;
+
        go/doc, go/parser, internal/goroot, internal/goversion
        < go/build;
 
@@ -605,6 +622,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" {
@@ -614,8 +632,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
@@ -843,3 +863,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)
+       }
+}