jech / babeld

The Babel routing daemon
http://www.irif.fr/~jch/software/babel/
MIT License
383 stars 92 forks source link

Tips for running the automated tests #122

Open julianharty opened 1 week ago

julianharty commented 1 week ago

Context

This project includes automated tests written using a main program rather than using a unit testing framework. Here's how to build and run these tests.

Clean before you start

Run make clean when switching to make the project and make the tests otherwise the make will fail either because there are multiple main functions available to the linker, or none.

More info A compilation flag of NO_MAIN is defined when the tests are compiled. When the project is clean the program's main is excluded and a separate one used for testing is included during the make process. If the make target changes between test and not building the tests then there is no dependency that causes the program's main to be recompiled with the current value of the compilation flag/without the compilation flag. Running the clean removes the object files for any main and means the next make command performs as intended.

Running the tests

Currently when make test runs it actually runs the tests silently and deletes the test program it created. If you'd like to see the tests run and/or capture a log of the test run, one way is to edit the Makefile along the following lines:

# Create a temporary folder for the output
mkdir tests/logs

# Edit the test target in the main Makefile to redirect the output of running the main generated to run the tests
cd tests/ && $(MAKE) && ./main > ./logs/tests.log && $(MAKE) clean

Note: the main program is still deleted as the final step in this make process, remove the final && $(MAKE) clean if you'd like to run the tests again afterwards.