internal/conformance/subprocess.go
internal/conformance · 118 lines · 5 declarations · source
Declarations
type Subprocess
type Subprocess struct {
Command []string
Stderr io.Writer
mu sync.Mutex
cmd *exec.Cmd
stdin io.WriteCloser
stdout *bufio.Reader
}
Subprocess reaches a driver written in any language: the runner starts the command once and exchanges one JSON line per turn, an Instruction in and a Report out, on its stdin and stdout. One line each way is the whole protocol, so a driver is a loop around the adapter and nothing else; stderr is the driver's own and is passed through for a person to read.
method Subprocess.start
func (s *Subprocess) start(ctx context.Context) error
method Subprocess.Run
func (s *Subprocess) Run(ctx context.Context, in Instruction) (Report, error)
method Subprocess.Close
func (s *Subprocess) Close() error
Close ends the driver by closing its input; a driver exits when its input ends.
func Serve
func Serve(ctx context.Context, in io.Reader, out io.Writer, driver Driver) error
Serve is the other side of the protocol: a loop any driver can be, given an implementation. The reference is served this way to prove the protocol end to end.