Skip to content

Commit

Permalink
Add test that surfaces issue with output containing invalid data
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Aug 30, 2023
1 parent 502ea17 commit 9e60c58
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/helloworld/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/ActiveState/termtest/test/helloworld

go 1.20

replace github.com/ActiveState/termtest => ../../

require github.com/ActiveState/termtest v0.0.0-00010101000000-000000000000

require (
github.com/ActiveState/pty v0.0.0-20230628221854-6fb90eb08a14 // indirect
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02 // indirect
golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49 // indirect
)
11 changes: 11 additions & 0 deletions test/helloworld/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/ActiveState/pty v0.0.0-20230628221854-6fb90eb08a14 h1:RdhhSiwmgyUaaF2GBNrbqTwE5SM+MaVjwf91Ua+CK8c=
github.com/ActiveState/pty v0.0.0-20230628221854-6fb90eb08a14/go.mod h1:5mM6vNRQwshCjlkOnVpwC//4ZpkiC6nmZr8lPOxJdXs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02 h1:AgcIVYPa6XJnU3phs104wLj8l5GEththEw6+F79YsIY=
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
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=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
7 changes: 7 additions & 0 deletions test/helloworld/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 World")
}
30 changes: 30 additions & 0 deletions test/helloworld/helloworld_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"os/exec"
"path/filepath"
"runtime"
"testing"

"github.com/ActiveState/termtest"
)

func Test_ExactOutput(t *testing.T) {
_, filename, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("unable to get the current filename")
}
cmd := exec.Command("go", "run", filepath.Join(filepath.Dir(filename), "helloworld.go"))

tt, err := termtest.New(cmd, termtest.OptTestErrorHandler(t))
if err != nil {
t.Fatalf("unexpected error: %s", err)
}

tt.ExpectExitCode(0)

output := tt.Output()
if output != "Hello World" {
t.Errorf("Output should be 'Hello World' and nothing else, got: %s", output)
}
}

0 comments on commit 9e60c58

Please sign in to comment.