exampleCommand returns an exec.Cmd to run an example.
(t *testing.T, prog string, arg ...string)
| 109 | |
| 110 | // exampleCommand returns an exec.Cmd to run an example. |
| 111 | func exampleCommand(t *testing.T, prog string, arg ...string) (cmd *exec.Cmd) { |
| 112 | args := []string{} |
| 113 | if *debug { |
| 114 | args = append(args, "-debug=true") |
| 115 | } |
| 116 | args = append(args, arg...) |
| 117 | prog, err := filepath.Abs(path.Join(*dir, prog)) |
| 118 | fatalIf(t, err) |
| 119 | if _, err := os.Stat(prog); err == nil { |
| 120 | cmd = exec.Command(prog, args...) |
| 121 | } else if _, err := os.Stat(prog + ".go"); err == nil { |
| 122 | args = append([]string{"run", prog + ".go"}, args...) |
| 123 | cmd = exec.Command("go", args...) |
| 124 | } else { |
| 125 | t.Fatalf("Cannot find binary or source for %s", prog) |
| 126 | } |
| 127 | cmd.Stderr = os.Stderr |
| 128 | return cmd |
| 129 | } |
| 130 | |
| 131 | // Run an example Go program, return the combined output as a string. |
| 132 | func runExample(t *testing.T, prog string, arg ...string) (string, error) { |
no test coverage detected