www.delorie.com/gnu/docs/greg/greg_28.html   search  
 
Buy GNU books!


Greg testing framework

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.0.8.3 Reading from a child process

The greg-recv macro is used to read data from a child process. This procedure actually provides a simple front-end to the expect module. You can use the expect module facilities directly if you want more control than is offered by greg-recv.

The greg-recv macro expects one or more lists as arguments - each list containing a string (a pattern to match) and a result to return on a successful match. The value returned by greg-recv is the result for the pattern actually matched.
If no pattern is matched within the timeout period then an exception is raised, causing the testcase to return a FAIL result (unless you use (set! expect-timeout-proc xxx) to override Gregs timeout handler.
If no pattern is matched before an end-of-file is read, then an exception is raised, causing the testcase to return a FAIL result (unless you use (set! expect-eof-proc xxx) to override Gregs end-of-file handler.

NB. The expect-timeout-proc and expect-eof-proc are saved when a tool is tarted, and restored when it ends ... so if you want to make changes to these procedures in multiple tools, you must do so in the begin.grg and end.grg files for each tool.

In addition to setting up the above expect procedures, Greg also sets the expect-timeout variable to a 15 second timeout, and sets the expect-char-proc to be greg-dlog so that data read from the child process is logged as debug output by default. You can of course override this behavior in begin.grg.

The pattern matching is done with extended regular expressions, usually with input split into lines so that a carat (^) at the start of an expression matches the start of a line, and a dollar ($) matches the end of a line.
This is convenient for testing programs that produce lines of output in an expected format, as you can easily match the start and end of an output line.

If you want to change this behavior to permit multi-line patterns and to have the carat and dollar match the start of input and end of input respectively, then you can use -
 
(set! expect-strings-compile-flags regexp/extended)
(set! expect-strings-exec-flags 0)
This pattern matching behavior is occasionally useful when you are testing a program that produces output without clearly recognisable individual lines. NB. greg does not save and restore these values, so a change to them effect all tools being tested until you change them back.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003