File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ func TestAgent(t *testing.T) {
76
76
session .Stdin = ptty .Input ()
77
77
err = session .Start (command )
78
78
require .NoError (t , err )
79
+ caret := "$"
80
+ if runtime .GOOS == "windows" {
81
+ caret = ">"
82
+ }
83
+ ptty .ExpectMatch (caret )
79
84
ptty .WriteLine ("echo test" )
80
85
ptty .ExpectMatch ("test" )
81
86
ptty .WriteLine ("exit" )
Original file line number Diff line number Diff line change @@ -3,13 +3,15 @@ package ptytest
3
3
import (
4
4
"bufio"
5
5
"bytes"
6
+ "context"
6
7
"io"
7
8
"os"
8
9
"os/exec"
9
10
"regexp"
10
11
"runtime"
11
12
"strings"
12
13
"testing"
14
+ "time"
13
15
"unicode/utf8"
14
16
15
17
"github.com/stretchr/testify/require"
@@ -76,6 +78,19 @@ func (p *PTY) ExpectMatch(str string) string {
76
78
var buffer bytes.Buffer
77
79
multiWriter := io .MultiWriter (& buffer , p .outputWriter )
78
80
runeWriter := bufio .NewWriterSize (multiWriter , utf8 .UTFMax )
81
+ complete , cancelFunc := context .WithCancel (context .Background ())
82
+ defer cancelFunc ()
83
+ go func () {
84
+ timer := time .NewTimer (10 * time .Second )
85
+ defer timer .Stop ()
86
+ select {
87
+ case <- complete .Done ():
88
+ return
89
+ case <- timer .C :
90
+ }
91
+ _ = p .Close ()
92
+ p .t .Errorf ("match exceeded deadline: wanted %q; got %q" , str , buffer .String ())
93
+ }()
79
94
for {
80
95
var r rune
81
96
r , _ , err := p .runeReader .ReadRune ()
You can’t perform that action at this time.
0 commit comments