github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/tpl/internal/go_templates/testenv/testenv_test.go (about) 1 // Copyright 2022 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 testenv_test 6 7 import ( 8 "os" 9 "path/filepath" 10 "runtime" 11 "testing" 12 13 "github.com/gohugoio/hugo/tpl/internal/go_templates/testenv" 14 ) 15 16 func _TestGoToolLocation(t *testing.T) { 17 testenv.MustHaveGoBuild(t) 18 19 var exeSuffix string 20 if runtime.GOOS == "windows" { 21 exeSuffix = ".exe" 22 } 23 24 // Tests are defined to run within their package source directory, 25 // and this package's source directory is $GOROOT/src/internal/testenv. 26 // The 'go' command is installed at $GOROOT/bin/go, so if the environment 27 // is correct then testenv.GoTool() should be identical to ../../../bin/go. 28 29 relWant := "../../../bin/go" + exeSuffix 30 absWant, err := filepath.Abs(relWant) 31 if err != nil { 32 t.Fatal(err) 33 } 34 35 wantInfo, err := os.Stat(absWant) 36 if err != nil { 37 t.Fatal(err) 38 } 39 t.Logf("found go tool at %q (%q)", relWant, absWant) 40 41 goTool, err := testenv.GoTool() 42 if err != nil { 43 t.Fatalf("testenv.GoTool(): %v", err) 44 } 45 t.Logf("testenv.GoTool() = %q", goTool) 46 47 gotInfo, err := os.Stat(goTool) 48 if err != nil { 49 t.Fatal(err) 50 } 51 if !os.SameFile(wantInfo, gotInfo) { 52 t.Fatalf("%q is not the same file as %q", absWant, goTool) 53 } 54 }