2020-09-03 13:48:39 +08:00
|
|
|
package eval_test
|
2020-08-13 12:09:38 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"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) {
|
2020-09-03 13:55:14 +08:00
|
|
|
tmpHome, cleanup := testutil.InTempHome()
|
2020-08-13 12:09:38 +08:00
|
|
|
defer cleanup()
|
|
|
|
|
2020-09-03 11:55:16 +08:00
|
|
|
restorePath := testutil.WithTempEnv("PATH", tmpHome+":"+os.Getenv("PATH"))
|
2020-09-03 11:16:29 +08:00
|
|
|
defer restorePath()
|
|
|
|
|
2020-08-13 12:09:38 +08:00
|
|
|
Test(t,
|
|
|
|
That(`e = (external true); kind-of $e`).Puts("fn"),
|
|
|
|
That(`e = (external true); put (repr $e)`).Puts("<external true>"),
|
|
|
|
That(`e = (external false); m = [&$e=true]; put (repr $m)`).Puts("[&<external false>=true]"),
|
2021-01-05 12:07:35 +08:00
|
|
|
// Test calling of external commands.
|
2020-08-13 12:09:38 +08:00
|
|
|
That(`e = (external true); $e`).DoesNothing(),
|
|
|
|
That(`e = (external true); $e &option`).Throws(ErrExternalCmdOpts, "$e &option"),
|
2020-09-05 03:31:47 +08:00
|
|
|
That(`e = (external false); $e`).Throws(CmdExit(
|
|
|
|
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".
|
2020-09-05 03:31:47 +08:00
|
|
|
That(`e = (external true); E:PATH=/ $e`).Throws(AnyError),
|
2020-08-13 12:09:38 +08:00
|
|
|
)
|
|
|
|
}
|