1
1
package ptytest_test
2
2
3
3
import (
4
+ "fmt"
4
5
"os/exec"
5
6
"testing"
6
7
8
+ "github.com/spf13/cobra"
7
9
"github.com/stretchr/testify/require"
8
10
9
11
"github.com/coder/coder/pty/ptytest"
@@ -18,6 +20,7 @@ func TestPtytest(t *testing.T) {
18
20
pty .ExpectMatch ("write" )
19
21
pty .WriteLine ("read" )
20
22
})
23
+
21
24
// nolint:paralleltest
22
25
t .Run ("Do not hang on Intel macOS" ,func (t * testing.T ) {
23
26
cmd := exec .Command ("sh" ,"-c" ,"echo hi, I will cause a hang" )
@@ -27,4 +30,23 @@ func TestPtytest(t *testing.T) {
27
30
err := cmd .Run ()
28
31
require .NoError (t ,err )
29
32
})
33
+
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
+ return nil
43
+ },
44
+ }
45
+
46
+ pty := ptytest .New (t )
47
+ cmd .SetIn (pty .Input ())
48
+ cmd .SetOut (pty .Output ())
49
+ err := cmd .Execute ()
50
+ require .NoError (t ,err )
51
+ })
30
52
}