mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 18:07:51 +08:00
parent
8deec2e3fe
commit
e23c622863
|
@ -9,6 +9,55 @@ import (
|
|||
"github.com/elves/elvish/pkg/eval/vars"
|
||||
)
|
||||
|
||||
func TestInteract_SingleCommand(t *testing.T) {
|
||||
f := setup()
|
||||
defer f.cleanup()
|
||||
f.feedIn("echo hello\n")
|
||||
|
||||
Interact(f.fds(), &InteractConfig{})
|
||||
f.testOut(t, 1, "hello\n")
|
||||
}
|
||||
|
||||
func TestInteract_Exception(t *testing.T) {
|
||||
f := setup()
|
||||
defer f.cleanup()
|
||||
f.feedIn("fail mock\n")
|
||||
|
||||
Interact(f.fds(), &InteractConfig{})
|
||||
f.testOutSnippet(t, 2, "fail mock")
|
||||
}
|
||||
|
||||
func TestInteract_RcFile(t *testing.T) {
|
||||
f := setup()
|
||||
defer f.cleanup()
|
||||
f.feedIn("")
|
||||
|
||||
writeFile("rc.elv", "echo hello from rc.elv")
|
||||
|
||||
Interact(f.fds(), &InteractConfig{Paths: Paths{Rc: "rc.elv"}})
|
||||
f.testOut(t, 1, "hello from rc.elv\n")
|
||||
}
|
||||
|
||||
func TestInteract_RcFile_Exception(t *testing.T) {
|
||||
f := setup()
|
||||
defer f.cleanup()
|
||||
f.feedIn("")
|
||||
|
||||
writeFile("rc.elv", "fail mock")
|
||||
|
||||
Interact(f.fds(), &InteractConfig{Paths: Paths{Rc: "rc.elv"}})
|
||||
f.testOutSnippet(t, 2, "fail mock")
|
||||
}
|
||||
|
||||
func TestInteract_RcFile_NonexistentIsOK(t *testing.T) {
|
||||
f := setup()
|
||||
defer f.cleanup()
|
||||
f.feedIn("")
|
||||
|
||||
Interact(f.fds(), &InteractConfig{Paths: Paths{Rc: "rc.elv"}})
|
||||
f.testOut(t, 1, "")
|
||||
}
|
||||
|
||||
func TestExtractExports(t *testing.T) {
|
||||
ns := eval.Ns{
|
||||
exportsVarName: vars.NewReadOnly(vals.EmptyMap.Assoc("a", "lorem")),
|
||||
|
|
|
@ -30,6 +30,14 @@ func (f *fixture) fds() [3]*os.File {
|
|||
return [3]*os.File{f.pipes[0].r, f.pipes[1].w, f.pipes[2].w}
|
||||
}
|
||||
|
||||
func (f *fixture) feedIn(s string) {
|
||||
_, err := f.pipes[0].w.WriteString(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
f.pipes[0].w.Close()
|
||||
}
|
||||
|
||||
func (f *fixture) testOut(t *testing.T, fd int, wantOut string) {
|
||||
t.Helper()
|
||||
if out := f.pipes[fd].get(); out != wantOut {
|
||||
|
|
Loading…
Reference in New Issue
Block a user