So I write a response to this blogs.perl.org post titled, 'Who Tests the Tester? Me!!!' by lichtkind and almost as soon as I hit the submit button I take a closer look at my test and say, 'oops...I forgot to change the class to the new subclass...I'll just change that and rerun my tests. No problem...'

t/01.t ............ ok t/hsltupletest.t .. 1/? # Failed test 'A is now between 0 and 360 since it is degrees' # at t/hsltupletest.t line 22. # Looks like you failed 1 test of 6. t/hsltupletest.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/6 subtests t/tupletest.t ..... ok Test Summary Report ------------------- t/hsltupletest.t (Wstat: 256 (exited 1) Tests: 6 Failed: 1) Failed test: 6 Non-zero exit status: 1 Files=3, Tests=12, 0 wallclock secs ( 0.08 usr 0.02 sys + 0.49 cusr + 0.07 csys = 0.66 CPU) Result: FAIL

Denied!

Debugging reveals something extremely strange...

main::(./t/hsltupletest.t:8): my $prospectTupleRef = [qw~a b c~]; DB<1> n main::(./t/hsltupletest.t:10): my $tuple = HSLTuple->new($prospectT +upleRef, 'HSL'); DB<1> n main::(./t/hsltupletest.t:12): ok($tuple->is_valid($prospectTupleRe +f) == 0, "A B C is an array but not an HSL tuple"); DB<1> x $tuple 0 FakeTuple=HASH(0x5b2e6ee12a70) 'axes' => 3 'space_name' => 'HSL' 'tupledata' => undef DB<2>

What? It says it is a FakeTuple even though I clearly used the HSLTuple! Unsurprisingly, it calls the is_valid() method of FakeTuple:

main::(./t/hsltupletest.t:20): ok($tuple->is_valid([qw~361 62 99~]) + == 0 , "A must be between 0 and 360 since it is degrees"); DB<2> s FakeTuple::is_valid(FakeTuple.pm:34): 34: my ($self, $data2Check) = @_; DB<2> l 34==> my ($self, $data2Check) = @_; 35: my $result = 0; 36: for(0..2){$result++ if ($data2Check->[$_]=~m/\d+/ && 37 $data2Check->[$_] >= 0 && 38 $data2Check->[$_] <= 100)}; 39 40: return ( $result == $self->no_of_axes() ) ? 1 : 0; 41 } 42 43 # code (loosely) borrowed from Basis.pm DB<2>

Why did it not use my derived class and call my overridden method?

Celebrate Intellectual Diversity


In reply to Perl Inheritance Not Working as Expected by InfiniteSilence

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.