Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame^] | 1 | package rt_test |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "syscall" |
| 6 | "testing" |
| 7 | |
| 8 | "veyron/lib/testutil/blackbox" |
| 9 | "veyron/runtimes/google/rt" |
| 10 | ) |
| 11 | |
| 12 | func init() { |
| 13 | blackbox.CommandTable["withRuntime"] = withRuntime |
| 14 | blackbox.CommandTable["withoutRuntime"] = withoutRuntime |
| 15 | } |
| 16 | |
| 17 | func simpleEchoProgram() { |
| 18 | fmt.Println("ready") |
| 19 | fmt.Println(blackbox.ReadLineFromStdin()) |
| 20 | blackbox.WaitForEOFOnStdin() |
| 21 | } |
| 22 | |
| 23 | func withRuntime([]string) { |
| 24 | rt.Init() |
| 25 | simpleEchoProgram() |
| 26 | } |
| 27 | |
| 28 | func withoutRuntime([]string) { |
| 29 | simpleEchoProgram() |
| 30 | } |
| 31 | |
| 32 | func TestWithRuntime(t *testing.T) { |
| 33 | c := blackbox.HelperCommand(t, "withRuntime") |
| 34 | defer c.Cleanup() |
| 35 | c.Cmd.Start() |
| 36 | c.Expect("ready") |
| 37 | syscall.Kill(c.Cmd.Process.Pid, syscall.SIGHUP) |
| 38 | c.WriteLine("foo") |
| 39 | c.Expect("foo") |
| 40 | c.CloseStdin() |
| 41 | c.ExpectEOFAndWait() |
| 42 | } |
| 43 | |
| 44 | func TestWithoutRuntime(t *testing.T) { |
| 45 | c := blackbox.HelperCommand(t, "withoutRuntime") |
| 46 | defer c.Cleanup() |
| 47 | c.Cmd.Start() |
| 48 | c.Expect("ready") |
| 49 | syscall.Kill(c.Cmd.Process.Pid, syscall.SIGHUP) |
| 50 | c.ExpectEOFAndWaitForExitCode(fmt.Errorf("exit status 2")) |
| 51 | } |