Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: Rewrite ptytest to buffer stdout#3170

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 7 commits intomainfrommafredri/ptytest-buffer-output
Jul 25, 2022
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
chore: Simplify timeout in ExpectMatch
  • Loading branch information
@mafredri
mafredri committedJul 25, 2022
commit7b331cd3c4cea992ac811060088e50bd77d8d89f
29 changes: 9 additions & 20 deletionspty/ptytest/ptytest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,21 +86,8 @@ type PTY struct {
func (p *PTY) ExpectMatch(str string) string {
p.t.Helper()

complete, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

timeout := make(chan error, 1)
go func() {
defer close(timeout)
timer := time.NewTimer(10 * time.Second)
defer timer.Stop()
select {
case <-complete.Done():
return
case <-timer.C:
}
timeout <- xerrors.Errorf("%s match exceeded deadline", time.Now())
}()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

var buffer bytes.Buffer
match := make(chan error, 1)
Expand All@@ -127,14 +114,16 @@ func (p *PTY) ExpectMatch(str string) string {
select {
case err := <-match:
if err != nil {
p.t.Fatalf("read error: %v (wanted %q; got %q)", err, str, buffer.String())
p.t.Fatalf("%s: read error: %v (wanted %q; got %q)", time.Now(), err, str, buffer.String())
return ""
}
p.t.Logf("matched %q = %q", str, buffer.String())
case err := <-timeout:
p.t.Logf("%s: matched %q = %q", time.Now(), str, buffer.String())
return buffer.String()
case <-ctx.Done():
_ = p.out.closeErr(p.Close())
p.t.Fatalf("%s: wanted %q; got %q", err, str, buffer.String())
p.t.Fatalf("%s: match exceeded deadline: wanted %q; got %q", time.Now(), str, buffer.String())
return ""
}
return buffer.String()
}

func (p *PTY) Write(r rune) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp