← Back to team overview

geda-developers team mailing list archive

Unit tests

 

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.

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.



Andrew


-- 
Andrew Poelstra
Mathematics Department, University of Texas at Austin
Email: apoelstra at wpsoftware.net
Web:   http://www.wpsoftware.net/andrew

Attachment: pgpWYHRm0Yh8R.pgp
Description: PGP signature


Follow ups