|
1 | 1 | package iostreams |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bufio" |
4 | 5 | "errors" |
5 | 6 | "fmt" |
6 | 7 | "io" |
| 8 | + "os" |
7 | 9 | "testing" |
8 | 10 | ) |
9 | 11 |
|
@@ -89,3 +91,40 @@ func TestStopAlternateScreenBuffer(t *testing.T) { |
89 | 91 | t.Errorf("after IOStreams.StopAlternateScreenBuffer() got %q, want %q", got, want) |
90 | 92 | } |
91 | 93 | } |
| 94 | + |
| 95 | +func TestIOStreams_pager(t *testing.T) { |
| 96 | + t.Skip("TODO: fix this test in race detection mode") |
| 97 | + ios, _, stdout, _ := Test() |
| 98 | + ios.SetStdoutTTY(true) |
| 99 | + ios.SetPager(fmt.Sprintf("%s -test.run=TestHelperProcess --", os.Args[0])) |
| 100 | + t.Setenv("GH_WANT_HELPER_PROCESS", "1") |
| 101 | + if err := ios.StartPager(); err != nil { |
| 102 | + t.Fatal(err) |
| 103 | + } |
| 104 | + if _, err := fmt.Fprintln(ios.Out, "line1"); err != nil { |
| 105 | + t.Errorf("error writing line 1: %v", err) |
| 106 | + } |
| 107 | + if _, err := fmt.Fprintln(ios.Out, "line2"); err != nil { |
| 108 | + t.Errorf("error writing line 2: %v", err) |
| 109 | + } |
| 110 | + ios.StopPager() |
| 111 | + wants := "pager: line1\npager: line2\n" |
| 112 | + if got := stdout.String(); got != wants { |
| 113 | + t.Errorf("expected %q, got %q", wants, got) |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +func TestHelperProcess(t *testing.T) { |
| 118 | + if os.Getenv("GH_WANT_HELPER_PROCESS") != "1" { |
| 119 | + return |
| 120 | + } |
| 121 | + scanner := bufio.NewScanner(os.Stdin) |
| 122 | + for scanner.Scan() { |
| 123 | + fmt.Printf("pager: %s\n", scanner.Text()) |
| 124 | + } |
| 125 | + if err := scanner.Err(); err != nil { |
| 126 | + fmt.Fprintf(os.Stderr, "error reading stdin: %v", err) |
| 127 | + os.Exit(1) |
| 128 | + } |
| 129 | + os.Exit(0) |
| 130 | +} |
0 commit comments