diff options
author | Joshua MacDonald <josh.macdonald@gmail.com> | 2015-11-21 23:36:51 -0800 |
---|---|---|
committer | Joshua MacDonald <josh.macdonald@gmail.com> | 2015-11-21 23:36:51 -0800 |
commit | ede482d8f3398262adcfb23095b6caad5872d8ba (patch) | |
tree | 89ea4cf3d61efbc82a9b342f3a9b6edc6edd8f69 /xdelta3/go/src/regtest.go | |
parent | 6116f8879faff1a8145f55d9f537c33f39931678 (diff) |
New TestGroup.Go method, improved error handling
Diffstat (limited to 'xdelta3/go/src/regtest.go')
-rw-r--r-- | xdelta3/go/src/regtest.go | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/xdelta3/go/src/regtest.go b/xdelta3/go/src/regtest.go index b028ed5..793c9fc 100644 --- a/xdelta3/go/src/regtest.go +++ b/xdelta3/go/src/regtest.go | |||
@@ -11,61 +11,63 @@ import ( | |||
11 | const ( | 11 | const ( |
12 | blocksize = 1<<16 | 12 | blocksize = 1<<16 |
13 | winsize = 1<<22 | 13 | winsize = 1<<22 |
14 | xdelta3 = "/volume/home/jmacd/src/xdelta-devel/xdelta3/xdelta3" | 14 | xdelta3 = "/Users/jmacd/src/xdelta-devel/xdelta3/xdelta3" |
15 | seed = 1422253499919909358 | 15 | seed = 1422253499919909358 |
16 | ) | 16 | ) |
17 | 17 | ||
18 | func smokeTest(r *xdelta.Runner, t *xdelta.TestGroup, p *xdelta.Program) { | 18 | func smokeTest(r *xdelta.Runner, p *xdelta.Program) { |
19 | t.Add(1) | 19 | t, g := xdelta.NewTestGroup(r) |
20 | target := "Hello world!" | 20 | target := "Hello world!" |
21 | source := "Hello world, nice to meet you!" | 21 | source := "Hello world, nice to meet you!" |
22 | 22 | ||
23 | enc, err := r.Exec(p, true, []string{"-evv"}) | 23 | enc, err := t.Exec(p, true, []string{"-evv"}) |
24 | if err != nil { | 24 | if err != nil { |
25 | t.Panic(err) | 25 | g.Panic(err) |
26 | } | 26 | } |
27 | encodeout := t.Drain(enc.Stdout, "encode.stdout") | 27 | encodeout := t.Drain(enc.Stdout, "encode.stdout") |
28 | t.Empty(enc.Stderr, "encode") | 28 | t.Empty(enc.Stderr, "encode") |
29 | 29 | ||
30 | t.Write("encode.stdin", enc.Stdin, []byte(target)) | 30 | if err := xdelta.TestWrite("encode.stdin", enc.Stdin, []byte(target)); err != nil { |
31 | t.Write("encode.srcin", enc.Srcin, []byte(source)) | 31 | g.Panic(err) |
32 | 32 | } | |
33 | if err := enc.Cmd.Wait(); err != nil { | 33 | if err := xdelta.TestWrite("encode.srcin", enc.Srcin, []byte(source)); err != nil { |
34 | t.Panic(err) | 34 | g.Panic(err) |
35 | } | 35 | } |
36 | 36 | ||
37 | dec, err := r.Exec(p, true, []string{"-dvv"}) | 37 | dec, err := t.Exec(p, true, []string{"-dvv"}) |
38 | if err != nil { | 38 | if err != nil { |
39 | t.Panic(err) | 39 | g.Panic(err) |
40 | } | 40 | } |
41 | 41 | ||
42 | decodeout := t.Drain(dec.Stdout, "decode.stdout") | 42 | decodeout := t.Drain(dec.Stdout, "decode.stdout") |
43 | t.Empty(dec.Stderr, "decode") | 43 | t.Empty(dec.Stderr, "decode") |
44 | 44 | ||
45 | t.Write("decode.stdin", dec.Stdin, <-encodeout) | 45 | if err := xdelta.TestWrite("decode.stdin", dec.Stdin, <-encodeout); err != nil { |
46 | t.Write("decode.srcin", dec.Srcin, []byte(source)) | 46 | g.Panic(err) |
47 | decoded := string(<-decodeout) | ||
48 | if err := dec.Cmd.Wait(); err != nil { | ||
49 | t.Panic(err) | ||
50 | } | 47 | } |
48 | if err := xdelta.TestWrite("decode.srcin", dec.Srcin, []byte(source)); err != nil { | ||
49 | g.Panic(err) | ||
50 | } | ||
51 | decoded := string(<-decodeout) | ||
51 | if decoded != target { | 52 | if decoded != target { |
52 | t.Panic(errors.New("It's not working!!!")) | 53 | g.Panic(errors.New("It's not working!!!")) |
53 | } | 54 | } |
54 | t.Done() | 55 | t.Wait(g) |
55 | fmt.Println("Smoketest pass") | 56 | fmt.Println("Smoketest pass") |
56 | } | 57 | } |
57 | 58 | ||
58 | func offsetTest(r *xdelta.Runner, t *xdelta.TestGroup, p *xdelta.Program, bufsize, offset, length int64) { | 59 | func offsetTest(r *xdelta.Runner, p *xdelta.Program, bufsize, offset, length int64) { |
59 | t.Add(1) | 60 | t, g := xdelta.NewTestGroup(r) |
60 | eargs := []string{"-e", "-0", fmt.Sprint("-B", bufsize), "-vv", fmt.Sprint("-W", winsize)} | 61 | eargs := []string{"-e", "-0", fmt.Sprint("-B", bufsize), "-vv", fmt.Sprint("-W", winsize)} |
61 | enc, err := r.Exec(p, true, eargs) | 62 | enc, err := t.Exec(p, true, eargs) |
62 | if err != nil { | 63 | if err != nil { |
63 | t.Panic(err) | 64 | g.Panic(err) |
64 | } | 65 | } |
66 | |||
65 | dargs := []string{"-d", fmt.Sprint("-B", bufsize), "-vv", fmt.Sprint("-W", winsize)} | 67 | dargs := []string{"-d", fmt.Sprint("-B", bufsize), "-vv", fmt.Sprint("-W", winsize)} |
66 | dec, err := r.Exec(p, true, dargs) | 68 | dec, err := t.Exec(p, true, dargs) |
67 | if err != nil { | 69 | if err != nil { |
68 | t.Panic(err) | 70 | g.Panic(err) |
69 | } | 71 | } |
70 | 72 | ||
71 | read, write := io.Pipe() | 73 | read, write := io.Pipe() |
@@ -81,13 +83,7 @@ func offsetTest(r *xdelta.Runner, t *xdelta.TestGroup, p *xdelta.Program, bufsiz | |||
81 | xdelta.WriteRstreams(t, seed, offset, length, enc.Srcin, enc.Stdin) | 83 | xdelta.WriteRstreams(t, seed, offset, length, enc.Srcin, enc.Stdin) |
82 | xdelta.WriteRstreams(t, seed, offset, length, dec.Srcin, write) | 84 | xdelta.WriteRstreams(t, seed, offset, length, dec.Srcin, write) |
83 | 85 | ||
84 | if err := enc.Cmd.Wait(); err != nil { | 86 | t.Wait(g) |
85 | t.Panic(err) | ||
86 | } | ||
87 | if err := dec.Cmd.Wait(); err != nil { | ||
88 | t.Panic(err) | ||
89 | } | ||
90 | t.Done() | ||
91 | } | 87 | } |
92 | 88 | ||
93 | func main() { | 89 | func main() { |
@@ -99,8 +95,8 @@ func main() { | |||
99 | 95 | ||
100 | prog := &xdelta.Program{xdelta3} | 96 | prog := &xdelta.Program{xdelta3} |
101 | 97 | ||
102 | smokeTest(r, xdelta.NewTestGroup(), prog) | 98 | smokeTest(r, prog) |
103 | offsetTest(r, xdelta.NewTestGroup(), prog, 4 << 20, 3 << 20, 5 << 20) | 99 | offsetTest(r, prog, 4 << 20, 3 << 20, 5 << 20) |
104 | 100 | ||
105 | //offsetTest(r, xdelta.NewTestGroup(), prog, 1 << 31, 1 << 32, 1 << 33) | 101 | //offsetTest(r, xdelta.NewTestGroup(), prog, 1 << 31, 1 << 32, 1 << 33) |
106 | } | 102 | } |