github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/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 "github.com/gohugoio/hugo/tpl/internal/go_templates/testenv" 9 //"internal/platform" 10 "os" 11 "path/filepath" 12 "runtime" 13 "strings" 14 "testing" 15 ) 16 17 func TestGoToolLocation(t *testing.T) { 18 testenv.MustHaveGoBuild(t) 19 20 var exeSuffix string 21 if runtime.GOOS == "windows" { 22 exeSuffix = ".exe" 23 } 24 25 // Tests are defined to run within their package source directory, 26 // and this package's source directory is $GOROOT/src/internal/testenv. 27 // The 'go' command is installed at $GOROOT/bin/go, so if the environment 28 // is correct then testenv.GoTool() should be identical to ../../../bin/go. 29 30 relWant := "../../../bin/go" + exeSuffix 31 absWant, err := filepath.Abs(relWant) 32 if err != nil { 33 t.Fatal(err) 34 } 35 36 wantInfo, err := os.Stat(absWant) 37 if err != nil { 38 t.Fatal(err) 39 } 40 t.Logf("found go tool at %q (%q)", relWant, absWant) 41 42 goTool, err := testenv.GoTool() 43 if err != nil { 44 t.Fatalf("testenv.GoTool(): %v", err) 45 } 46 t.Logf("testenv.GoTool() = %q", goTool) 47 48 gotInfo, err := os.Stat(goTool) 49 if err != nil { 50 t.Fatal(err) 51 } 52 if !os.SameFile(wantInfo, gotInfo) { 53 t.Fatalf("%q is not the same file as %q", absWant, goTool) 54 } 55 } 56 57 func TestHasGoBuild(t *testing.T) { 58 // Removed by Hugo. 59 } 60 61 func TestMustHaveExec(t *testing.T) { 62 hasExec := false 63 t.Run("MustHaveExec", func(t *testing.T) { 64 testenv.MustHaveExec(t) 65 t.Logf("MustHaveExec did not skip") 66 hasExec = true 67 }) 68 69 switch runtime.GOOS { 70 case "js", "wasip1": 71 if hasExec { 72 // js and wasip1 lack an “exec” syscall. 73 t.Errorf("expected MustHaveExec to skip on %v", runtime.GOOS) 74 } 75 case "ios": 76 if b := testenv.Builder(); strings.HasSuffix(b, "-corellium") && !hasExec { 77 // Most ios environments can't exec, but the corellium builder can. 78 t.Errorf("expected MustHaveExec not to skip on %v", b) 79 } 80 default: 81 if b := testenv.Builder(); b != "" && !hasExec { 82 t.Errorf("expected MustHaveExec not to skip on %v", b) 83 } 84 } 85 }