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

     1  // +build !windows,!plan9
     2  
     3  package eval_test
     4  
     5  import (
     6  	"path/filepath"
     7  	"strings"
     8  	"testing"
     9  
    10  	. "src.elv.sh/pkg/eval/evaltest"
    11  	"src.elv.sh/pkg/testutil"
    12  )
    13  
    14  func TestCompileEffectUnix(t *testing.T) {
    15  	_, cleanup := testutil.InTestDir()
    16  	defer cleanup()
    17  
    18  	mustWriteScript("foo", "#!/bin/sh", "echo foo")
    19  	mustWriteScript("lorem/ipsum", "#!/bin/sh", "echo lorem ipsum")
    20  
    21  	Test(t,
    22  		// External commands.
    23  		That("./foo").Prints("foo\n"),
    24  		That("lorem/ipsum").Prints("lorem ipsum\n"),
    25  		// Using the explicit e: namespace.
    26  		That("e:./foo").Prints("foo\n"),
    27  		// Names of external commands may be built dynamically.
    28  		That("x = ipsum", "lorem/$x").Prints("lorem ipsum\n"),
    29  		// Using new FD as destination in external commands.
    30  		// Regression test against b.elv.sh/788.
    31  		That("./foo 5</dev/null").Prints("foo\n"),
    32  	)
    33  }
    34  
    35  func mustWriteScript(name string, lines ...string) {
    36  	testutil.MustMkdirAll(filepath.Dir(name))
    37  	testutil.MustWriteFile(name, []byte(strings.Join(lines, "\n")), 0700)
    38  }