Skip to content

Commit

Permalink
Add pty specific repro of superfluous output
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Aug 31, 2023
1 parent b647873 commit a695852
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/pty/go.mod
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
4 changes: 4 additions & 0 deletions test/pty/go.sum
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=
7 changes: 7 additions & 0 deletions test/pty/helloworld.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("hello")
}
46 changes: 46 additions & 0 deletions test/pty/pty_test.go
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)
}
}

0 comments on commit a695852

Please sign in to comment.