@@ -14,6 +14,8 @@ import (
14
14
"errors"
15
15
"fmt"
16
16
"io"
17
+ "path/filepath"
18
+ "regexp"
17
19
"runtime"
18
20
"strings"
19
21
"testing"
@@ -255,15 +257,31 @@ func TestValidTerminalMode(t *testing.T) {
255
257
t .Fatalf ("session failed: %s" , err )
256
258
}
257
259
258
- stdin .Write ([]byte ("stty -a && exit\n " ))
260
+ if _ , err := io .WriteString (stdin , "echo SHELL $SHELL && stty -a && exit\n " ); err != nil {
261
+ t .Fatal (err )
262
+ }
259
263
260
- var buf bytes. Buffer
261
- if _ , err := io .Copy (& buf , stdout ); err != nil {
264
+ buf := new (strings. Builder )
265
+ if _ , err := io .Copy (buf , stdout ); err != nil {
262
266
t .Fatalf ("reading failed: %s" , err )
263
267
}
264
268
269
+ if testing .Verbose () {
270
+ t .Logf ("echo SHELL $SHELL && stty -a && exit:\n %s" , buf )
271
+ }
272
+
273
+ shellLine := regexp .MustCompile ("(?m)^SHELL (.*)$" ).FindStringSubmatch (buf .String ())
274
+ if len (shellLine ) != 2 {
275
+ t .Fatalf ("missing output from echo SHELL $SHELL" )
276
+ }
277
+ switch shell := filepath .Base (strings .TrimSpace (shellLine [1 ])); shell {
278
+ case "sh" , "bash" :
279
+ default :
280
+ t .Skipf ("skipping test on non-Bourne shell %q" , shell )
281
+ }
282
+
265
283
if sttyOutput := buf .String (); ! strings .Contains (sttyOutput , "-echo " ) {
266
- t .Fatalf ("terminal mode failure: expected -echo in stty output, got %s" , sttyOutput )
284
+ t .Fatal ("terminal mode failure: expected -echo in stty output" )
267
285
}
268
286
}
269
287
0 commit comments