lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Re: patch to avoid hard coding RTTI types names in the tests (was:


From: Vadim Zeitlin
Subject: [lmi] Re: patch to avoid hard coding RTTI types names in the tests (was: still MSVC compilation problems)
Date: Mon, 30 Jun 2008 22:16:05 +0200

On Tue, 24 Jun 2008 13:20:48 +0000 Greg Chicares <address@hidden> wrote:

GC> > GC> > GC> >  Finally, I still have unit test failures after this change:
GC> > GC> > GC> [...]
GC> > GC> > GC> > but they seem to be due to the difference between the 
expected and real
GC> > GC> > GC> > value of std::type::info::name() so I think I should just add 
tests for
GC> > GC> > GC> > MSVC into any_member_test.cpp along the existing tests for 
g++ version. Do
GC> > GC> > GC> > you see anything wrong with this?
GC> > GC> > GC> 
GC> > GC> > GC> Nothing wrong with that. Testing the value of 
std::type::info::name()
GC> > GC> > GC> is fragile, but we're already doing it for other compilers, and 
I'd
GC> > GC> > GC> rather not spend time thinking about removing that fragility 
right now.
GC> > GC> > 
GC> > GC> >  In fact I think it's easy enough to remove this fragility: instead 
of
GC> > GC> > hardcoding the results of std::type_info::name() in the test code 
we could
GC> > GC> > construct the string dynamically using lmi::TypeInfo(). Then there 
would be
GC> > GC> > no need for any compiler [version] tests.
GC> [...]
GC> >  Here it is. I didn't test this with old g++ yet but it does work (i.e. 
the
GC> > test passes) with g++ 4.1 and MSVC.
GC> 
GC> It works with MinGW gcc-3.4.4, too. Could I ask you to write a
GC> similar patch for 'safely_dereference_as_test.cpp', which has
GC> the same fragility?

 Here it is finally, sorry for the delay (I had some strange problems
during the merge, I'm afraid I got entangled in several concurrent
changes...):

--- safely_dereference_as_test.cpp      2008-01-01 18:30:08 +0000
+++ safely_dereference_as_test.cpp      2008-06-30 20:14:46 +0000
@@ -56,13 +56,8 @@
 //    BOOST_TEST_EQUAL( p, &safely_dereference_as<B>(&d));

     std::string diagnostic0;
-#if defined __GNUC__
-#   if !(LMI_GCC_VERSION < 40000)
-    diagnostic0 = "Cannot dereference null pointer of type 'D*'.";
-#   else  // LMI_GCC_VERSION < 40000
-    diagnostic0 = "Cannot dereference null pointer of type 'P1D'.";
-#   endif // LMI_GCC_VERSION < 40000
-#endif // defined __GNUC__
+    diagnostic0 = "Cannot dereference null pointer of type '";
+    diagnostic0 += lmi::TypeInfo(typeid(D *)).Name() + "'.";

     D* null_pointer = 0;
     BOOST_TEST_THROW
@@ -72,13 +67,10 @@
         );

     std::string diagnostic1;
-#if defined __GNUC__
-#   if !(LMI_GCC_VERSION < 40000)
-    diagnostic1 = "Cannot cast pointer of type 'B*' to type 'D*'.";
-#   else  // LMI_GCC_VERSION < 40000
-    diagnostic1 = "Cannot cast pointer of type 'P1B' to type 'P1D'.";
-#   endif // LMI_GCC_VERSION < 40000
-#endif // defined __GNUC__
+    diagnostic1 = "Cannot cast pointer of type '";
+    diagnostic1 += lmi::TypeInfo(typeid(B *)).Name();
+    diagnostic1 += "' to type '";
+    diagnostic1 += lmi::TypeInfo(typeid(D *)).Name() + "'.";

     BOOST_TEST_THROW
         (safely_dereference_as<D>(&b)


 For the reference, here is the first part of this patch, to
any_member_test.cpp again (it's the same one as I had sent before):


--- any_member_test.cpp 2008-01-01 18:30:08 +0000
+++ any_member_test.cpp 2008-06-22 13:38:43 +0000
@@ -353,16 +353,9 @@

     // Test no-such-member diagnostic for both const and non-const
     // subscripting operators.
-
-#if !(defined __GNUC__ && LMI_GCC_VERSION < 40000)
-    std::string err
-        ("Symbol table for class S ascribes no member named 'nonexistent'."
-        );
-#else  // defined __GNUC__ && LMI_GCC_VERSION < 40000
-    std::string err
-        ("Symbol table for class 1S ascribes no member named 'nonexistent'."
-        );
-#endif // defined __GNUC__ && LMI_GCC_VERSION < 40000
+    std::string err("Symbol table for class ");
+    err += lmi::TypeInfo(typeid(S)).Name();
+    err += " ascribes no member named 'nonexistent'.";

     BOOST_TEST_THROW(s_const["nonexistent"], std::runtime_error, err);
     BOOST_TEST_THROW(s      ["nonexistent"], std::runtime_error, err);
@@ -467,11 +460,11 @@
     std::cout << "Testing function template member_cast().\n";
     s.x0.set_str("Test 3");

-#if !(defined __GNUC__ && LMI_GCC_VERSION < 40000)
-    std::string err("Cannot cast from 'int S::*' to 'base_datum'.");
-#else  // defined __GNUC__ && LMI_GCC_VERSION < 40000
-    std::string err("Cannot cast from 'M1Si' to '10base_datum'.");
-#endif // defined __GNUC__ && LMI_GCC_VERSION < 40000
+    std::string err("Cannot cast from '");
+    err += lmi::TypeInfo(typeid(int S::*)).Name();
+    err += "' to '";
+    err += lmi::TypeInfo(typeid(base_datum)).Name();
+    err += "'.";

     BOOST_TEST_THROW(member_cast<base_datum>(s["i0"]), std::runtime_error, 
err);


 Please let me know if you have any questions or comments.

 Thanks,
VZ





reply via email to

[Prev in Thread] Current Thread [Next in Thread]