golang.org/x/build@v0.0.0-20240506185731-218518f32b70/cmd/updatestd/updatestd_test.go (about) 1 // Copyright 2020 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 main 6 7 import ( 8 "runtime" 9 "strings" 10 "testing" 11 ) 12 13 func TestBuildList(t *testing.T) { 14 if testing.Short() { 15 t.Skip("skipping in short mode because buildList may need to use the internet") 16 } 17 18 goCmd = "go" // for testing, using the go command in PATH 19 gowork := strings.TrimSpace(string(runner{"."}.runOut("go", "env", "GOWORK"))) 20 if gowork != "" && gowork != "off" { 21 t.Skipf("must be run outside a workspace. GOWORK=%q", gowork) 22 } 23 // This test is in the golang.org/x/build module. 24 // Check that buildList(".") returns sensible results. 25 main, deps := buildList(".") 26 if want := (module{ 27 Path: "golang.org/x/build", 28 Main: true, 29 Indirect: false, 30 }); main != want { 31 t.Errorf("got main = %+v, want %+v", main, want) 32 } 33 for i, m := range deps { 34 if m.Path == "" { 35 t.Errorf("deps[%d]: module path is empty", i) 36 } 37 if m.Main { 38 t.Errorf("deps[%d]: unexpectedly a main module", i) 39 } 40 } 41 if len(deps) < 10 { 42 t.Errorf("buildList returned %d (less than 10) non-main modules in build list of x/build; "+ 43 "either buildList is broken or TestBuildList needs to be updated (that'll be the day)", 44 len(deps)) 45 } 46 } 47 48 func TestGOROOTVersion(t *testing.T) { 49 // This test requires Go 1.14 or higher to run. 50 // Verify gorootVersion(runtime.GOROOT()) returns a fitting version. 51 v, err := gorootVersion(runtime.GOROOT()) 52 if err != nil { 53 t.Fatal("gorootVersion returned non-nil error:", err) 54 } 55 if v < 14 { 56 t.Errorf("gorootVersion returned unexpectedly low version %d", v) 57 } 58 }