github.com/elves/elvish@v0.15.0/pkg/cli/clitest/apptest_test.go (about)

     1  package clitest
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/elves/elvish/pkg/cli"
     7  	"github.com/elves/elvish/pkg/cli/term"
     8  )
     9  
    10  func TestFixture(t *testing.T) {
    11  	f := Setup(
    12  		WithSpec(func(spec *cli.AppSpec) {
    13  			spec.CodeAreaState.Buffer = cli.CodeBuffer{Content: "test", Dot: 4}
    14  		}),
    15  		WithTTY(func(tty TTYCtrl) {
    16  			tty.SetSize(20, 30) // h = 20, w = 30
    17  		}),
    18  	)
    19  	defer f.Stop()
    20  
    21  	// Verify that the functions passed to Setup have taken effect.
    22  	if cli.GetCodeBuffer(f.App).Content != "test" {
    23  		t.Errorf("WithSpec did not work")
    24  	}
    25  
    26  	buf := f.MakeBuffer()
    27  	// Verify that the WithTTY function has taken effect.
    28  	if buf.Width != 30 {
    29  		t.Errorf("WithTTY did not work")
    30  	}
    31  
    32  	f.TestTTY(t, "test", term.DotHere)
    33  
    34  	f.App.Notify("something")
    35  	f.TestTTYNotes(t, "something")
    36  
    37  	f.App.CommitCode()
    38  	if code, err := f.Wait(); code != "test" || err != nil {
    39  		t.Errorf("Wait returned %q, %v", code, err)
    40  	}
    41  }