1 // Copyright 2011 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.
19 func TestMain(m *testing.M) {
20 Default.GOROOT = testenv.GOROOT(nil)
24 func TestMatch(t *testing.T) {
27 match := func(tag string, want map[string]bool) {
29 m := make(map[string]bool)
30 if !ctxt.matchAuto(tag, m) {
31 t.Errorf("%s context should match %s, does not", what, tag)
33 if !reflect.DeepEqual(m, want) {
34 t.Errorf("%s tags = %v, want %v", tag, m, want)
37 nomatch := func(tag string, want map[string]bool) {
39 m := make(map[string]bool)
40 if ctxt.matchAuto(tag, m) {
41 t.Errorf("%s context should NOT match %s, does", what, tag)
43 if !reflect.DeepEqual(m, want) {
44 t.Errorf("%s tags = %v, want %v", tag, m, want)
48 match(runtime.GOOS+","+runtime.GOARCH, map[string]bool{runtime.GOOS: true, runtime.GOARCH: true})
49 match(runtime.GOOS+","+runtime.GOARCH+",!foo", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "foo": true})
50 nomatch(runtime.GOOS+","+runtime.GOARCH+",foo", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "foo": true})
53 ctxt.BuildTags = []string{"foo"}
54 match(runtime.GOOS+","+runtime.GOARCH, map[string]bool{runtime.GOOS: true, runtime.GOARCH: true})
55 match(runtime.GOOS+","+runtime.GOARCH+",foo", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "foo": true})
56 nomatch(runtime.GOOS+","+runtime.GOARCH+",!foo", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "foo": true})
57 match(runtime.GOOS+","+runtime.GOARCH+",!bar", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "bar": true})
58 nomatch(runtime.GOOS+","+runtime.GOARCH+",bar", map[string]bool{runtime.GOOS: true, runtime.GOARCH: true, "bar": true})
61 func TestDotSlashImport(t *testing.T) {
62 p, err := ImportDir("testdata/other", 0)
66 if len(p.Imports) != 1 || p.Imports[0] != "./file" {
67 t.Fatalf("testdata/other: Imports=%v, want [./file]", p.Imports)
70 p1, err := Import("./file", "testdata/other", 0)
74 if p1.Name != "file" {
75 t.Fatalf("./file: Name=%q, want %q", p1.Name, "file")
77 dir := filepath.Clean("testdata/other/file") // Clean to use \ on Windows
79 t.Fatalf("./file: Dir=%q, want %q", p1.Name, dir)
83 func TestEmptyImport(t *testing.T) {
84 p, err := Import("", testenv.GOROOT(t), FindOnly)
86 t.Fatal(`Import("") returned nil error.`)
89 t.Fatal(`Import("") returned nil package.`)
91 if p.ImportPath != "" {
92 t.Fatalf("ImportPath=%q, want %q.", p.ImportPath, "")
96 func TestEmptyFolderImport(t *testing.T) {
97 _, err := Import(".", "testdata/empty", 0)
98 if _, ok := err.(*NoGoError); !ok {
99 t.Fatal(`Import("testdata/empty") did not return NoGoError.`)
103 func TestMultiplePackageImport(t *testing.T) {
104 pkg, err := Import(".", "testdata/multi", 0)
106 mpe, ok := err.(*MultiplePackageError)
108 t.Fatal(`Import("testdata/multi") did not return MultiplePackageError.`)
110 want := &MultiplePackageError{
111 Dir: filepath.FromSlash("testdata/multi"),
112 Packages: []string{"main", "test_package"},
113 Files: []string{"file.go", "file_appengine.go"},
115 if !reflect.DeepEqual(mpe, want) {
116 t.Errorf("err = %#v; want %#v", mpe, want)
119 // TODO(#45999): Since the name is ambiguous, pkg.Name should be left empty.
120 if wantName := "main"; pkg.Name != wantName {
121 t.Errorf("pkg.Name = %q; want %q", pkg.Name, wantName)
124 if wantGoFiles := []string{"file.go", "file_appengine.go"}; !reflect.DeepEqual(pkg.GoFiles, wantGoFiles) {
125 t.Errorf("pkg.GoFiles = %q; want %q", pkg.GoFiles, wantGoFiles)
128 if wantInvalidFiles := []string{"file_appengine.go"}; !reflect.DeepEqual(pkg.InvalidGoFiles, wantInvalidFiles) {
129 t.Errorf("pkg.InvalidGoFiles = %q; want %q", pkg.InvalidGoFiles, wantInvalidFiles)
133 func TestLocalDirectory(t *testing.T) {
134 if runtime.GOOS == "ios" {
135 t.Skipf("skipping on %s/%s, no valid GOROOT", runtime.GOOS, runtime.GOARCH)
138 cwd, err := os.Getwd()
143 p, err := ImportDir(cwd, 0)
147 if p.ImportPath != "go/build" {
148 t.Fatalf("ImportPath=%q, want %q", p.ImportPath, "go/build")
152 var shouldBuildTests = []struct {
162 content: "// +build yes\n\n" +
164 tags: map[string]bool{"yes": true},
169 content: "//go:build yes\n" +
171 tags: map[string]bool{"yes": true},
176 content: "// +build no yes\n\n" +
178 tags: map[string]bool{"yes": true, "no": true},
183 content: "//go:build no || yes\n" +
185 tags: map[string]bool{"yes": true, "no": true},
190 content: "// +build no,yes\n\n" +
192 tags: map[string]bool{"yes": true, "no": true},
197 content: "//go:build no && yes\n" +
199 tags: map[string]bool{"yes": true, "no": true},
204 content: "// +build cgo\n\n" +
205 "// Copyright The Go Authors.\n\n" +
206 "// This package implements parsing of tags like\n" +
209 tags: map[string]bool{"cgo": true},
214 content: "//go:build cgo\n" +
215 "// Copyright The Go Authors.\n\n" +
216 "// This package implements parsing of tags like\n" +
219 tags: map[string]bool{"cgo": true},
223 name: "AfterPackage",
224 content: "// Copyright The Go Authors.\n\n" +
225 "package build\n\n" +
226 "// shouldBuild checks tags given by lines of the form\n" +
229 "func shouldBuild(content []byte)\n",
230 tags: map[string]bool{},
235 content: "// +build yes\n" +
237 tags: map[string]bool{},
242 content: "//go:build yes\n" +
244 tags: map[string]bool{"yes": true},
249 content: "// +build no\n" +
251 tags: map[string]bool{},
256 content: "//go:build no\n" +
258 tags: map[string]bool{"no": true},
263 content: "//go:binary-only-package\n" +
266 tags: map[string]bool{},
272 content: "//go:binary-only-package\n" +
275 tags: map[string]bool{"no": true},
280 name: "ValidGoBuild",
281 content: "// +build yes\n\n" +
284 tags: map[string]bool{"no": true},
288 name: "MissingBuild2",
290 "// +build yes\n\n" +
293 tags: map[string]bool{"no": true},
302 tags: map[string]bool{},
312 tags: map[string]bool{"no": true},
317 content: "/*/*/ /* hi *//* \n" +
322 tags: map[string]bool{"no": true},
327 content: "/**///go:build no\n" +
329 tags: map[string]bool{},
337 tags: map[string]bool{"no": true},
342 func TestShouldBuild(t *testing.T) {
343 for _, tt := range shouldBuildTests {
344 t.Run(tt.name, func(t *testing.T) {
345 ctx := &Context{BuildTags: []string{"yes"}}
346 tags := map[string]bool{}
347 shouldBuild, binaryOnly, err := ctx.shouldBuild([]byte(tt.content), tags)
348 if shouldBuild != tt.shouldBuild || binaryOnly != tt.binaryOnly || !reflect.DeepEqual(tags, tt.tags) || err != tt.err {
349 t.Errorf("mismatch:\n"+
350 "have shouldBuild=%v, binaryOnly=%v, tags=%v, err=%v\n"+
351 "want shouldBuild=%v, binaryOnly=%v, tags=%v, err=%v",
352 shouldBuild, binaryOnly, tags, err,
353 tt.shouldBuild, tt.binaryOnly, tt.tags, tt.err)
359 func TestGoodOSArchFile(t *testing.T) {
360 ctx := &Context{BuildTags: []string{"linux"}, GOOS: "darwin"}
361 m := map[string]bool{}
362 want := map[string]bool{"linux": true}
363 if !ctx.goodOSArchFile("hello_linux.go", m) {
364 t.Errorf("goodOSArchFile(hello_linux.go) = false, want true")
366 if !reflect.DeepEqual(m, want) {
367 t.Errorf("goodOSArchFile(hello_linux.go) tags = %v, want %v", m, want)
371 type readNopCloser struct {
375 func (r readNopCloser) Close() error {
380 ctxtP9 = Context{GOARCH: "arm", GOOS: "plan9"}
381 ctxtAndroid = Context{GOARCH: "arm", GOOS: "android"}
384 var matchFileTests = []struct {
390 {ctxtP9, "foo_arm.go", "", true},
391 {ctxtP9, "foo1_arm.go", "// +build linux\n\npackage main\n", false},
392 {ctxtP9, "foo_darwin.go", "", false},
393 {ctxtP9, "foo.go", "", true},
394 {ctxtP9, "foo1.go", "// +build linux\n\npackage main\n", false},
395 {ctxtP9, "foo.badsuffix", "", false},
396 {ctxtAndroid, "foo_linux.go", "", true},
397 {ctxtAndroid, "foo_android.go", "", true},
398 {ctxtAndroid, "foo_plan9.go", "", false},
399 {ctxtAndroid, "android.go", "", true},
400 {ctxtAndroid, "plan9.go", "", true},
401 {ctxtAndroid, "plan9_test.go", "", true},
402 {ctxtAndroid, "arm.s", "", true},
403 {ctxtAndroid, "amd64.s", "", true},
406 func TestMatchFile(t *testing.T) {
407 for _, tt := range matchFileTests {
409 ctxt.OpenFile = func(path string) (r io.ReadCloser, err error) {
410 if path != "x+"+tt.name {
411 t.Fatalf("OpenFile asked for %q, expected %q", path, "x+"+tt.name)
413 return &readNopCloser{strings.NewReader(tt.data)}, nil
415 ctxt.JoinPath = func(elem ...string) string {
416 return strings.Join(elem, "+")
418 match, err := ctxt.MatchFile("x", tt.name)
419 if match != tt.match || err != nil {
420 t.Fatalf("MatchFile(%q) = %v, %v, want %v, nil", tt.name, match, err, tt.match)
425 func TestImportCmd(t *testing.T) {
426 if runtime.GOOS == "ios" {
427 t.Skipf("skipping on %s/%s, no valid GOROOT", runtime.GOOS, runtime.GOARCH)
430 p, err := Import("cmd/internal/objfile", "", 0)
434 if !strings.HasSuffix(filepath.ToSlash(p.Dir), "src/cmd/internal/objfile") {
435 t.Fatalf("Import cmd/internal/objfile returned Dir=%q, want %q", filepath.ToSlash(p.Dir), ".../src/cmd/internal/objfile")
440 expandSrcDirPath = filepath.Join(string(filepath.Separator)+"projects", "src", "add")
443 var expandSrcDirTests = []struct {
444 input, expected string
446 {"-L ${SRCDIR}/libs -ladd", "-L /projects/src/add/libs -ladd"},
447 {"${SRCDIR}/add_linux_386.a -pthread -lstdc++", "/projects/src/add/add_linux_386.a -pthread -lstdc++"},
448 {"Nothing to expand here!", "Nothing to expand here!"},
453 {"$FOO ${BAR}", "$FOO ${BAR}"},
454 {"Find me the $SRCDIRECTORY.", "Find me the $SRCDIRECTORY."},
455 {"$SRCDIR is missing braces", "$SRCDIR is missing braces"},
458 func TestExpandSrcDir(t *testing.T) {
459 for _, test := range expandSrcDirTests {
460 output, _ := expandSrcDir(test.input, expandSrcDirPath)
461 if output != test.expected {
462 t.Errorf("%q expands to %q with SRCDIR=%q when %q is expected", test.input, output, expandSrcDirPath, test.expected)
464 t.Logf("%q expands to %q with SRCDIR=%q", test.input, output, expandSrcDirPath)
469 func TestShellSafety(t *testing.T) {
471 input, srcdir, expected string
474 {"-I${SRCDIR}/../include", "/projects/src/issue 11868", "-I/projects/src/issue 11868/../include", true},
475 {"-I${SRCDIR}", "~wtf$@%^", "-I~wtf$@%^", true},
476 {"-X${SRCDIR}/1,${SRCDIR}/2", "/projects/src/issue 11868", "-X/projects/src/issue 11868/1,/projects/src/issue 11868/2", true},
477 {"-I/tmp -I/tmp", "/tmp2", "-I/tmp -I/tmp", true},
478 {"-I/tmp", "/tmp/[0]", "-I/tmp", true},
479 {"-I${SRCDIR}/dir", "/tmp/[0]", "-I/tmp/[0]/dir", false},
480 {"-I${SRCDIR}/dir", "/tmp/go go", "-I/tmp/go go/dir", true},
481 {"-I${SRCDIR}/dir dir", "/tmp/go", "-I/tmp/go/dir dir", true},
483 for _, test := range tests {
484 output, ok := expandSrcDir(test.input, test.srcdir)
485 if ok != test.result {
486 t.Errorf("Expected %t while %q expands to %q with SRCDIR=%q; got %t", test.result, test.input, output, test.srcdir, ok)
488 if output != test.expected {
489 t.Errorf("Expected %q while %q expands with SRCDIR=%q; got %q", test.expected, test.input, test.srcdir, output)
494 // Want to get a "cannot find package" error when directory for package does not exist.
495 // There should be valid partial information in the returned non-nil *Package.
496 func TestImportDirNotExist(t *testing.T) {
497 testenv.MustHaveGoBuild(t) // really must just have source
500 emptyDir := t.TempDir()
502 ctxt.GOPATH = emptyDir
510 {"Import(full, 0)", "go/build/doesnotexist", "", 0},
511 {"Import(local, 0)", "./doesnotexist", filepath.Join(ctxt.GOROOT, "src/go/build"), 0},
512 {"Import(full, FindOnly)", "go/build/doesnotexist", "", FindOnly},
513 {"Import(local, FindOnly)", "./doesnotexist", filepath.Join(ctxt.GOROOT, "src/go/build"), FindOnly},
516 defer os.Setenv("GO111MODULE", os.Getenv("GO111MODULE"))
518 for _, GO111MODULE := range []string{"off", "on"} {
519 t.Run("GO111MODULE="+GO111MODULE, func(t *testing.T) {
520 os.Setenv("GO111MODULE", GO111MODULE)
522 for _, test := range tests {
523 p, err := ctxt.Import(test.path, test.srcDir, test.mode)
525 errOk := (err != nil && strings.HasPrefix(err.Error(), "cannot find package"))
526 wantErr := `"cannot find package" error`
527 if test.srcDir == "" {
528 if err != nil && strings.Contains(err.Error(), "is not in GOROOT") {
531 wantErr = `"cannot find package" or "is not in GOROOT" error`
534 t.Errorf("%s got error: %q, want %s", test.label, err, wantErr)
536 // If an error occurs, build.Import is documented to return
537 // a non-nil *Package containing partial information.
539 t.Fatalf(`%s got nil p, want non-nil *Package`, test.label)
541 // Verify partial information in p.
542 if p.ImportPath != "go/build/doesnotexist" {
543 t.Errorf(`%s got p.ImportPath: %q, want "go/build/doesnotexist"`, test.label, p.ImportPath)
550 func TestImportVendor(t *testing.T) {
551 testenv.MustHaveGoBuild(t) // really must just have source
553 t.Setenv("GO111MODULE", "off")
556 wd, err := os.Getwd()
560 ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
561 p, err := ctxt.Import("c/d", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
563 t.Fatalf("cannot find vendored c/d from testdata src/a/b directory: %v", err)
565 want := "a/vendor/c/d"
566 if p.ImportPath != want {
567 t.Fatalf("Import succeeded but found %q, want %q", p.ImportPath, want)
571 func BenchmarkImportVendor(b *testing.B) {
572 testenv.MustHaveGoBuild(b) // really must just have source
574 b.Setenv("GO111MODULE", "off")
577 wd, err := os.Getwd()
581 ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
582 dir := filepath.Join(ctxt.GOPATH, "src/a/b")
584 for i := 0; i < b.N; i++ {
585 _, err := ctxt.Import("c/d", dir, 0)
587 b.Fatalf("cannot find vendored c/d from testdata src/a/b directory: %v", err)
592 func TestImportVendorFailure(t *testing.T) {
593 testenv.MustHaveGoBuild(t) // really must just have source
595 t.Setenv("GO111MODULE", "off")
598 wd, err := os.Getwd()
602 ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
603 p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
605 t.Fatalf("found made-up package x.com/y/z in %s", p.Dir)
609 if !strings.Contains(e, " (vendor tree)") {
610 t.Fatalf("error on failed import does not mention GOROOT/src/vendor directory:\n%s", e)
614 func TestImportVendorParentFailure(t *testing.T) {
615 testenv.MustHaveGoBuild(t) // really must just have source
617 t.Setenv("GO111MODULE", "off")
620 wd, err := os.Getwd()
624 ctxt.GOPATH = filepath.Join(wd, "testdata/withvendor")
625 // This import should fail because the vendor/c directory has no source code.
626 p, err := ctxt.Import("c", filepath.Join(ctxt.GOPATH, "src/a/b"), 0)
628 t.Fatalf("found empty parent in %s", p.Dir)
630 if p != nil && p.Dir != "" {
631 t.Fatalf("decided to use %s", p.Dir)
634 if !strings.Contains(e, " (vendor tree)") {
635 t.Fatalf("error on failed import does not mention GOROOT/src/vendor directory:\n%s", e)
639 // Check that a package is loaded in module mode if GO111MODULE=on, even when
640 // no go.mod file is present. It should fail to resolve packages outside std.
641 // Verifies golang.org/issue/34669.
642 func TestImportPackageOutsideModule(t *testing.T) {
643 testenv.MustHaveGoBuild(t)
645 // Disable module fetching for this test so that 'go list' fails quickly
646 // without trying to find the latest version of a module.
647 t.Setenv("GOPROXY", "off")
649 // Create a GOPATH in a temporary directory. We don't use testdata
650 // because it's in GOROOT, which interferes with the module heuristic.
651 gopath := t.TempDir()
652 if err := os.MkdirAll(filepath.Join(gopath, "src/example.com/p"), 0777); err != nil {
655 if err := os.WriteFile(filepath.Join(gopath, "src/example.com/p/p.go"), []byte("package p"), 0666); err != nil {
659 t.Setenv("GO111MODULE", "on")
660 t.Setenv("GOPATH", gopath)
663 ctxt.Dir = filepath.Join(gopath, "src/example.com/p")
665 want := "go.mod file not found in current directory or any parent directory"
666 if _, err := ctxt.Import("example.com/p", gopath, FindOnly); err == nil {
667 t.Fatal("importing package when no go.mod is present succeeded unexpectedly")
668 } else if errStr := err.Error(); !strings.Contains(errStr, want) {
669 t.Fatalf("error when importing package when no go.mod is present: got %q; want %q", errStr, want)
671 t.Logf(`ctxt.Import("example.com/p", _, FindOnly): %v`, err)
675 // TestIssue23594 prevents go/build from regressing and populating Package.Doc
676 // from comments in test files.
677 func TestIssue23594(t *testing.T) {
678 // Package testdata/doc contains regular and external test files
679 // with comments attached to their package declarations. The names of the files
680 // ensure that we see the comments from the test files first.
681 p, err := ImportDir("testdata/doc", 0)
683 t.Fatalf("could not import testdata: %v", err)
686 if p.Doc != "Correct" {
687 t.Fatalf("incorrectly set .Doc to %q", p.Doc)
691 // TestIssue56509 tests that go/build does not add non-go files to InvalidGoFiles
692 // when they have unparsable comments.
693 func TestIssue56509(t *testing.T) {
694 // The directory testdata/bads contains a .s file that has an unparsable
695 // comment. (go/build parses initial comments in non-go files looking for
696 // //go:build or //+go build comments).
697 p, err := ImportDir("testdata/bads", 0)
699 t.Fatalf("could not import testdata/bads: %v", err)
702 if len(p.InvalidGoFiles) != 0 {
703 t.Fatalf("incorrectly added non-go file to InvalidGoFiles")
707 // TestMissingImportErrorRepetition checks that when an unknown package is
708 // imported, the package path is only shown once in the error.
709 // Verifies golang.org/issue/34752.
710 func TestMissingImportErrorRepetition(t *testing.T) {
711 testenv.MustHaveGoBuild(t) // need 'go list' internally
713 if err := os.WriteFile(filepath.Join(tmp, "go.mod"), []byte("module m"), 0666); err != nil {
716 t.Setenv("GO111MODULE", "on")
717 t.Setenv("GOPROXY", "off")
718 t.Setenv("GONOPROXY", "none")
723 pkgPath := "example.com/hello"
724 _, err := ctxt.Import(pkgPath, tmp, FindOnly)
726 t.Fatal("unexpected success")
729 // Don't count the package path with a URL like https://...?go-get=1.
730 // See golang.org/issue/35986.
731 errStr := strings.ReplaceAll(err.Error(), "://"+pkgPath+"?go-get=1", "://...?go-get=1")
733 // Also don't count instances in suggested "go get" or similar commands
734 // (see https://golang.org/issue/41576). The suggested command typically
735 // follows a semicolon.
736 errStr, _, _ = strings.Cut(errStr, ";")
738 if n := strings.Count(errStr, pkgPath); n != 1 {
739 t.Fatalf("package path %q appears in error %d times; should appear once\nerror: %v", pkgPath, n, err)
743 // TestCgoImportsIgnored checks that imports in cgo files are not included
744 // in the imports list when cgo is disabled.
745 // Verifies golang.org/issue/35946.
746 func TestCgoImportsIgnored(t *testing.T) {
748 ctxt.CgoEnabled = false
749 p, err := ctxt.ImportDir("testdata/cgo_disabled", 0)
753 for _, path := range p.Imports {
754 if path == "should/be/ignored" {
755 t.Errorf("found import %q in ignored cgo file", path)
760 // Issue #52053. Check that if there is a file x_GOOS_GOARCH.go that both
761 // GOOS and GOARCH show up in the Package.AllTags field. We test both the
762 // case where the file matches and where the file does not match.
763 // The latter case used to fail, incorrectly omitting GOOS.
764 func TestAllTags(t *testing.T) {
768 p, err := ctxt.ImportDir("testdata/alltags", 0)
772 want := []string{"arm", "netbsd"}
773 if !reflect.DeepEqual(p.AllTags, want) {
774 t.Errorf("AllTags = %v, want %v", p.AllTags, want)
776 wantFiles := []string{"alltags.go", "x_netbsd_arm.go"}
777 if !reflect.DeepEqual(p.GoFiles, wantFiles) {
778 t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
781 ctxt.GOARCH = "amd64"
783 p, err = ctxt.ImportDir("testdata/alltags", 0)
787 if !reflect.DeepEqual(p.AllTags, want) {
788 t.Errorf("AllTags = %v, want %v", p.AllTags, want)
790 wantFiles = []string{"alltags.go"}
791 if !reflect.DeepEqual(p.GoFiles, wantFiles) {
792 t.Errorf("GoFiles = %v, want %v", p.GoFiles, wantFiles)
796 func TestAllTagsNonSourceFile(t *testing.T) {
797 p, err := Default.ImportDir("testdata/non_source_tags", 0)
801 if len(p.AllTags) > 0 {
802 t.Errorf("AllTags = %v, want empty", p.AllTags)
806 func TestDirectives(t *testing.T) {
807 p, err := ImportDir("testdata/directives", 0)
809 t.Fatalf("could not import testdata: %v", err)
812 check := func(name string, list []Directive, want string) {
813 if runtime.GOOS == "windows" {
814 want = strings.ReplaceAll(want, "testdata/directives/", `testdata\\directives\\`)
817 s := fmt.Sprintf("%q", list)
819 t.Errorf("%s = %s, want %s", name, s, want)
822 check("Directives", p.Directives,
823 `[{"//go:main1" "testdata/directives/a.go:1:1"} {"//go:plant" "testdata/directives/eve.go:1:1"}]`)
824 check("TestDirectives", p.TestDirectives,
825 `[{"//go:test1" "testdata/directives/a_test.go:1:1"} {"//go:test2" "testdata/directives/b_test.go:1:1"}]`)
826 check("XTestDirectives", p.XTestDirectives,
827 `[{"//go:xtest1" "testdata/directives/c_test.go:1:1"} {"//go:xtest2" "testdata/directives/d_test.go:1:1"} {"//go:xtest3" "testdata/directives/d_test.go:2:1"}]`)