@@ -21,20 +21,20 @@ func ReadUntilString(ctx context.Context, t *testing.T, want string, r io.Reader
21
21
// ReadUntil emulates a terminal and reads one byte at a time until the matcher
22
22
// returns true or the context expires. If the matcher is nil, read until EOF.
23
23
// 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 ) {
25
25
// output can contain virtual terminal sequences, so we need to parse these
26
26
// to correctly interpret getting what we want.
27
+ readBytes := make ([]byte , 0 )
27
28
term := vt10x .New (vt10x .WithSize (80 , 80 ))
28
29
readErrs := make (chan error , 1 )
29
30
defer func () {
30
31
// 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.
32
33
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 ))
38
38
}
39
39
}()
40
40
for {
@@ -48,6 +48,7 @@ func ReadUntil(ctx context.Context, t *testing.T, r io.Reader, matcher func(line
48
48
if err != nil {
49
49
return err
50
50
}
51
+ readBytes = append (readBytes , b ... )
51
52
_ , err = term .Write (b )
52
53
if err != nil {
53
54
return err
0 commit comments