Skip to content

fix: improve pty and ptytest #5327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 7, 2022
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
mtojek committed Dec 7, 2022
commit 593a891e9523ced6e3dd4f082871b398c0549c96
8 changes: 8 additions & 0 deletions pty/pty_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ func (p *otherPty) Resize(height uint16, width uint16) error {
}

func (p *otherPty) Close() error {
if p.opts.logger != nil {
p.opts.logger.Println("Will close...")
}

p.mutex.Lock()
defer p.mutex.Unlock()

if p.opts.logger != nil {
p.opts.logger.Println("Closing...")
}

if p.closed {
return p.err
}
Expand Down
4 changes: 2 additions & 2 deletions pty/ptytest/ptytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (p *PTY) ExpectMatch(str string) string {
p.logf("matched %q = %q", str, buffer.String())
return buffer.String()
case <-timeout.Done():
// Ensure gorouine is cleaned up before test exit.
// Ensure goroutine is cleaned up before test exit.
_ = p.out.closeErr(p.Close())
<-match

Expand Down Expand Up @@ -202,7 +202,7 @@ func logf(t *testing.T, name, format string, args ...interface{}) {
func fatalf(t *testing.T, name, reason, format string, args ...interface{}) {
t.Helper()

panic(fmt.Sprintf("%s: %s %s", name, reason, fmt.Sprintf(format, args...)))
t.Fatal(fmt.Sprintf("%s: %s %s", name, reason, fmt.Sprintf(format, args...)))
}

// stdbuf is like a buffered stdout, it buffers writes until read.
Expand Down