.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.6.9 / internal / hooks / licenses_test.go
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         "io/ioutil"
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 isn't
19         // supported for those versions.
20         testenv.NeedsGo1Point(t, 15)
21
22         if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
23                 t.Skip("generating licenses only works on Unixes")
24         }
25         tmp, err := ioutil.TempFile("", "")
26         if err != nil {
27                 t.Fatal(err)
28         }
29         tmp.Close()
30
31         if out, err := exec.Command("./gen-licenses.sh", tmp.Name()).CombinedOutput(); err != nil {
32                 t.Fatalf("generating licenses failed: %q, %v", out, err)
33         }
34
35         got, err := ioutil.ReadFile(tmp.Name())
36         if err != nil {
37                 t.Fatal(err)
38         }
39         want, err := ioutil.ReadFile("licenses.go")
40         if err != nil {
41                 t.Fatal(err)
42         }
43         if !bytes.Equal(got, want) {
44                 t.Error("combined license text needs updating. Run: `go generate ./internal/hooks` from the gopls module.")
45         }
46 }