#129 Ruby Test Cases Patch

closed
cfis
None
5
2005-09-24
2005-09-14
cfis
No

I noticed that the Ruby test cases that deal with
abstract classes, or classes without constructors, fail
when using Ruby 1.8.

Setup - Windows XP, the VC build of Ruby 1.8.2 and
MingW to compile SWIG and run the test cases

Cause - The spirit of the test cases is correct, they
make sure that you can't create an instance of a class
that is abstract or does not have a construtor. I
would guess they were developed against Ruby 1.6.
However, Ruby 1.8 changes the way objects are
constructed by introducing a function called
rb_allocate which is used to allocate memory for the
new object.

SWIG supports both the old style and new style of
creating Ruby objects. In the new style, if a class is
abstract then SWIG undefines the rb_allocate method -
thus making it impossible to create an instance of the
class.

If you look at the test cases, you'll see they catch
one of two Ruby exceptions - NameError and
NoConstructorError - when trying to construct an
abstract class or a class with no constructor.

However, in Ruby 1.8 with the SWIG bindings (thus
rb_allocate is undefined), the exception that is thrown
is TypeError, with the full message being:

TypeError: allocator undefined for
<module_name>::<class_name>

Thus I've updated the test cases to make an additional
check for this exception. With this change, all the
tests run successfully against the latest version of
SWIG in CVS (as of Sept. 13, 2005).

Discussion

  • cfis

    cfis - 2005-09-14
    • summary: Ruby Test Case Patches --> Ruby Test Cases Patch
     
  • cfis

    cfis - 2005-09-14

    Logged In: YES
    user_id=1323508

    Small mistake above - Ruby 1.8 introduced a function called
    rb_define_alloc_func (not rb_allocate) which allows you to
    define your allocation function. You can also undefine an
    allocation function using rb_undef_alloc_func. This is what
    SWIG uses for abstract classes.

     
  • cfis

    cfis - 2005-09-19

    Ruby Test Case Patches

     
    Attachments
  • cfis

    cfis - 2005-09-24
    • assigned_to: nobody --> cfis
    • status: open --> closed
     
  • cfis

    cfis - 2005-09-24

    Logged In: YES
    user_id=1323508

    Fixed.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks