]> Cypherpunks.ru repositories - gostls13.git/blob - src/go/build/deps_test.go
[dev.boringcrypto] misc/boring: add new releases to RELEASES file
[gostls13.git] / src / go / build / deps_test.go
1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // This file exercises the import parser but also checks that
6 // some low-level packages do not have new dependencies added.
7
8 package build
9
10 import (
11         "bytes"
12         "fmt"
13         "go/token"
14         "internal/testenv"
15         "io/fs"
16         "os"
17         "path/filepath"
18         "runtime"
19         "sort"
20         "strings"
21         "testing"
22 )
23
24 // depsRules defines the expected dependencies between packages in
25 // the Go source tree. It is a statement of policy.
26 //
27 // DO NOT CHANGE THIS DATA TO FIX BUILDS.
28 // Existing packages should not have their constraints relaxed
29 // without prior discussion.
30 // Negative assertions should almost never be removed.
31 //
32 // The general syntax of a rule is:
33 //
34 //              a, b < c, d;
35 //
36 // which means c and d come after a and b in the partial order
37 // (that is, c and d can import a and b),
38 // but doesn't provide a relative order between a vs b or c vs d.
39 //
40 // The rules can chain together, as in:
41 //
42 //              e < f, g < h;
43 //
44 // which is equivalent to
45 //
46 //              e < f, g;
47 //              f, g < h;
48 //
49 // Except for the special bottom element "NONE", each name
50 // must appear exactly once on the right-hand side of a rule.
51 // That rule serves as the definition of the allowed dependencies
52 // for that name. The definition must appear before any uses
53 // of the name on the left-hand side of a rule. (That is, the
54 // rules themselves must be ordered according to the partial
55 // order, for easier reading by people.)
56 //
57 // Negative assertions double-check the partial order:
58 //
59 //              i !< j
60 //
61 // means that it must NOT be the case that i < j.
62 // Negative assertions may appear anywhere in the rules,
63 // even before i and j have been defined.
64 //
65 // Comments begin with #.
66 //
67 // All-caps names are pseudo-names for specific points
68 // in the dependency lattice.
69 //
70 var depsRules = `
71         # No dependencies allowed for any of these packages.
72         NONE
73         < container/list, container/ring,
74           internal/cfg, internal/cpu, internal/goarch,
75           internal/goexperiment, internal/goos,
76           internal/goversion, internal/nettrace,
77           unicode/utf8, unicode/utf16, unicode,
78           unsafe;
79
80         # These packages depend only on internal/goarch and unsafe.
81         internal/goarch, unsafe
82         < internal/abi;
83
84         # RUNTIME is the core runtime group of packages, all of them very light-weight.
85         internal/abi, internal/cpu, internal/goarch,
86         internal/goexperiment, internal/goos, unsafe
87         < internal/bytealg
88         < internal/itoa
89         < internal/unsafeheader
90         < runtime/internal/sys
91         < runtime/internal/atomic
92         < runtime/internal/math
93         < runtime
94         < sync/atomic
95         < internal/race
96         < sync
97         < internal/reflectlite
98         < errors
99         < internal/oserror, math/bits
100         < RUNTIME;
101
102         RUNTIME
103         < sort
104         < container/heap;
105
106         RUNTIME
107         < io;
108
109         syscall !< io;
110         reflect !< sort;
111
112         RUNTIME, unicode/utf8
113         < path;
114
115         unicode !< path;
116
117         # SYSCALL is RUNTIME plus the packages necessary for basic system calls.
118         RUNTIME, unicode/utf8, unicode/utf16
119         < internal/syscall/windows/sysdll, syscall/js
120         < syscall
121         < internal/syscall/unix, internal/syscall/windows, internal/syscall/windows/registry
122         < internal/syscall/execenv
123         < SYSCALL;
124
125         # TIME is SYSCALL plus the core packages about time, including context.
126         SYSCALL
127         < time/tzdata
128         < time
129         < context
130         < TIME;
131
132         TIME, io, path, sort
133         < io/fs;
134
135         # MATH is RUNTIME plus the basic math packages.
136         RUNTIME
137         < math
138         < MATH;
139
140         unicode !< math;
141
142         MATH
143         < math/cmplx;
144
145         MATH
146         < math/rand;
147
148         MATH
149         < runtime/metrics;
150
151         MATH, unicode/utf8
152         < strconv;
153
154         unicode !< strconv;
155
156         # STR is basic string and buffer manipulation.
157         RUNTIME, io, unicode/utf8, unicode/utf16, unicode
158         < bytes, strings
159         < bufio;
160
161         bufio, path, strconv
162         < STR;
163
164         # OS is basic OS access, including helpers (path/filepath, os/exec, etc).
165         # OS includes string routines, but those must be layered above package os.
166         # OS does not include reflection.
167         io/fs
168         < internal/testlog
169         < internal/poll
170         < os
171         < os/signal;
172
173         io/fs
174         < embed;
175
176         unicode, fmt !< os, os/signal;
177
178         os/signal, STR
179         < path/filepath
180         < io/ioutil, os/exec;
181
182         io/ioutil, os/exec, os/signal
183         < OS;
184
185         reflect !< OS;
186
187         OS
188         < golang.org/x/sys/cpu;
189
190         # FMT is OS (which includes string routines) plus reflect and fmt.
191         # It does not include package log, which should be avoided in core packages.
192         strconv, unicode
193         < reflect;
194
195         os, reflect
196         < internal/fmtsort
197         < fmt;
198
199         OS, fmt
200         < FMT;
201
202         log !< FMT;
203
204         OS, FMT
205         < internal/execabs;
206
207         OS, internal/execabs
208         < internal/goroot;
209
210         # Misc packages needing only FMT.
211         FMT
212         < flag,
213           html,
214           mime/quotedprintable,
215           net/internal/socktest,
216           net/url,
217           runtime/debug,
218           runtime/trace,
219           text/scanner,
220           text/tabwriter;
221
222         # encodings
223         # core ones do not use fmt.
224         io, strconv
225         < encoding;
226
227         encoding, reflect
228         < encoding/binary
229         < encoding/base32, encoding/base64;
230
231         fmt !< encoding/base32, encoding/base64;
232
233         FMT, encoding/base32, encoding/base64
234         < encoding/ascii85, encoding/csv, encoding/gob, encoding/hex,
235           encoding/json, encoding/pem, encoding/xml, mime;
236
237         # hashes
238         io
239         < hash
240         < hash/adler32, hash/crc32, hash/crc64, hash/fnv, hash/maphash;
241
242         # math/big
243         FMT, encoding/binary, math/rand
244         < math/big;
245
246         # compression
247         FMT, encoding/binary, hash/adler32, hash/crc32
248         < compress/bzip2, compress/flate, compress/lzw
249         < archive/zip, compress/gzip, compress/zlib;
250
251         # templates
252         FMT
253         < text/template/parse;
254
255         net/url, text/template/parse
256         < text/template
257         < internal/lazytemplate;
258
259         encoding/json, html, text/template
260         < html/template;
261
262         # regexp
263         FMT
264         < regexp/syntax
265         < regexp
266         < internal/lazyregexp;
267
268         # suffix array
269         encoding/binary, regexp
270         < index/suffixarray;
271
272         # executable parsing
273         FMT, encoding/binary, compress/zlib
274         < debug/dwarf
275         < debug/elf, debug/gosym, debug/macho, debug/pe, debug/plan9obj, internal/xcoff
276         < DEBUG;
277
278         # go parser and friends.
279         FMT
280         < go/token
281         < go/scanner
282         < go/ast
283         < go/internal/typeparams
284         < go/parser;
285
286         FMT
287         < go/build/constraint;
288
289         go/build/constraint, go/parser, text/tabwriter
290         < go/printer
291         < go/format;
292
293         go/parser, internal/lazyregexp, text/template
294         < go/doc;
295
296         math/big, go/token
297         < go/constant;
298
299         container/heap, go/constant, go/parser, regexp
300         < go/types;
301
302         FMT, internal/goexperiment
303         < internal/buildcfg;
304
305         go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion
306         < go/build;
307
308         DEBUG, go/build, go/types, text/scanner
309         < go/internal/gcimporter, go/internal/gccgoimporter, go/internal/srcimporter
310         < go/importer;
311
312         # databases
313         FMT
314         < database/sql/internal
315         < database/sql/driver
316         < database/sql;
317
318         # images
319         FMT, compress/lzw, compress/zlib
320         < image/color
321         < image, image/color/palette
322         < image/internal/imageutil
323         < image/draw
324         < image/gif, image/jpeg, image/png;
325
326         # cgo, delayed as long as possible.
327         # If you add a dependency on CGO, you must add the package
328         # to cgoPackages in cmd/dist/test.go as well.
329         RUNTIME
330         < C
331         < runtime/cgo
332         < CGO
333         < runtime/race, runtime/msan;
334
335         # Bulk of the standard library must not use cgo.
336         # The prohibition stops at net and os/user.
337         C !< fmt, go/types;
338
339         CGO, OS
340         < plugin;
341
342         CGO, FMT
343         < os/user
344         < archive/tar;
345
346         sync
347         < internal/singleflight;
348
349         os
350         < golang.org/x/net/dns/dnsmessage,
351           golang.org/x/net/lif,
352           golang.org/x/net/route;
353
354         # net is unavoidable when doing any networking,
355         # so large dependencies must be kept out.
356         # This is a long-looking list but most of these
357         # are small with few dependencies.
358         CGO,
359         golang.org/x/net/dns/dnsmessage,
360         golang.org/x/net/lif,
361         golang.org/x/net/route,
362         internal/nettrace,
363         internal/poll,
364         internal/singleflight,
365         internal/race,
366         os
367         < net;
368
369         fmt, unicode !< net;
370         math/rand !< net; # net uses runtime instead
371
372         # NET is net plus net-helper packages.
373         FMT, net
374         < net/textproto;
375
376         mime, net/textproto, net/url
377         < NET;
378
379         # logging - most packages should not import; http and up is allowed
380         FMT
381         < log;
382
383         log !< crypto/tls, database/sql, go/importer, testing;
384
385         FMT, log, net
386         < log/syslog;
387
388         NET, log
389         < net/mail;
390
391         NONE < crypto/internal/boring/sig;
392         sync/atomic < crypto/internal/boring/fipstls;
393
394         encoding/binary, golang.org/x/sys/cpu, hash,
395         FMT, math/big,
396         CGO, crypto/internal/boring/sig, crypto/internal/boring/fipstls
397         < crypto
398         < crypto/subtle
399         < crypto/internal/subtle
400         < crypto/elliptic/internal/fiat
401         < crypto/ed25519/internal/edwards25519/field
402         < crypto/ed25519/internal/edwards25519
403         < crypto/cipher
404         < encoding/asn1
405         < crypto/internal/boring
406         < crypto/aes, crypto/des, crypto/hmac, crypto/md5, crypto/rc4,
407           crypto/sha1, crypto/sha256, crypto/sha512
408         < crypto/rand
409         < crypto/internal/randutil
410         < crypto/ed25519
411         < golang.org/x/crypto/cryptobyte/asn1
412         < golang.org/x/crypto/cryptobyte
413         < golang.org/x/crypto/curve25519
414         < crypto/dsa, crypto/elliptic, crypto/rsa
415         < crypto/ecdsa
416         < CRYPTO-BORING;
417
418         net !< CRYPTO-BORING;
419
420         # TLS, Prince of Dependencies.
421         CRYPTO-BORING, NET, container/list, encoding/hex, encoding/pem
422         < golang.org/x/crypto/internal/subtle
423         < golang.org/x/crypto/chacha20
424         < golang.org/x/crypto/poly1305
425         < golang.org/x/crypto/chacha20poly1305
426         < golang.org/x/crypto/hkdf
427         < crypto/x509/internal/macos
428         < crypto/x509/pkix
429         < crypto/x509
430         < crypto/tls;
431
432         crypto/internal/boring/sig, crypto/internal/boring/fipstls
433         < crypto/tls/fipsonly;
434
435         crypto/internal/boring
436         < crypto/boring;
437
438         # crypto-aware packages
439
440         NET, crypto/rand, mime/quotedprintable
441         < mime/multipart;
442
443         crypto/tls
444         < net/smtp;
445
446         # HTTP, King of Dependencies.
447
448         FMT
449         < golang.org/x/net/http2/hpack
450         < net/http/internal, net/http/internal/ascii, net/http/internal/testcert;
451
452         FMT, NET, container/list, encoding/binary, log
453         < golang.org/x/text/transform
454         < golang.org/x/text/unicode/norm
455         < golang.org/x/text/unicode/bidi
456         < golang.org/x/text/secure/bidirule
457         < golang.org/x/net/idna
458         < golang.org/x/net/http/httpguts, golang.org/x/net/http/httpproxy;
459
460         NET, crypto/tls
461         < net/http/httptrace;
462
463         compress/gzip,
464         golang.org/x/net/http/httpguts,
465         golang.org/x/net/http/httpproxy,
466         golang.org/x/net/http2/hpack,
467         net/http/internal,
468         net/http/internal/ascii,
469         net/http/internal/testcert,
470         net/http/httptrace,
471         mime/multipart,
472         log
473         < net/http;
474
475         # HTTP-aware packages
476
477         encoding/json, net/http
478         < expvar;
479
480         net/http, net/http/internal/ascii
481         < net/http/cookiejar, net/http/httputil;
482
483         net/http, flag
484         < net/http/httptest;
485
486         net/http, regexp
487         < net/http/cgi
488         < net/http/fcgi;
489
490         # Profiling
491         FMT, compress/gzip, encoding/binary, text/tabwriter
492         < runtime/pprof;
493
494         OS, compress/gzip, regexp
495         < internal/profile;
496
497         html, internal/profile, net/http, runtime/pprof, runtime/trace
498         < net/http/pprof;
499
500         # RPC
501         encoding/gob, encoding/json, go/token, html/template, net/http
502         < net/rpc
503         < net/rpc/jsonrpc;
504
505         # System Information
506         internal/cpu, sync
507         < internal/sysinfo;
508
509         # Test-only
510         log
511         < testing/iotest
512         < testing/fstest;
513
514         FMT, flag, math/rand
515         < testing/quick;
516
517         FMT, flag, runtime/debug, runtime/trace, internal/sysinfo, math/rand
518         < testing;
519
520         internal/testlog, runtime/pprof, regexp
521         < testing/internal/testdeps;
522
523         OS, flag, testing, internal/cfg
524         < internal/testenv;
525
526         OS, encoding/base64
527         < internal/obscuretestdata;
528
529         CGO, OS, fmt
530         < os/signal/internal/pty;
531
532         NET, testing, math/rand
533         < golang.org/x/net/nettest;
534
535         FMT, container/heap, math/rand
536         < internal/trace;
537 `
538
539 // listStdPkgs returns the same list of packages as "go list std".
540 func listStdPkgs(goroot string) ([]string, error) {
541         // Based on cmd/go's matchPackages function.
542         var pkgs []string
543
544         src := filepath.Join(goroot, "src") + string(filepath.Separator)
545         walkFn := func(path string, d fs.DirEntry, err error) error {
546                 if err != nil || !d.IsDir() || path == src {
547                         return nil
548                 }
549
550                 base := filepath.Base(path)
551                 if strings.HasPrefix(base, ".") || strings.HasPrefix(base, "_") || base == "testdata" {
552                         return filepath.SkipDir
553                 }
554
555                 name := filepath.ToSlash(path[len(src):])
556                 if name == "builtin" || name == "cmd" {
557                         return filepath.SkipDir
558                 }
559
560                 pkgs = append(pkgs, strings.TrimPrefix(name, "vendor/"))
561                 return nil
562         }
563         if err := filepath.WalkDir(src, walkFn); err != nil {
564                 return nil, err
565         }
566         return pkgs, nil
567 }
568
569 func TestDependencies(t *testing.T) {
570         if !testenv.HasSrc() {
571                 // Tests run in a limited file system and we do not
572                 // provide access to every source file.
573                 t.Skipf("skipping on %s/%s, missing full GOROOT", runtime.GOOS, runtime.GOARCH)
574         }
575
576         ctxt := Default
577         all, err := listStdPkgs(ctxt.GOROOT)
578         if err != nil {
579                 t.Fatal(err)
580         }
581         sort.Strings(all)
582
583         sawImport := map[string]map[string]bool{} // from package => to package => true
584         policy := depsPolicy(t)
585
586         for _, pkg := range all {
587                 imports, err := findImports(pkg)
588                 if err != nil {
589                         t.Error(err)
590                         continue
591                 }
592                 if sawImport[pkg] == nil {
593                         sawImport[pkg] = map[string]bool{}
594                 }
595                 ok := policy[pkg]
596                 var bad []string
597                 for _, imp := range imports {
598                         sawImport[pkg][imp] = true
599                         if !ok[imp] {
600                                 bad = append(bad, imp)
601                         }
602                 }
603                 if bad != nil {
604                         t.Errorf("unexpected dependency: %s imports %v", pkg, bad)
605                 }
606         }
607
608         // depPath returns the path between the given from and to packages.
609         // It returns the empty string if there's no dependency path.
610         var depPath func(string, string) string
611         depPath = func(from, to string) string {
612                 if sawImport[from][to] {
613                         return from + " => " + to
614                 }
615                 for pkg := range sawImport[from] {
616                         if p := depPath(pkg, to); p != "" {
617                                 return from + " => " + p
618                         }
619                 }
620                 return ""
621         }
622 }
623
624 var buildIgnore = []byte("\n// +build ignore")
625
626 func findImports(pkg string) ([]string, error) {
627         vpkg := pkg
628         if strings.HasPrefix(pkg, "golang.org") {
629                 vpkg = "vendor/" + pkg
630         }
631         dir := filepath.Join(Default.GOROOT, "src", vpkg)
632         files, err := os.ReadDir(dir)
633         if err != nil {
634                 return nil, err
635         }
636         var imports []string
637         var haveImport = map[string]bool{}
638         fset := token.NewFileSet()
639         for _, file := range files {
640                 name := file.Name()
641                 if name == "slice_go14.go" || name == "slice_go18.go" {
642                         // These files are for compiler bootstrap with older versions of Go and not built in the standard build.
643                         continue
644                 }
645                 if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
646                         continue
647                 }
648                 info := fileInfo{
649                         name: filepath.Join(dir, name),
650                         fset: fset,
651                 }
652                 f, err := os.Open(info.name)
653                 if err != nil {
654                         return nil, err
655                 }
656                 err = readGoInfo(f, &info)
657                 f.Close()
658                 if err != nil {
659                         return nil, fmt.Errorf("reading %v: %v", name, err)
660                 }
661                 if bytes.Contains(info.header, buildIgnore) {
662                         continue
663                 }
664                 for _, imp := range info.imports {
665                         path := imp.path
666                         if !haveImport[path] {
667                                 haveImport[path] = true
668                                 imports = append(imports, path)
669                         }
670                 }
671         }
672         sort.Strings(imports)
673         return imports, nil
674 }
675
676 // depsPolicy returns a map m such that m[p][d] == true when p can import d.
677 func depsPolicy(t *testing.T) map[string]map[string]bool {
678         allowed := map[string]map[string]bool{"NONE": {}}
679         disallowed := [][2][]string{}
680
681         parseDepsRules(t, func(deps []string, op string, users []string) {
682                 if op == "!<" {
683                         disallowed = append(disallowed, [2][]string{deps, users})
684                         return
685                 }
686                 for _, u := range users {
687                         if allowed[u] != nil {
688                                 t.Errorf("multiple deps lists for %s", u)
689                         }
690                         allowed[u] = make(map[string]bool)
691                         for _, d := range deps {
692                                 if allowed[d] == nil {
693                                         t.Errorf("use of %s before its deps list", d)
694                                 }
695                                 allowed[u][d] = true
696                         }
697                 }
698         })
699
700         // Check for missing deps info.
701         for _, deps := range allowed {
702                 for d := range deps {
703                         if allowed[d] == nil {
704                                 t.Errorf("missing deps list for %s", d)
705                         }
706                 }
707         }
708
709         // Complete transitive allowed deps.
710         for k := range allowed {
711                 for i := range allowed {
712                         for j := range allowed {
713                                 if i != k && k != j && allowed[i][k] && allowed[k][j] {
714                                         if i == j {
715                                                 // Can only happen along with a "use of X before deps" error above,
716                                                 // but this error is more specific - it makes clear that reordering the
717                                                 // rules will not be enough to fix the problem.
718                                                 t.Errorf("deps policy cycle: %s < %s < %s", j, k, i)
719                                         }
720                                         allowed[i][j] = true
721                                 }
722                         }
723                 }
724         }
725
726         // Check negative assertions against completed allowed deps.
727         for _, bad := range disallowed {
728                 deps, users := bad[0], bad[1]
729                 for _, d := range deps {
730                         for _, u := range users {
731                                 if allowed[u][d] {
732                                         t.Errorf("deps policy incorrect: assertion failed: %s !< %s", d, u)
733                                 }
734                         }
735                 }
736         }
737
738         if t.Failed() {
739                 t.FailNow()
740         }
741
742         return allowed
743 }
744
745 // parseDepsRules parses depsRules, calling save(deps, op, users)
746 // for each deps < users or deps !< users rule
747 // (op is "<" or "!<").
748 func parseDepsRules(t *testing.T, save func(deps []string, op string, users []string)) {
749         p := &depsParser{t: t, lineno: 1, text: depsRules}
750
751         var prev []string
752         var op string
753         for {
754                 list, tok := p.nextList()
755                 if tok == "" {
756                         if prev == nil {
757                                 break
758                         }
759                         p.syntaxError("unexpected EOF")
760                 }
761                 if prev != nil {
762                         save(prev, op, list)
763                 }
764                 prev = list
765                 if tok == ";" {
766                         prev = nil
767                         op = ""
768                         continue
769                 }
770                 if tok != "<" && tok != "!<" {
771                         p.syntaxError("missing <")
772                 }
773                 op = tok
774         }
775 }
776
777 // A depsParser parses the depsRules syntax described above.
778 type depsParser struct {
779         t        *testing.T
780         lineno   int
781         lastWord string
782         text     string
783 }
784
785 // syntaxError reports a parsing error.
786 func (p *depsParser) syntaxError(msg string) {
787         p.t.Fatalf("deps:%d: syntax error: %s near %s", p.lineno, msg, p.lastWord)
788 }
789
790 // nextList parses and returns a comma-separated list of names.
791 func (p *depsParser) nextList() (list []string, token string) {
792         for {
793                 tok := p.nextToken()
794                 switch tok {
795                 case "":
796                         if len(list) == 0 {
797                                 return nil, ""
798                         }
799                         fallthrough
800                 case ",", "<", "!<", ";":
801                         p.syntaxError("bad list syntax")
802                 }
803                 list = append(list, tok)
804
805                 tok = p.nextToken()
806                 if tok != "," {
807                         return list, tok
808                 }
809         }
810 }
811
812 // nextToken returns the next token in the deps rules,
813 // one of ";" "," "<" "!<" or a name.
814 func (p *depsParser) nextToken() string {
815         for {
816                 if p.text == "" {
817                         return ""
818                 }
819                 switch p.text[0] {
820                 case ';', ',', '<':
821                         t := p.text[:1]
822                         p.text = p.text[1:]
823                         return t
824
825                 case '!':
826                         if len(p.text) < 2 || p.text[1] != '<' {
827                                 p.syntaxError("unexpected token !")
828                         }
829                         p.text = p.text[2:]
830                         return "!<"
831
832                 case '#':
833                         i := strings.Index(p.text, "\n")
834                         if i < 0 {
835                                 i = len(p.text)
836                         }
837                         p.text = p.text[i:]
838                         continue
839
840                 case '\n':
841                         p.lineno++
842                         fallthrough
843                 case ' ', '\t':
844                         p.text = p.text[1:]
845                         continue
846
847                 default:
848                         i := strings.IndexAny(p.text, "!;,<#\n \t")
849                         if i < 0 {
850                                 i = len(p.text)
851                         }
852                         t := p.text[:i]
853                         p.text = p.text[i:]
854                         p.lastWord = t
855                         return t
856                 }
857         }
858 }
859
860 // TestStdlibLowercase tests that all standard library package names are
861 // lowercase. See Issue 40065.
862 func TestStdlibLowercase(t *testing.T) {
863         if !testenv.HasSrc() {
864                 t.Skipf("skipping on %s/%s, missing full GOROOT", runtime.GOOS, runtime.GOARCH)
865         }
866
867         ctxt := Default
868         all, err := listStdPkgs(ctxt.GOROOT)
869         if err != nil {
870                 t.Fatal(err)
871         }
872
873         for _, pkgname := range all {
874                 if strings.ToLower(pkgname) != pkgname {
875                         t.Errorf("package %q should not use upper-case path", pkgname)
876                 }
877         }
878 }
879
880 // TestFindImports tests that findImports works.  See #43249.
881 func TestFindImports(t *testing.T) {
882         imports, err := findImports("go/build")
883         if err != nil {
884                 t.Fatal(err)
885         }
886         t.Logf("go/build imports %q", imports)
887         want := []string{"bytes", "os", "path/filepath", "strings"}
888 wantLoop:
889         for _, w := range want {
890                 for _, imp := range imports {
891                         if imp == w {
892                                 continue wantLoop
893                         }
894                 }
895                 t.Errorf("expected to find %q in import list", w)
896         }
897 }