incubator-lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <mar...@rectangular.com>
Subject Re: [lucy-dev] C TAP test harnesses
Date Tue, 17 May 2011 05:37:17 GMT
On Fri, May 13, 2011 at 11:17:44AM -0700, Marvin Humphrey wrote:
> On Thu, May 12, 2011 at 09:59:47PM -0700, Joe Schaefer wrote:
> > FWIW the features in the apreq stuff that are nice for me are
> > 
> > 1) macros provide access to __FILE__ and __LINE__ in the test source file,
> 
> It's definitely nice having access to __FILE__ and __LINE__.  The Charmonizer
> tests don't include them because we prioritized taking variadic arguments for
> the test label.  We couldn't keep that feature and include __FILE__ and
> __LINE__ implicitly without requiring variadic macro support from the
> compiler.
> 
> >From what I can tell, you made the opposite choice in the apreq harness -- you
> support __FILE__ and __LINE__, but you only accept simple string test labels. 
> 
> If we were to change the Lucy test harness to use __FILE__ and __LINE__
> implicitly, we would also have to modify some number of tests by creating
> pre-formatted test labels locally to pass into the TEST_XXXXX() routines.  
> A starter patch incorporating the necessary changes to TEST_TRUE() is below my
> sig.  (It does not include fixes for the 22 incompatible variadic invocations
> of TEST_TRUE().)

Another possibility is to integrate __FILE__ and __LINE__ while still
accepting variadic arguments to our test macros.  This is a less invasive
approach, since none of the client code has to change.  A diff illustrating
the necessary mods to TEST_TRUE is below my sig. 

We would need fallback code for when the compiler does not provide proper
support for variadic macros, akin to what we have for THROW in Lucy::Object::Err.

Joe, would you be interested in hacking on Test.cfh/Test.c until all the
functions look something like the example below?  If we get a patch from you
for that, I'll build on it with a patch supplying the fallback code.

Marvin Humphrey


diff --git a/core/Lucy/Test.c b/core/Lucy/Test.c
index 0457683..bab29da 100644
--- a/core/Lucy/Test.c
+++ b/core/Lucy/Test.c
@@ -56,11 +56,12 @@ TestBatch_plan(TestBatch *self) {
 }
 
 bool_t
-TestBatch_test_true(void *vself, bool_t condition, const char *pattern, ...) {
+TestBatch_test_true(void *vself, bool_t condition, const char *file, 
+                    int line, const char *pattern, ...) {
     va_list args;
     va_start(args, pattern);
-    bool_t result = TestBatch_VTest_True((TestBatch*)vself, condition,
-                                         pattern, args);
+    bool_t result = TestBatch_VTest_True((TestBatch*)vself, condition, file,
+                                         line, pattern, args);
     va_end(args);
     return result;
 }
@@ -135,8 +136,8 @@ TestBatch_skip(void *vself, const char *pattern, ...) {
 }
 
 bool_t
-TestBatch_vtest_true(TestBatch *self, bool_t condition, const char *pattern,
-                     va_list args) {
+TestBatch_vtest_true(TestBatch *self, bool_t condition, const char *file,
+                     int line, const char *pattern, va_list args) {
     // Increment test number.
     self->test_num++;
 
@@ -152,7 +153,7 @@ TestBatch_vtest_true(TestBatch *self, bool_t condition, const char *pattern,
         self->num_failed++;
         printf("not ok %" I64P " - ", self->test_num);
         vprintf(pattern, args);
-        printf("\n");
+        printf(" # (%s:%d)\n", file, line);
         return false;
     }
 }
diff --git a/core/Lucy/Test.cfh b/core/Lucy/Test.cfh
index 1b14224..5fc7df5 100644
--- a/core/Lucy/Test.cfh
+++ b/core/Lucy/Test.cfh
@@ -37,7 +37,8 @@ class Lucy::Test::TestBatch inherits Lucy::Object::Obj {
     Plan(TestBatch *self);
 
     inert bool_t
-    test_true(void *vself, bool_t condition, const char *pattern, ...);
+    test_true(void *vself, bool_t condition, const char *file, int line,
+              const char *pattern, ...);
 
     inert bool_t
     test_false(void *vself, bool_t condition, const char *pattern, ...);
@@ -64,8 +65,8 @@ class Lucy::Test::TestBatch inherits Lucy::Object::Obj {
     skip(void *vself, const char *pattern, ...);
 
     bool_t
-    VTest_True(TestBatch *self, bool_t condition, const char *pattern,
-               va_list args);
+    VTest_True(TestBatch *self, bool_t condition, const char *file,
+               int line, const char *pattern, va_list args);
 
     bool_t
     VTest_False(TestBatch *self, bool_t condition, const char *pattern,
@@ -94,8 +95,13 @@ class Lucy::Test::TestBatch inherits Lucy::Object::Obj {
 }
 
 __C__
+
+#define LUCY_TESTBATCH_TEST_TRUE(_batch, _condition, ...) \
+    lucy_TestBatch_test_true(_batch, _condition, __FILE__, __LINE__, \
+                             __VA_ARGS__) 
+
 #ifdef LUCY_USE_SHORT_NAMES
-  #define TEST_TRUE                    lucy_TestBatch_test_true
+  #define TEST_TRUE                    LUCY_TESTBATCH_TEST_TRUE
   #define TEST_FALSE                   lucy_TestBatch_test_false
   #define TEST_INT_EQ                  lucy_TestBatch_test_int_equals
   #define TEST_FLOAT_EQ                lucy_TestBatch_test_float_equals



Mime
View raw message