package matrix
Module Matrix_test.ChildSource
Programs run as a child process on a pseudo-terminal.
A child runs on the slave side of a pseudo-terminal whose master a terminal holds, on the real clock. The slave is the child's controlling terminal, so resize signals it as a window does, and the terminal answers its queries as its profile says, as soon as its output is read. Nothing outside the child knows when it is done, so a test waits for what it expects to see, and checks it only where the screen is one a terminal may show: where no update (mode 2026) is open, and where one opens (Updates).
The type for children.
val with_spawn :
Terminal.t ->
?env:(string * string) list ->
?cwd:string ->
prog:string ->
args:string list ->
(t -> 'a) ->
'awith_spawn term ~prog ~args f runs prog with args on a pseudo-terminal of term's size, calls f with the child, and ends and reaps the child when f returns or raises (Pty.with_spawn). The child's environment is the profile's, then env, and nothing of the test's, so a program that needs PATH or HOME is given them. cwd is its working directory, by default the test's.
Raises Unix.Unix_error as Pty.spawn does.
resize c ~cols ~rows resizes the terminal and the pseudo-terminal, which signals the child, and sends the mode 2048 report when the child has set it.
wait c ~within ready applies the child's output to the terminal and answers it until ready holds of the terminal, and returns with the terminal at that point of the output. The output read after it is applied by the next call. ready is checked at each point of the output where no update is open or where one opens, from the point the terminal is at. It blocks for at most within seconds.
Raises Failure, with the screen, if within seconds pass or the child's output ends first.
exit c ~within applies the child's output until it ends, and is the child's exit status. It blocks for at most within seconds of output.
Raises Failure, with the screen, if the output has not ended within within seconds.