Source file src/cmd/go/help_test.go

     1  // Copyright 2018 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 main_test
     6  
     7  import (
     8  	"bytes"
     9  	"os"
    10  	"testing"
    11  
    12  	"cmd/go/internal/help"
    13  	"cmd/go/internal/modload"
    14  )
    15  
    16  func TestDocsUpToDate(t *testing.T) {
    17  	t.Parallel()
    18  
    19  	if !modload.Enabled() {
    20  		t.Skipf("help.Help in GOPATH mode is configured by main.main")
    21  	}
    22  
    23  	buf := new(bytes.Buffer)
    24  	// Match the command in mkalldocs.sh that generates alldocs.go.
    25  	help.Help(buf, []string{"documentation"})
    26  	data, err := os.ReadFile("alldocs.go")
    27  	if err != nil {
    28  		t.Fatalf("error reading alldocs.go: %v", err)
    29  	}
    30  	if !bytes.Equal(data, buf.Bytes()) {
    31  		t.Errorf("alldocs.go is not up to date; run mkalldocs.sh to regenerate it")
    32  	}
    33  }
    34  

View as plain text