From 7d6d3f5d4adbee52131e89d4465c8cdf88d80aad Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Mon, 17 Apr 2023 12:30:28 -0400 Subject: [PATCH] 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 Commit-Queue: Bryan Mills Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Roland Shoemaker --- ssh/test/session_test.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/ssh/test/session_test.go b/ssh/test/session_test.go index d66509b2d3..f88c3b7abc 100644 --- a/ssh/test/session_test.go +++ b/ssh/test/session_test.go @@ -14,6 +14,8 @@ import ( "errors" "fmt" "io" + "path/filepath" + "regexp" "runtime" "strings" "testing" @@ -255,15 +257,31 @@ func TestValidTerminalMode(t *testing.T) { t.Fatalf("session failed: %s", err) } - stdin.Write([]byte("stty -a && exit\n")) + if _, err := io.WriteString(stdin, "echo SHELL $SHELL && stty -a && exit\n"); err != nil { + t.Fatal(err) + } - var buf bytes.Buffer - if _, err := io.Copy(&buf, stdout); err != nil { + buf := new(strings.Builder) + if _, err := io.Copy(buf, stdout); err != nil { t.Fatalf("reading failed: %s", err) } + if testing.Verbose() { + t.Logf("echo SHELL $SHELL && stty -a && exit:\n%s", buf) + } + + shellLine := regexp.MustCompile("(?m)^SHELL (.*)$").FindStringSubmatch(buf.String()) + if len(shellLine) != 2 { + t.Fatalf("missing output from echo SHELL $SHELL") + } + switch shell := filepath.Base(strings.TrimSpace(shellLine[1])); shell { + case "sh", "bash": + default: + t.Skipf("skipping test on non-Bourne shell %q", shell) + } + if sttyOutput := buf.String(); !strings.Contains(sttyOutput, "-echo ") { - t.Fatalf("terminal mode failure: expected -echo in stty output, got %s", sttyOutput) + t.Fatal("terminal mode failure: expected -echo in stty output") } }