golang.org/x/tools/gopls@v0.15.3/internal/protocol/command/interface_test.go (about)

     1  // Copyright 2021 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 command_test
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  
    11  	"github.com/google/go-cmp/cmp"
    12  	"golang.org/x/tools/gopls/internal/protocol/command/gen"
    13  	"golang.org/x/tools/internal/testenv"
    14  )
    15  
    16  func TestGenerated(t *testing.T) {
    17  	testenv.NeedsGoPackages(t)
    18  	testenv.NeedsLocalXTools(t)
    19  
    20  	onDisk, err := os.ReadFile("command_gen.go")
    21  	if err != nil {
    22  		t.Fatal(err)
    23  	}
    24  
    25  	generated, err := gen.Generate()
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	if diff := cmp.Diff(string(generated), string(onDisk)); diff != "" {
    30  		t.Errorf("command_gen.go is stale -- regenerate (-generated +on disk)\n%s", diff)
    31  	}
    32  }