-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pty specific repro of superfluous output
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/ActiveState/termtest/test/pty | ||
|
||
go 1.20 | ||
|
||
require github.com/creack/pty v0.0.0-00010101000000-000000000000 | ||
|
||
require golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49 // indirect | ||
|
||
replace github.com/creack/pty => github.com/photostorm/pty v0.0.0-20230324012736-6794a5ba0ba0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/photostorm/pty v0.0.0-20230324012736-6794a5ba0ba0 h1:12sw4rIcXrMHdMlCbTmaC3RkBfHR8zdoAsetnmMWRh0= | ||
github.com/photostorm/pty v0.0.0-20230324012736-6794a5ba0ba0/go.mod h1:KO+FcPtyLAiRC0hJwreJVvfwc7vnNz77UxBTIGHdPVk= | ||
golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49 h1:TMjZDarEwf621XDryfitp/8awEhiZNiwgphKlTMGRIg= | ||
golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("hello") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/creack/pty" | ||
) | ||
|
||
func Test_Pty_Output(t *testing.T) { | ||
_, filename, _, ok := runtime.Caller(0) | ||
if !ok { | ||
t.Fatal("unable to get the current filename") | ||
} | ||
c := exec.Command("go", "run", filepath.Join(filepath.Dir(filename), "helloworld.go")) | ||
|
||
ptyrw, err := pty.StartWithSize(c, &pty.Winsize{Cols: 140, Rows: 10}) | ||
if err != nil { | ||
t.Fatalf("pty could not start: %s", err) | ||
} | ||
defer func() { _ = ptyrw.Close() }() | ||
|
||
var output []byte | ||
for { | ||
snapshot := make([]byte, 1024) | ||
n, err := ptyrw.Read(snapshot) | ||
if n > 0 { | ||
fmt.Printf("Read: %s", snapshot[:n]) | ||
output = append(output, snapshot[:n]...) | ||
} | ||
if err != nil { | ||
t.Fatalf("read error: %s", err) | ||
break | ||
} | ||
time.Sleep(time.Millisecond * 100) | ||
} | ||
outputv := strings.TrimSpace(string(output)) | ||
if outputv != "hello" { | ||
t.Fatalf("Output is not 'hello', got: %s", outputv) | ||
} | ||
} |