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

Commit7692c5d

Browse files
committed
Create proper test to fully reproduce the issue on macOS
1 parent638acb6 commit7692c5d

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

‎pty/ptytest/ptytest_test.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package ptytest_test
22

33
import (
44
"fmt"
5-
"os/exec"
5+
"strings"
66
"testing"
77

88
"github.com/spf13/cobra"
@@ -21,32 +21,36 @@ func TestPtytest(t *testing.T) {
2121
pty.WriteLine("read")
2222
})
2323

24-
// nolint:paralleltest
25-
t.Run("Do not hang on Intel macOS",func(t*testing.T) {
26-
cmd:=exec.Command("sh","-c","echo hi, I will cause a hang")
27-
pty:=ptytest.New(t)
28-
cmd.Stdin=pty.Input()
29-
cmd.Stdout=pty.Output()
30-
err:=cmd.Run()
31-
require.NoError(t,err)
32-
})
24+
t.Run("Cobra ptytest should not hang when output is not consumed",func(t*testing.T) {
25+
t.Parallel()
3326

34-
// nolint:paralleltest
35-
t.Run("CobraCommandWorksLinux",func(t*testing.T) {
36-
// Example with cobra command instead of exec. More abstractions, but
37-
// for some reason works on linux.
38-
cmd:= cobra.Command{
39-
Use:"test",
40-
RunE:func(cmd*cobra.Command,args []string)error {
41-
fmt.Println("Hello world")
42-
returnnil
43-
},
27+
tests:= []struct {
28+
namestring
29+
outputstring
30+
}{
31+
{name:"1024 is safe (does not exceed macOS buffer)",output:strings.Repeat(".",1024)},
32+
{name:"1025 exceeds macOS buffer (must not hang)",output:strings.Repeat(".",1025)},
4433
}
34+
for_,tt:=rangetests {
35+
tt:=tt
36+
// nolint:paralleltest // Avoid parallel test to more easily identify the issue.
37+
t.Run(tt.name,func(t*testing.T) {
38+
// Example with cobra command instead of exec. More abstractions, but
39+
// for some reason works on linux.
40+
cmd:= cobra.Command{
41+
Use:"test",
42+
RunE:func(cmd*cobra.Command,args []string)error {
43+
fmt.Fprint(cmd.OutOrStdout(),tt.output)
44+
returnnil
45+
},
46+
}
4547

46-
pty:=ptytest.New(t)
47-
cmd.SetIn(pty.Input())
48-
cmd.SetOut(pty.Output())
49-
err:=cmd.Execute()
50-
require.NoError(t,err)
48+
pty:=ptytest.New(t)
49+
cmd.SetIn(pty.Input())
50+
cmd.SetOut(pty.Output())
51+
err:=cmd.Execute()
52+
require.NoError(t,err)
53+
})
54+
}
5155
})
5256
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp