1
0
mirror of https://github.com/golang/go synced 2024-11-25 22:07:58 -07:00

html: be able to test more than one testdata file.

R=andybalholm
CC=golang-dev
https://golang.org/cl/5351041
This commit is contained in:
Nigel Tao 2011-11-07 09:38:40 +11:00
parent ea9e93862d
commit bbd173fc3d

View File

@ -23,6 +23,7 @@ func pipeErr(err error) io.Reader {
} }
func readDat(filename string, c chan io.Reader) { func readDat(filename string, c chan io.Reader) {
defer close(c)
f, err := os.Open("testdata/webkit/" + filename) f, err := os.Open("testdata/webkit/" + filename)
if err != nil { if err != nil {
c <- pipeErr(err) c <- pipeErr(err)
@ -125,17 +126,27 @@ func dump(n *Node) (string, error) {
} }
func TestParser(t *testing.T) { func TestParser(t *testing.T) {
// TODO(nigeltao): Process all the .dat files, not just the first one. testFiles := []struct {
filenames := []string{ filename string
"tests1.dat", // n is the number of test cases to run from that file.
// -1 means all test cases.
n int
}{
// TODO(nigeltao): Process all the test cases from all the .dat files.
{"tests1.dat", 87},
{"tests2.dat", 0},
{"tests3.dat", 0},
} }
for _, filename := range filenames { for _, tf := range testFiles {
rc := make(chan io.Reader) rc := make(chan io.Reader)
go readDat(filename, rc) go readDat(tf.filename, rc)
// TODO(nigeltao): Process all test cases, not just a subset. for i := 0; i != tf.n; i++ {
for i := 0; i < 87; i++ {
// Parse the #data section. // Parse the #data section.
b, err := ioutil.ReadAll(<-rc) dataReader := <-rc
if dataReader == nil {
break
}
b, err := ioutil.ReadAll(dataReader)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -158,7 +169,7 @@ func TestParser(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if want := string(b); got != want { if want := string(b); got != want {
t.Errorf("%s test #%d %q, got vs want:\n----\n%s----\n%s----", filename, i, text, got, want) t.Errorf("%s test #%d %q, got vs want:\n----\n%s----\n%s----", tf.filename, i, text, got, want)
continue continue
} }
if renderTestBlacklist[text] { if renderTestBlacklist[text] {
@ -178,10 +189,16 @@ func TestParser(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if got != got1 { if got != got1 {
t.Errorf("%s test #%d %q, got vs got1:\n----\n%s----\n%s----", filename, i, text, got, got1) t.Errorf("%s test #%d %q, got vs got1:\n----\n%s----\n%s----", tf.filename, i, text, got, got1)
continue continue
} }
} }
// Drain any untested cases for the test file.
for r := range rc {
if _, err := ioutil.ReadAll(r); err != nil {
t.Fatal(err)
}
}
} }
} }