(args ...string)
| 48 | |
| 49 | } |
| 50 | func (e *env) Run(args ...string) (out, err []byte, exitCode int) { |
| 51 | outbuf := new(bytes.Buffer) |
| 52 | errbuf := new(bytes.Buffer) |
| 53 | os.Args = append(os.Args[:1], args...) |
| 54 | cmdmain.Stdout, cmdmain.Stderr = outbuf, errbuf |
| 55 | if e.stdin == nil { |
| 56 | cmdmain.Stdin = strings.NewReader("") |
| 57 | } else { |
| 58 | cmdmain.Stdin = e.stdin |
| 59 | } |
| 60 | exitc := make(chan int, 1) |
| 61 | cmdmain.Exit = func(code int) { |
| 62 | exitc <- code |
| 63 | runtime.Goexit() |
| 64 | } |
| 65 | go func() { |
| 66 | cmdmain.Main() |
| 67 | cmdmain.Exit(0) |
| 68 | }() |
| 69 | select { |
| 70 | case exitCode = <-exitc: |
| 71 | case <-time.After(e.timeout()): |
| 72 | panic("timeout running command") |
| 73 | } |
| 74 | out = outbuf.Bytes() |
| 75 | err = errbuf.Bytes() |
| 76 | return |
| 77 | } |
| 78 | |
| 79 | // TestUsageOnNoargs tests that we output a usage message when given no args, and return |
| 80 | // with a non-zero exit status. |
no test coverage detected