1
0
mirror of https://github.com/golang/go synced 2024-11-21 18:34:44 -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) {
defer close(c)
f, err := os.Open("testdata/webkit/" + filename)
if err != nil {
c <- pipeErr(err)
@ -125,17 +126,27 @@ func dump(n *Node) (string, error) {
}
func TestParser(t *testing.T) {
// TODO(nigeltao): Process all the .dat files, not just the first one.
filenames := []string{
"tests1.dat",
testFiles := []struct {
filename string
// 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)
go readDat(filename, rc)
// TODO(nigeltao): Process all test cases, not just a subset.
for i := 0; i < 87; i++ {
go readDat(tf.filename, rc)
for i := 0; i != tf.n; i++ {
// Parse the #data section.
b, err := ioutil.ReadAll(<-rc)
dataReader := <-rc
if dataReader == nil {
break
}
b, err := ioutil.ReadAll(dataReader)
if err != nil {
t.Fatal(err)
}
@ -158,7 +169,7 @@ func TestParser(t *testing.T) {
t.Fatal(err)
}
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
}
if renderTestBlacklist[text] {
@ -178,10 +189,16 @@ func TestParser(t *testing.T) {
t.Fatal(err)
}
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
}
}
// Drain any untested cases for the test file.
for r := range rc {
if _, err := ioutil.ReadAll(r); err != nil {
t.Fatal(err)
}
}
}
}