"Fossies" - the Fresh Open Source Software Archive

Member "xdelta3-3.1.0/go/src/xdelta/run.go" (28 Dec 2015, 1153 Bytes) of package /linux/misc/xdelta3-3.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package xdelta
    2 
    3 import (
    4     "fmt"
    5     "io"
    6     "io/ioutil"
    7     "os"
    8     "os/exec"
    9 )
   10 
   11 type Program struct {
   12     Path string
   13 }
   14 
   15 type Run struct {
   16     Cmd exec.Cmd
   17     Srcfile string
   18     Stdin io.WriteCloser
   19     Srcin io.WriteCloser
   20     Stdout io.ReadCloser
   21     Stderr io.ReadCloser
   22 }
   23 
   24 type Runner struct {
   25     Testdir string
   26 }
   27 
   28 func (r *Run) Wait() error {
   29     return r.Cmd.Wait()
   30 }
   31 
   32 func NewRunner() (*Runner, error) {
   33     if dir, err := ioutil.TempDir(tmpDir, "xrt"); err != nil {
   34         return nil, err
   35     } else {
   36         return &Runner{dir}, nil
   37     }
   38 }
   39 
   40 func (r *Runner) newTestGroup(name string) (*TestGroup) {
   41     tg := &TestGroup{Runner: r}
   42     tg.WaitGroup.Add(1)
   43     g0 := &Goroutine{tg, name, false}
   44     tg.running = append(tg.running, g0)
   45     tg.main = g0
   46     return tg
   47 }
   48 
   49 func (r *Runner) Cleanup() {
   50     os.RemoveAll(r.Testdir)
   51 }
   52 
   53 func (r *Runner) RunTest(name string, f func (t *TestGroup)) {
   54     t := r.newTestGroup(name)
   55     c := make(chan interface{})
   56     go func() {
   57         defer func() {
   58             rec := recover()
   59             c <- rec
   60         }()
   61         fmt.Println("Testing", name, "...")
   62         f(t)
   63         c <- nil
   64     }()
   65     rec := <- c
   66     if t.errors == nil && rec == nil {
   67         fmt.Println("Success:", name)
   68     } else {
   69         fmt.Println("FAILED:", name, t.errors, rec)
   70     }
   71 }