mirror of
https://github.com/golang/go
synced 2024-11-18 16:04:44 -07:00
cmd/godoc: Add a basic regression test.
R=adg, bradfitz CC=golang-dev https://golang.org/cl/11419044
This commit is contained in:
parent
57f0a571b9
commit
3af65e49c2
70
cmd/godoc/godoc_test.go
Normal file
70
cmd/godoc/godoc_test.go
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var godocTests = []struct {
|
||||
args []string
|
||||
matches []string // regular expressions
|
||||
}{
|
||||
{
|
||||
[]string{"fmt"},
|
||||
[]string{
|
||||
`import "fmt"`,
|
||||
`Package fmt implements formatted I/O`,
|
||||
},
|
||||
},
|
||||
{
|
||||
[]string{"io", "WriteString"},
|
||||
[]string{
|
||||
`import "io"`,
|
||||
`func WriteString\(`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Basic regression test for godoc command-line tool.
|
||||
func TestGodoc(t *testing.T) {
|
||||
tmp, err := ioutil.TempDir("", "godoc-regtest-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
bin := filepath.Join(tmp, "godoc")
|
||||
cmd := exec.Command("go", "build", "-o", bin)
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("Building godoc: %v", err)
|
||||
}
|
||||
|
||||
for _, test := range godocTests {
|
||||
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
|
||||
}
|
||||
logged := false
|
||||
for _, pat := range test.matches {
|
||||
re := regexp.MustCompile(pat)
|
||||
if !re.Match(out) {
|
||||
if !logged {
|
||||
t.Logf("Output of running with args %#v:\n%s", test.args, out)
|
||||
logged = true
|
||||
}
|
||||
t.Errorf("Did not match /%v/", pat)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user