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

     1  package shell
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	. "src.elv.sh/pkg/prog/progtest"
     8  )
     9  
    10  func TestMain(m *testing.M) {
    11  	interactiveRescueShell = false
    12  	os.Exit(m.Run())
    13  }
    14  
    15  func TestInteract_SingleCommand(t *testing.T) {
    16  	f := Setup()
    17  	defer f.Cleanup()
    18  	f.FeedIn("echo hello\n")
    19  
    20  	Interact(f.Fds(), &InteractConfig{})
    21  	f.TestOut(t, 1, "hello\n")
    22  }
    23  
    24  func TestInteract_Exception(t *testing.T) {
    25  	f := Setup()
    26  	defer f.Cleanup()
    27  	f.FeedIn("fail mock\n")
    28  
    29  	Interact(f.Fds(), &InteractConfig{})
    30  	f.TestOutSnippet(t, 2, "fail mock")
    31  	f.TestOut(t, 1, "")
    32  }
    33  
    34  func TestInteract_RcFile(t *testing.T) {
    35  	f := Setup()
    36  	defer f.Cleanup()
    37  	f.FeedIn("")
    38  
    39  	MustWriteFile("rc.elv", "echo hello from rc.elv")
    40  
    41  	Interact(f.Fds(), &InteractConfig{Paths: Paths{Rc: "rc.elv"}})
    42  	f.TestOut(t, 1, "hello from rc.elv\n")
    43  }
    44  
    45  func TestInteract_RcFile_DoesNotCompile(t *testing.T) {
    46  	f := Setup()
    47  	defer f.Cleanup()
    48  	f.FeedIn("")
    49  
    50  	MustWriteFile("rc.elv", "echo $a")
    51  
    52  	Interact(f.Fds(), &InteractConfig{Paths: Paths{Rc: "rc.elv"}})
    53  	f.TestOutSnippet(t, 2, "variable $a not found")
    54  	f.TestOut(t, 1, "")
    55  }
    56  
    57  func TestInteract_RcFile_Exception(t *testing.T) {
    58  	f := Setup()
    59  	defer f.Cleanup()
    60  	f.FeedIn("")
    61  
    62  	MustWriteFile("rc.elv", "fail mock")
    63  
    64  	Interact(f.Fds(), &InteractConfig{Paths: Paths{Rc: "rc.elv"}})
    65  	f.TestOutSnippet(t, 2, "fail mock")
    66  	f.TestOut(t, 1, "")
    67  }
    68  
    69  func TestInteract_RcFile_NonexistentIsOK(t *testing.T) {
    70  	f := Setup()
    71  	defer f.Cleanup()
    72  	f.FeedIn("")
    73  
    74  	Interact(f.Fds(), &InteractConfig{Paths: Paths{Rc: "rc.elv"}})
    75  	f.TestOut(t, 1, "")
    76  }