Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2aaaec0

Browse files
committed
Add more pty diagnostics for terminal parsing
Signed-off-by: Spike Curtis <[email protected]>
1 parent 375c70d commit 2aaaec0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

testutil/pty.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ func ReadUntilString(ctx context.Context, t *testing.T, want string, r io.Reader
2121
// ReadUntil emulates a terminal and reads one byte at a time until the matcher
2222
// returns true or the context expires. If the matcher is nil, read until EOF.
2323
// The PTY must be sized to 80x80 or there could be unexpected results.
24-
func ReadUntil(ctx context.Context, t *testing.T, r io.Reader, matcher func(line string) bool) error {
24+
func ReadUntil(ctx context.Context, t *testing.T, r io.Reader, matcher func(line string) bool) (retErr error) {
2525
// output can contain virtual terminal sequences, so we need to parse these
2626
// to correctly interpret getting what we want.
27+
readBytes := make([]byte, 0)
2728
term := vt10x.New(vt10x.WithSize(80, 80))
2829
readErrs := make(chan error, 1)
2930
defer func() {
3031
// Dump the terminal contents since they can be helpful for debugging, but
31-
// skip empty lines since much of the terminal will usually be blank.
32+
// trim empty lines since much of the terminal will usually be blank.
3233
got := term.String()
33-
lines := strings.Split(got, "\n")
34-
for _, line := range lines {
35-
if strings.TrimSpace(line) != "" {
36-
t.Logf("got: %v", line)
37-
}
34+
trimmed := strings.Trim(got, "\n")
35+
t.Logf("Terminal contents:\n%s", trimmed)
36+
if retErr != nil {
37+
t.Logf("Bytes Read: %s", string(readBytes))
3838
}
3939
}()
4040
for {
@@ -48,6 +48,7 @@ func ReadUntil(ctx context.Context, t *testing.T, r io.Reader, matcher func(line
4848
if err != nil {
4949
return err
5050
}
51+
readBytes = append(readBytes, b...)
5152
_, err = term.Write(b)
5253
if err != nil {
5354
return err

0 commit comments

Comments
 (0)