Skip to content
Myr

test: exec binary from within tea.Program

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Muehlhaeuser · committed by Christian Muehlhaeuser · parent b1c9d80 · Browse files · 1 file+48 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+48 added−0 removed

  • other:+48 added−0 removed

1 file+48 added−0 removed

added:exec_test.go+48 added
1package tea23import (4 "bytes"5 "os/exec"6 "testing"7)89type execFinishedMsg struct{ err error }10type testExecModel struct{ err error }1112func (m testExecModel) Init() Cmd {13 c := exec.Command("true") //nolint:gosec14 return ExecProcess(c, func(err error) Msg {15 return execFinishedMsg{err}16 })17}1819func (m *testExecModel) Update(msg Msg) (Model, Cmd) {20 switch msg := msg.(type) {21 case execFinishedMsg:22 if msg.err != nil {23 m.err = msg.err24 }25 return m, Quit26 }2728 return m, nil29}3031func (m *testExecModel) View() string {32 return "\n"33}3435func TestTeaExec(t *testing.T) {36 var buf bytes.Buffer37 var in bytes.Buffer3839 m := &testExecModel{}40 p := NewProgram(m, WithInput(&in), WithOutput(&buf))41 if err := p.Start(); err != nil {42 t.Fatal(err)43 }4445 if m.err != nil {46 t.Fatal(m.err)47 }48}