How to setup unit tests with DejaGnu

Viewed 237

I'm trying to learn DejaGnu (https://www.gnu.org/software/dejagnu/) and would like to use it as a framework for unit tests for a C API. My build system is based on the Autotools.

In a subdirectory of ./testsuite, I have a number of C files, each of which includes dejagnu.h and uses its procedures to report passes and failures of some tests.

In ./testsuite, my Makefile.am has the line AUTOMAKE_OPTIONS=dejagnu, which causes make check to call DejaGnu's runtest.

What I am missing now is some glue code (probably some Expect files) that lets runtest find my C files with the unit tests, executes them and collects the result.

I'm looking for an explanation better than DejaGnu's description in its manual, an example setup or a link to some open source project that actually implements what I have in mind in its build system.

(I am not asking for alternative tools. This is a question especially about DejaGnu.)

1 Answers

Using the pass/fail functions defined in dejagnu.h is only valid for batch tools for unit testing. What you need is a simple xx.exp file like the below:

load_lib dejagnu.exp

host_execute $srcdir/unit-code/unittest

Related