Skip to content

Commit 496deca

Browse files
Bryan C. MillsMaisem Ali
Bryan C. Mills
authored and
Maisem Ali
committed
ssh/test: skip TestValidTerminalMode on non-Bourne shells
Fixes golang/go#38037. Change-Id: Ide77dddc9f57b3f0318a419a1474e11215623b64 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/485175 Run-TryBot: Bryan Mills <[email protected]> Commit-Queue: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
1 parent 0c414fc commit 496deca

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

ssh/test/session_test.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"errors"
1515
"fmt"
1616
"io"
17+
"path/filepath"
18+
"regexp"
1719
"runtime"
1820
"strings"
1921
"testing"
@@ -255,15 +257,31 @@ func TestValidTerminalMode(t *testing.T) {
255257
t.Fatalf("session failed: %s", err)
256258
}
257259

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+
}
259263

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 {
262266
t.Fatalf("reading failed: %s", err)
263267
}
264268

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+
265283
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")
267285
}
268286
}
269287

0 commit comments

Comments
 (0)