Each DejaGnu test is an expect
script; the tests vary widely in
complexity, depending on the nature of the tool and the feature tested.
Here is a very simple GDB test--one of the simplest tests shipped with DejaGnu (extracted from `gdb.t00/echo.exp'):(2)
# send a string to the GDB stdin: send "echo Hello world!\n" # inspect the GDB stdout for the correct reply, # and determine whether the test passes or fails: expect { -re "Hello world.*$prompt $" { pass "Echo test" } -re "$prompt $" { fail "Echo test" } timeout { fail "(timeout) Echo test" } }
Though brief, this example is a complete test. It illustrates some of the main features of DejaGnu test scripts:
send
(to give it commands) and expect
(to analyze its responses).
expect
command uses a list of pairs; a pattern (regular
expression if `-re' specified), followed by an action to run if the
pattern matches output from the program. Only the action for the
first matching pattern will execute.
pass
and fail
to record the
test outcome.
Go to the first, previous, next, last section, table of contents.