github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/eval/builtin_fn_cmd_unix_test.go (about)

     1  // +build !windows,!plan9,!js
     2  
     3  package eval_test
     4  
     5  import (
     6  	"testing"
     7  
     8  	. "src.elv.sh/pkg/eval/evaltest"
     9  )
    10  
    11  func TestHasExternal(t *testing.T) {
    12  	Test(t,
    13  		That("has-external sh").Puts(true),
    14  		That("has-external random-invalid-command").Puts(false),
    15  	)
    16  }
    17  
    18  func TestSearchExternal(t *testing.T) {
    19  	Test(t,
    20  		// Even on UNIX systems we can't assume that commands like `sh` or
    21  		// `test` are in a specific directory. Those commands might be in /bin
    22  		// or /usr/bin. However, on all systems we currently support it will
    23  		// be in /bin and, possibly, /usr/bin. So ensure we limit the search
    24  		// to the one universal UNIX directory for basic commands.
    25  		That("E:PATH=/bin search-external sh").Puts("/bin/sh"),
    26  		// We should check for a specific error if the external command cannot
    27  		// be found. However, the current implementation of `search-external`
    28  		// returns the raw error returned by a Go runtime function over which
    29  		// we have no control.
    30  		//
    31  		// TODO: Replace the raw Go runtime `exec.LookPath` error with an
    32  		// Elvish error; possibly wrapping the Go runtime error. Then tighten
    33  		// this test to that specific error.
    34  		That("search-external random-invalid-command").Throws(AnyError),
    35  	)
    36  }
    37  
    38  func TestExternal(t *testing.T) {
    39  	Test(t,
    40  		That(`(external sh) -c 'echo external-sh'`).Prints("external-sh\n"),
    41  	)
    42  }