| 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_testscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib_test`/ |
| 6 | |
| 7 | import ( |
| 8 | "iterscip-go gomod github.com/golang/go/src go1.25.0 iter/" |
| 9 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 10 | "slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/" |
| 11 | "sortscip-go gomod github.com/golang/go/src go1.25.0 sort/" |
| 12 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 13 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 14 | |
| 15 | "github.com/google/go-cmp/cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/" |
| 16 | "golang.org/x/tools/internal/stdlibscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/" |
| 17 | ) |
| 18 | |
| 19 | func TestImportsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib_test`/TestImports().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { testDepsFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib_test`/testDepsFunc().(t, "testdata/nethttp.imports", stdlibscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/.Importsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/Imports().) } |
| 20 | func TestDepsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib_test`/TestDeps().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { testDepsFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib_test`/testDepsFunc().(t, "testdata/nethttp.deps", stdlibscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/.Dependenciesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/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 testDepsFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib_test`/testDepsFunc().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, filename string, depsFunc func(pkgs ...string) iterscip-go gomod github.com/golang/go/src go1.25.0 iter/.Seqscip-go gomod github.com/golang/go/src go1.25.0 iter/Seq#[string]) { |
| 25 | data, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().(filename) |
| 26 | if err != nil { |
| 27 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 28 | } |
| 29 | want := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(string(data)), "\n") |
| 30 | got := slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.Collectscip-go gomod github.com/golang/go/src go1.25.0 slices/Collect().(depsFunc("net/http")) |
| 31 | sortscip-go gomod github.com/golang/go/src go1.25.0 sort/.Stringsscip-go gomod github.com/golang/go/src go1.25.0 sort/Strings().(want) |
| 32 | sortscip-go gomod github.com/golang/go/src go1.25.0 sort/.Stringsscip-go gomod github.com/golang/go/src go1.25.0 sort/Strings().(got) |
| 33 | if diff := cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(got, want); diff != "" { |
| 34 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Deps mismatch (-want +got):\n%s", diff) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func TestIsBootstrapPackagescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib_test`/TestIsBootstrapPackage().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 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 := stdlibscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/.IsBootstrapPackagescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/IsBootstrapPackage().(pkg) |
| 47 | if got != want { |
| 48 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("IsBootstrapPackage(%q) = %t", pkg, got) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | if stdlibscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/.BootstrapVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/BootstrapVersion. < 24 { |
| 53 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("BootstrapVersion = %v, want at least go1.24", stdlibscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/.BootstrapVersionscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/stdlib`/BootstrapVersion.) |
| 54 | } |
| 55 | } |