github.com/elves/elvish@v0.15.0/pkg/eval/external_cmd_test.go (about)

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