ron7 has asked for the wisdom of the Perl Monks concerning the following question:
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:
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:package BossClass; ... sub new { ... } sub create { my $obj = $a ? Aclass->new(...) : $b ? Bclass->new(...) : Cclass->new(...); my $res = $obj->do_it(...); ... }
This works just fine for 4 out of 5 of my "polymorphic" classes. On the failing one, I get the following: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
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl compiler breaks using Test::Resub
by Corion (Patriarch) on Feb 03, 2011 at 09:56 UTC | |
by ron7 (Beadle) on Feb 04, 2011 at 01:23 UTC | |
by rurban (Scribe) on Apr 25, 2011 at 12:21 UTC | |
|
Re: Perl compiler breaks using Test::Resub
by chromatic (Archbishop) on Feb 03, 2011 at 05:28 UTC | |
|
Re: Perl compiler breaks using Test::Resub
by Khen1950fx (Canon) on Feb 03, 2011 at 09:49 UTC |