← Back to team overview

geda-developers team mailing list archive

Re: Unit tests

 

On 2/5/2015 9:51 PM, Andrew Poelstra wrote:

Hi guys,


Peter C emailed me recently about some weird pcb-printf behaviour he's seeing
with some specifiers, and in my five minute investigation I also noticed that

   unit_to_coord (get_unit_struct ("mm"), 1.0)

returns 999999, which is an off-by-one error. This is because unit_to_coord
passes through to 1/coord_to_unit instead of doing its own computation.


I'm sure there's lots of stuff like this that are basically trivial to catch,
but today we're not catching them because we have no unit tests.


There are some tests on the exporters but they are fairly limited (says one who is hopelessly out of date with the current state of things).

I discovered that GLib supports unit testing, as described at

https://developer.gnome.org/glib/stable/glib-Testing.html

so we can add unit tests with no new dependencies.


I've pushed 86ba8ca which adds a single test and changes `make check` to
run it. This commit also fixes the aforementioned off-by-one bug, since
this was a small fix, got the new testsuite into a passing state, and
didn't cause any regressions to fail.

Please let me know if there are comments or concerns about any of this.


To unit test a file:
   1. Add it to TEST_SRCS in src/Makefile.am

   2. In the file, add

     #ifdef PCB_UNIT_TEST
        /* Function to call g_test_add_func() on following functions */
        /* Actual unit test functions */
     #endif PCB_UNIT_TEST

   3. In src/main-test.c add a call to the first function from step 2.

See what I've done with pcb-printf.c for an example. If this seems
reasonable I'll add these steps to the README.

I am not really enough up to speed to comment on if this is a good way to implement it but I've seen huge benefits of better automated testing in other places. I'm all for whatever it takes to get PCB to that state (a more testable/verifiable one).

Thanks for looking into this.
-Dan





References