golang.org/x/tools/gopls@v0.15.3/internal/hooks/licenses_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 hooks 6 7 import ( 8 "bytes" 9 "os" 10 "os/exec" 11 "runtime" 12 "testing" 13 14 "golang.org/x/tools/internal/testenv" 15 ) 16 17 func TestLicenses(t *testing.T) { 18 // License text differs for older Go versions because staticcheck or gofumpt 19 // isn't supported for those versions, and this fails for unknown, unrelated 20 // reasons on Kokoro legacy CI. 21 testenv.NeedsGo1Point(t, 21) 22 23 if runtime.GOOS != "linux" && runtime.GOOS != "darwin" { 24 t.Skip("generating licenses only works on Unixes") 25 } 26 tmp, err := os.CreateTemp("", "") 27 if err != nil { 28 t.Fatal(err) 29 } 30 tmp.Close() 31 32 if out, err := exec.Command("./gen-licenses.sh", tmp.Name()).CombinedOutput(); err != nil { 33 t.Fatalf("generating licenses failed: %q, %v", out, err) 34 } 35 36 got, err := os.ReadFile(tmp.Name()) 37 if err != nil { 38 t.Fatal(err) 39 } 40 want, err := os.ReadFile("licenses.go") 41 if err != nil { 42 t.Fatal(err) 43 } 44 if !bytes.Equal(got, want) { 45 t.Error("combined license text needs updating. Run: `go generate ./internal/hooks` from the gopls module.") 46 } 47 }