Debian Codegraph @

internal/stdlib/deps_test.go

raw symbols SCIP
1 // Copyright 2025 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 package stdlib_test
6
7 import (
8 "iter"
9 "os"
10 "slices"
11 "sort"
12 "strings"
13 "testing"
14
15 "github.com/google/go-cmp/cmp"
16 "golang.org/x/tools/internal/stdlib"
17 )
18
19 func TestImports(t *testing.T) { testDepsFunc(t, "testdata/nethttp.imports", stdlib.Imports) }
20 func TestDeps(t *testing.T) { testDepsFunc(t, "testdata/nethttp.deps", stdlib.Dependencies) }
21
22 // testDepsFunc checks that the specified dependency function applied
23 // to net/http returns the set of dependencies in the named file.
24 func testDepsFunc(t *testing.T, filename string, depsFunc func(pkgs ...string) iter.Seq[string]) {
25 data, err := os.ReadFile(filename)
26 if err != nil {
27 t.Fatal(err)
28 }
29 want := strings.Split(strings.TrimSpace(string(data)), "\n")
30 got := slices.Collect(depsFunc("net/http"))
31 sort.Strings(want)
32 sort.Strings(got)
33 if diff := cmp.Diff(got, want); diff != "" {
34 t.Fatalf("Deps mismatch (-want +got):\n%s", diff)
35 }
36 }
37
38 func TestIsBootstrapPackage(t *testing.T) {
39 for pkg, want := range map[string]bool{
40 "cmd/internal/obj/arm64": true,
41 "sort": true,
42 "encoding/json": false,
43 "golang.org/x/tools/internal/stdlib": false,
44 "": false,
45 } {
46 got := stdlib.IsBootstrapPackage(pkg)
47 if got != want {
48 t.Errorf("IsBootstrapPackage(%q) = %t", pkg, got)
49 }
50 }
51
52 if stdlib.BootstrapVersion < 24 {
53 t.Errorf("BootstrapVersion = %v, want at least go1.24", stdlib.BootstrapVersion)
54 }
55 }