func TestCLI(t *testing.T) {
	bin, cleanup := buildGodoc(t)
	defer cleanup()
	condStr := func(cond bool, s string) string {
		if !cond {
			return ""
		}
		return s
	}
	tests := []struct {
		args      []string
		matches   []string  
		dontmatch []string  
	}{
		{
			args: []string{"fmt"},
			matches: []string{
				`import "fmt"`,
				`Package fmt implements formatted I/O`,
			},
		},
		{
			args: []string{"io", "WriteString"},
			matches: []string{
				`func WriteString\(`,
				`WriteString writes the contents of the string s to w`,
			},
		},
		{
			args: []string{"nonexistingpkg"},
			matches: []string{
				`cannot find package` +
					condStr(!isGo19,
						`|no such file or directory|does not exist|cannot find the file|(?:' does not e)`),
			},
		},
		{
			args: []string{"fmt", "NonexistentSymbol"},
			matches: []string{
				`No match found\.`,
			},
		},
		{
			args: []string{"-src", "syscall", "Open"},
			matches: []string{
				`func Open\(`,
			},
			dontmatch: []string{
				`No match found\.`,
			},
		},
	}
	for _, test := range tests {
		cmd := exec.Command(bin, test.args...)
		cmd.Args[0] = "godoc"
		out, err := cmd.CombinedOutput()
		if err != nil {
			t.Errorf("Running with args %#v: %v", test.args, err)
			continue
		}
		for _, pat := range test.matches {
			re := regexp.MustCompile(pat)
			if !re.Match(out) {
				t.Errorf("godoc %v =\n%s\nwanted /%v/", strings.Join(test.args, " "), out, pat)
			}
		}
		for _, pat := range test.dontmatch {
			re := regexp.MustCompile(pat)
			if re.Match(out) {
				t.Errorf("godoc %v =\n%s\ndid not want /%v/", strings.Join(test.args, " "), out, pat)
			}
		}
	}
}
Basic regression test for godoc command-line tool.
package main_test
import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"net"
	"net/http"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"runtime"
	"strings"
	"testing"
	"time"
)
func buildGodoc(t *testing.T) (bin string, cleanup func()) {
	if runtime.GOARCH == "arm" {
		t.Skip("skipping test on arm platforms; too slow")
	}
	tmp, err := ioutil.TempDir("", "godoc-regtest-")
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		if cleanup == nil {  
			os.RemoveAll(tmp)
		}
	}()
	bin = filepath.Join(tmp, "godoc")
	if runtime.GOOS == "windows" {
		bin += ".exe"
	}
	cmd := exec.Command("go", "build", "-o", bin)
	if err := cmd.Run(); err != nil {
		t.Fatalf("Building godoc: %v", err)
	}
	return bin, func() { os.RemoveAll(tmp) }
}
var isGo19 bool  