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"
|
2022-03-26 10:21:06 +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)
|
2022-03-26 10:21:06 +08:00
|
|
|
testutil.InTempDir(t)
|
|
|
|
testutil.MustWriteFile("rc.elv", "echo hello from rc.elv")
|
|
|
|
testutil.MustWriteFile("rc-dnc.elv", "echo $a")
|
|
|
|
testutil.MustWriteFile("rc-fail.elv", "fail bad")
|
2021-09-12 21:04:30 +08:00
|
|
|
|
2022-02-05 22:48:55 +08:00
|
|
|
Test(t, &Program{},
|
2021-09-12 21:04:30 +08:00
|
|
|
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
|
2022-03-26 10:21:06 +08:00
|
|
|
testutil.MustWriteFile(
|
2021-09-12 21:04:30 +08:00
|
|
|
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
|
|
|
|
2022-02-05 22:48:55 +08:00
|
|
|
Test(t, &Program{},
|
2021-09-12 21:04:30 +08:00
|
|
|
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
|
|
|
}
|