MCPcopy
hub / github.com/cli/cli / newTestVirtualTerminal

Function newTestVirtualTerminal

internal/prompter/accessible_prompter_test.go:839–866  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

837}
838
839func newTestVirtualTerminal(t *testing.T) *expect.Console {
840 t.Helper()
841
842 // Create a PTY and hook up a virtual terminal emulator
843 ptm, pts, err := pty.Open()
844 require.NoError(t, err)
845
846 term := vt10x.New(vt10x.WithWriter(pts))
847
848 // Create a console via Expect that allows scripting against the terminal
849 consoleOpts := []expect.ConsoleOpt{
850 expect.WithStdin(ptm),
851 expect.WithStdout(term),
852 expect.WithCloser(ptm, pts),
853 failOnExpectError(t),
854 failOnSendError(t),
855 expect.WithDefaultTimeout(time.Second),
856 // Use this logger to debug expect based tests by printing the
857 // characters being read to stdout.
858 // expect.WithLogger(log.New(os.Stdout, "", 0)),
859 }
860
861 console, err := expect.NewConsole(consoleOpts...)
862 require.NoError(t, err)
863 t.Cleanup(func() { testCloser(t, console) })
864
865 return console
866}
867
868func newTestVirtualTerminalIOStreams(t *testing.T, console *expect.Console) *iostreams.IOStreams {
869 t.Helper()

Callers 2

TestAccessiblePrompterFunction · 0.70
TestSurveyPrompterFunction · 0.70

Calls 5

OpenMethod · 0.80
failOnExpectErrorFunction · 0.70
failOnSendErrorFunction · 0.70
testCloserFunction · 0.70
HelperMethod · 0.65

Tested by

no test coverage detected