| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | "os/exec" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | func TestWindowsTerminalInputResizeAndExit(t *testing.T) { |
| 12 | cmd := exec.Command("powershell.exe", "-NoProfile", "-NonInteractive", "-Command", "$v=[Console]::ReadLine(); [Console]::WriteLine('received:'+$v)") |
| 13 | terminal, err := startTerminal(cmd, 80, 24) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | t.Cleanup(func() { _ = terminal.Kill(); _ = terminal.Close() }) |
| 18 | if err = terminal.Resize(120, 40); err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | output := make(chan string, 1) |
| 22 | go func() { b, _ := io.ReadAll(terminal); output <- string(b) }() |
| 23 | if _, err = io.WriteString(terminal, "cage-terminal\r"); err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | select { |
| 27 | case text := <-output: |
| 28 | if !strings.Contains(text, "received:cage-terminal") { |
| 29 | t.Fatalf("ConPTY input did not reach child: %q", text) |
| 30 | } |
| 31 | if err := terminal.Wait(); err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | case <-time.After(15 * time.Second): |
| 35 | t.Fatal("ConPTY did not drain and close after child exit") |
| 36 | } |
| 37 | } |