cURL / Mailing Lists / curl-library / Single Mail

curl-library

Unit test setup failures

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 5 Jan 2011 13:36:03 -0800

There's a bit of an ambiguity in the way the unit test framework handles
errors in unit_setup() and unit_stop()--there's no way to signal that a
fatal error has occurred. The torture tests, for example, ensure that
a curl_easy_init() call in unit_setup() will fail, so the first test that
uses that handle will cause a NULL pointer dereference. The obvious solution
is to put a fail_unless(data) into the test portion, but that will cause
unit_stop() to be called, even though unit_setup() never succeeded.

I suggest that unit_setup() return an error code, and if an error is
indicated, then the test immediately aborts with a failure, and unit_stop()
is never called. Something like this diff should work, but if we wanted to
get fancy, the error code number returned by unit_setup() (a CURLcode,
probably) could be logged as well:

diff --git a/tests/unit/curlcheck.h b/tests/unit/curlcheck.h
index 57babe5..9d73843 100644
--- a/tests/unit/curlcheck.h
+++ b/tests/unit/curlcheck.h
@@ -46,12 +46,13 @@ extern int unitfail;
   int test(char *unused) \
   { \
   (void)unused; \
- unit_setup(); \
- {
+ if (unit_setup()) { \
+ fail("unit_setup() failed"); \
+ } else {
 
 #define UNITTEST_STOP \
+ unit_stop(); \
   } \
- unit_stop(); \
   return unitfail; \
   }
 
>>> Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-01-05