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