Dear All

I'm writing test cases for something that's already working just fine (yes, I know...)

The main engine module creates one instance of a number of different classes based on user selections. All these do the same thing via a common sub name, returning the same structure, but using vastly different data sources (in another language I'd be talking about polymorphism). Sort of like this:

package BossClass; ... sub new { ... } sub create { my $obj = $a ? Aclass->new(...) : $b ? Bclass->new(...) : Cclass->new(...); my $res = $obj->do_it(...); ... }
The constructor params and method call args can be different in each case and it's those I want to unit test, without actually the class instance in question doing whatever the class's do_it does, if you see what I mean. I've used Test::Resub for this. eg:
use Test::More; use Test::Resub qw/ resub /; my $mocker = resub 'Aclass::do_it', sub { }, capture=>1; my $tobj = BossClass->new(...); $tobj->create(); my $args = $mocker->args; # Tests check the args BossClass provided to the chosen constructor # and the do_it method are as expected
This works just fine for 4 out of 5 of my "polymorphic" classes. On the failing one, I get the following:
The result of B::Deparse::coderef2text was empty - maybe you're trying to serialize an XS function?
I know the constructor was called and I don't believe either the mock or real do_it was called. I'm guessing the error is occurring in the part of Test:Resub magic that compiles a replacement method on the fly, but the "resub" code I'm using for all the polymorphic classes is identical in all cases - just do nothing! Hope someone has encountered this before and can point me in the direction. I've tried temporarily commenting out the entire contents of the offending class's do_it (and all other subs in the class), but no joy: same error message.

In reply to Perl compiler breaks using Test::Resub by ron7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.