2020-09-03 13:48:39 +08:00
|
|
|
package eval_test
|
2020-08-13 12:09:38 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2021-07-15 10:31:01 +08:00
|
|
|
"os/exec"
|
2020-08-13 12:09:38 +08:00
|
|
|
"testing"
|
2020-09-03 11:16:29 +08:00
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
. "src.elv.sh/pkg/eval"
|
2020-09-03 13:48:39 +08:00
|
|
|
|
2021-01-27 09:28:38 +08:00
|
|
|
. "src.elv.sh/pkg/eval/evaltest"
|
|
|
|
"src.elv.sh/pkg/testutil"
|
2020-08-13 12:09:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuiltinFnExternal(t *testing.T) {
|
2021-08-07 05:18:09 +08:00
|
|
|
tmpHome := testutil.InTempHome(t)
|
|
|
|
testutil.Setenv(t, "PATH", tmpHome+":"+os.Getenv("PATH"))
|
2020-09-03 11:16:29 +08:00
|
|
|
|
2020-08-13 12:09:38 +08:00
|
|
|
Test(t,
|
2022-01-03 08:10:40 +08:00
|
|
|
That("var e = (external true); kind-of $e").Puts("fn"),
|
|
|
|
That("var e = (external true); put (repr $e)").Puts("<external true>"),
|
|
|
|
That("var e = (external false); var m = [&$e=true]; put (repr $m)").Puts("[&<external false>=true]"),
|
2021-01-05 12:07:35 +08:00
|
|
|
// Test calling of external commands.
|
2022-01-03 08:10:40 +08:00
|
|
|
That("var e = (external true); $e").DoesNothing(),
|
|
|
|
That("var e = (external true); $e &option").Throws(ErrExternalCmdOpts, "$e &option"),
|
|
|
|
That("var e = (external false); $e").Throws(CmdExit(
|
2020-09-05 03:31:47 +08:00
|
|
|
ExternalCmdExit{CmdName: "false", WaitStatus: exitWaitStatus(1)})),
|
2020-08-13 12:09:38 +08:00
|
|
|
|
|
|
|
// TODO: Modify the ExternalCmd.Call method to wrap the Go error in a
|
|
|
|
// predictable Elvish error so we don't have to resort to using
|
|
|
|
// ThrowsAny in the following tests.
|
|
|
|
//
|
|
|
|
// The command shouldn't be found when run so we should get an
|
|
|
|
// exception along the lines of "executable file not found in $PATH".
|
2022-03-20 17:31:38 +08:00
|
|
|
That("var e = (external true); { tmp E:PATH = /; $e }").
|
|
|
|
Throws(ErrorWithType(&exec.Error{})),
|
2020-08-13 12:09:38 +08:00
|
|
|
)
|
|
|
|
}
|