Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Commit

Permalink
Bump dependencies (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Mar 23, 2022
1 parent d1569d9 commit b8ffd1b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
8 changes: 4 additions & 4 deletions assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ func teeError() *tError {
}

// AssertState asserts console state.
func AssertState(t assert.TestingT, state *vt10x.State, expected string) bool {
func AssertState(t assert.TestingT, terminal vt10x.Terminal, expected string) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}

actual := trimTailingSpaces(expect.StripTrailingEmptyLines(state.String()))
actual := trimTailingSpaces(expect.StripTrailingEmptyLines(terminal.String()))

return assert.Equal(t, expected, actual)
}

// AssertStateRegex asserts console state.
func AssertStateRegex(t assert.TestingT, state *vt10x.State, expected string) bool {
func AssertStateRegex(t assert.TestingT, terminal vt10x.Terminal, expected string) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}

actual := trimTailingSpaces(expect.StripTrailingEmptyLines(state.String()))
actual := trimTailingSpaces(expect.StripTrailingEmptyLines(terminal.String()))

return assert.Regexp(t, expected, actual)
}
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ module github.com/nhatthm/consoledog
go 1.17

require (
github.com/Netflix/go-expect v0.0.0-20210722184520-ef0bf57d82b3
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2
github.com/creack/pty v1.1.17
github.com/cucumber/godog v0.12.4
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02
github.com/stretchr/testify v1.7.1
)

require (
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/kr/pty v1.1.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Netflix/go-expect v0.0.0-20210722184520-ef0bf57d82b3 h1:DM0Olh3jQEm4gVPLF0mI49+fm1+M1fXDtumX/fN/G4A=
github.com/Netflix/go-expect v0.0.0-20210722184520-ef0bf57d82b3/go.mod h1:68ORG0HSEWDuH5Eh73AFbYWZ1zT4Y+b0vhOa+vZRUdI=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand All @@ -33,7 +33,6 @@ github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/cucumber/gherkin-go/v19 v19.0.3 h1:mMSKu1077ffLbTJULUfM5HPokgeBcIGboyeNUof1MdE=
Expand All @@ -56,8 +55,9 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -114,8 +114,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c h1:kp3AxgXgDOmIJFR7bIwqFhwJ2qWar8tEQSE5XXhCfVk=
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
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/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand All @@ -131,8 +131,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
Expand Down Expand Up @@ -210,7 +208,6 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -264,7 +261,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
34 changes: 16 additions & 18 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/Netflix/go-expect"
"github.com/creack/pty"
pseudotty "github.com/creack/pty"
"github.com/cucumber/godog"
"github.com/hinshun/vt10x"
"github.com/stretchr/testify/require"
Expand All @@ -22,9 +22,9 @@ type Closer func(sc *godog.Scenario)
type Option func(m *Manager)

type session struct {
console *expect.Console
state *vt10x.State
output *Buffer
console *expect.Console
terminal vt10x.Terminal
output *Buffer
}

// Manager manages console and its state.
Expand Down Expand Up @@ -74,20 +74,20 @@ func (m *Manager) session() *session {
}

// NewConsole creates a new console.
func (m *Manager) NewConsole(sc *godog.Scenario) (*expect.Console, *vt10x.State) {
func (m *Manager) NewConsole(sc *godog.Scenario) (*expect.Console, vt10x.Terminal) {
m.mu.Lock()
defer m.mu.Unlock()

sess := &session{}

if s, ok := m.sessions[sc.Id]; ok {
return s.console, s.state
return s.console, s.terminal
}

m.test.Logf("Console: %s (#%s)\n", sc.Name, sc.Id)

sess.output = new(Buffer)
sess.console, sess.state = newVT10XConsole(m.test, m.termCols, m.termCols, expect.WithStdout(sess.output))
sess.console, sess.terminal = newVT10XConsole(m.test, m.termCols, m.termCols, expect.WithStdout(sess.output))

m.sessions[sc.Id] = sess
m.current = sc.Id
Expand All @@ -96,7 +96,7 @@ func (m *Manager) NewConsole(sc *godog.Scenario) (*expect.Console, *vt10x.State)
fn(sc, sess.console)
}

return sess.console, sess.state
return sess.console, sess.terminal
}

// CloseConsole closes the current console.
Expand All @@ -117,7 +117,7 @@ func (m *Manager) CloseConsole(sc *godog.Scenario) {

m.test.Logf("Raw output: %q\n", sess.output.String())
// Dump the terminal's screen.
m.test.Logf("State: \n%s\n", expect.StripTrailingEmptyLines(sess.state.String()))
m.test.Logf("State: \n%s\n", expect.StripTrailingEmptyLines(sess.terminal.String()))

delete(m.sessions, sc.Id)
m.current = ""
Expand All @@ -136,7 +136,7 @@ func (m *Manager) isConsoleOutput(expected *godog.DocString) error {
m.Flush()

t := teeError()
AssertState(t, m.session().state, expected.Content)
AssertState(t, m.session().terminal, expected.Content)

return t.LastError()
}
Expand All @@ -145,7 +145,7 @@ func (m *Manager) matchConsoleOutput(expected *godog.DocString) error {
m.Flush()

t := teeError()
AssertStateRegex(t, m.session().state, expected.Content)
AssertStateRegex(t, m.session().terminal, expected.Content)

return t.LastError()
}
Expand Down Expand Up @@ -202,18 +202,16 @@ func WithTermSize(cols, rows int) Option {
}
}

func newVT10XConsole(t TestingT, cols, rows int, opts ...expect.ConsoleOpt) (*expect.Console, *vt10x.State) {
ptm, pts, err := pty.Open()
func newVT10XConsole(t TestingT, cols, rows int, opts ...expect.ConsoleOpt) (*expect.Console, vt10x.Terminal) {
pty, tty, err := pseudotty.Open()
require.NoError(t, err)

var state vt10x.State
term, err := vt10x.Create(&state, pts)
require.NoError(t, err)
term := vt10x.New(vt10x.WithWriter(tty))

term.Resize(cols, rows)

c, err := expect.NewConsole(append(opts, expect.WithStdin(ptm), expect.WithStdout(term), expect.WithCloser(pts, ptm, term))...)
c, err := expect.NewConsole(append(opts, expect.WithStdin(pty), expect.WithStdout(term), expect.WithCloser(pty, tty))...)
require.NoError(t, err)

return c, &state
return c, term
}
5 changes: 3 additions & 2 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/Netflix/go-expect"
"github.com/cucumber/godog"

"github.com/nhatthm/consoledog"
)

Expand All @@ -19,7 +20,7 @@ func TestManager(t *testing.T) {
)

scenario := &godog.Scenario{}
_, state := m.NewConsole(scenario)
_, terminal := m.NewConsole(scenario)

// New again does not affect the state.
_, _ = m.NewConsole(scenario)
Expand All @@ -28,7 +29,7 @@ func TestManager(t *testing.T) {

expected := `hello world`

consoledog.AssertState(t, state, expected)
consoledog.AssertState(t, terminal, expected)

m.CloseConsole(scenario)

Expand Down

0 comments on commit b8ffd1b

Please sign in to comment.