github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/eval/external_cmd_test.go (about) 1 package eval_test 2 3 import ( 4 "os" 5 "os/exec" 6 "testing" 7 8 . "github.com/markusbkk/elvish/pkg/eval" 9 10 . "github.com/markusbkk/elvish/pkg/eval/evaltest" 11 "github.com/markusbkk/elvish/pkg/testutil" 12 ) 13 14 func TestBuiltinFnExternal(t *testing.T) { 15 tmpHome := testutil.InTempHome(t) 16 testutil.Setenv(t, "PATH", tmpHome+":"+os.Getenv("PATH")) 17 18 Test(t, 19 That("var e = (external true); kind-of $e").Puts("fn"), 20 That("var e = (external true); put (repr $e)").Puts("<external true>"), 21 That("var e = (external false); var m = [&$e=true]; put (repr $m)").Puts("[&<external false>=true]"), 22 // Test calling of external commands. 23 That("var e = (external true); $e").DoesNothing(), 24 That("var e = (external true); $e &option").Throws(ErrExternalCmdOpts, "$e &option"), 25 That("var e = (external false); $e").Throws(CmdExit( 26 ExternalCmdExit{CmdName: "false", WaitStatus: exitWaitStatus(1)})), 27 28 // TODO: Modify the ExternalCmd.Call method to wrap the Go error in a 29 // predictable Elvish error so we don't have to resort to using 30 // ThrowsAny in the following tests. 31 // 32 // The command shouldn't be found when run so we should get an 33 // exception along the lines of "executable file not found in $PATH". 34 That("var e = (external true); E:PATH=/ $e").Throws(ErrorWithType(&exec.Error{})), 35 ) 36 }