How to use 'DejaGnu'

'DejaGnu' is a wrapper around the Unix command-line tool "expect" which was originally written for communicating with programs that use a prompt (such as telnet or ftp). It can be used to communicate with any command-line program.

The example below tests whether a program outputs "Hello World!". It can be run on the command-line with "expect" if the first spawn command is uncommented. When run in the Praktomat via 'DejaGnu', variables "JAVA" and "PROGRAM" are replaced after checking the environment for the location of java and the name of the student submitted program. PROGRAM_exit can be added when run on the command-line. The Praktomat will automatically add it to end the program. Printing "PASS" or "FAIL" is interpreted accordingly by the Praktomat. The 'DejaGnu' variables PASS and FAIL can also be used instead. The main tests are achieved via regular expressions. All input (test data and prompts) must be escaped.

Dejagnu example

In general, writing complex tests in this manner can be difficult. The expect program spawns processes in parallel which can have undesired effects for the formatting of the output. It can be difficult to debug. On the command-line "expect -d" is useful for debugging. The programming language used by expect is tcl.

In the Praktomat, the expect file should be split into two parts: the code up to "PROGRAM_start" becomes the setup file, the rest is placed into the main test file. The reason for this is so that different tests can be written using the same setup. Different tests can be grouped in the same file, but if some tests are supposed to be public, some are secret, several test files are needed.

 


eCULT BMBF
Software und Dokumente der ProFormA-Gruppe der Ostfalia
https://elearning-ostfalia.github.io/proforma/

Dieses Vorhaben wurde aus Mitteln des Bundesministeriums für Bildung und Forschung unter den Förderkennzeichen 01PL11066H und 01PL16066H gefördert. Die Verantwortung für den Inhalt dieser Webseite liegt bei den Autorinnen.