2018-09-29 07:27:54 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
2021-08-07 04:31:39 +08:00
|
|
|
"path/filepath"
|
2018-09-29 07:27:54 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
. "src.elv.sh/pkg/prog/progtest"
|
2021-08-07 05:18:09 +08:00
|
|
|
. "src.elv.sh/pkg/testutil"
|
2018-09-29 07:27:54 +08:00
|
|
|
)
|
|
|
|
|
2021-09-12 21:04:30 +08:00
|
|
|
func TestInteract(t *testing.T) {
|
|
|
|
setupHomePaths(t)
|
|
|
|
InTempDir(t)
|
2021-08-07 05:18:09 +08:00
|
|
|
MustWriteFile("rc.elv", "echo hello from rc.elv")
|
2021-09-12 21:04:30 +08:00
|
|
|
MustWriteFile("rc-dnc.elv", "echo $a")
|
|
|
|
MustWriteFile("rc-fail.elv", "fail bad")
|
|
|
|
|
|
|
|
Test(t, Program{},
|
|
|
|
thatElvishInteract().WithStdin("echo hello\n").WritesStdout("hello\n"),
|
|
|
|
thatElvishInteract().WithStdin("fail mock\n").WritesStderrContaining("fail mock"),
|
|
|
|
|
|
|
|
thatElvishInteract("-rc", "rc.elv").WritesStdout("hello from rc.elv\n"),
|
|
|
|
// rc file does not compile
|
|
|
|
thatElvishInteract("-rc", "rc-dnc.elv").
|
|
|
|
WritesStderrContaining("variable $a not found"),
|
|
|
|
// rc file throws exception
|
|
|
|
thatElvishInteract("-rc", "rc-fail.elv").WritesStderrContaining("fail bad"),
|
|
|
|
// rc file not existing is OK
|
|
|
|
thatElvishInteract("-rc", "rc-nonexistent.elv").DoesNothing(),
|
|
|
|
)
|
2020-04-17 05:02:05 +08:00
|
|
|
}
|
|
|
|
|
2021-09-12 21:04:30 +08:00
|
|
|
func TestInteract_DefaultRCPath(t *testing.T) {
|
|
|
|
home := setupHomePaths(t)
|
|
|
|
// Legacy RC path
|
|
|
|
MustWriteFile(
|
|
|
|
filepath.Join(home, ".elvish", "rc.elv"), "echo hello legacy rc.elv")
|
|
|
|
// Note: non-legacy path is tested in interact_unix_test.go
|
2020-04-16 18:41:34 +08:00
|
|
|
|
2021-09-12 21:04:30 +08:00
|
|
|
Test(t, Program{},
|
|
|
|
thatElvishInteract().WritesStdout("hello legacy rc.elv\n"),
|
|
|
|
)
|
2020-04-16 18:41:34 +08:00
|
|
|
}
|
|
|
|
|
2021-09-12 21:04:30 +08:00
|
|
|
func thatElvishInteract(args ...string) Case {
|
|
|
|
return ThatElvish(args...).WritesStderrContaining("")
|
2020-04-16 18:41:34 +08:00
|
|
|
}
|