Let's pretend we have an object:
my $o = bless { x => bless ['y'], 'My::Value' }, 'My::Class';

I want to verify that the object when cursed recursively will consist of

{ x => [$v], # where $v is 'y' or 'z' a => 'b' } # if a exists at all

I thought Test::Deep's noclass should be able to tell me.

cmp_deeply $o, noclass(subhashof({ a => 'b', x => subbagof('y', 'z') } +));

But it doesn't work:

# Failed test at ... # Comparing $data->{"x"} as a SubBag # got : My::Value=ARRAY(0x561fbd1fe3a8) # expect : An array to use as a Bag

Without an object, it works nicely:

cmp_deeply { x => ['y'] }, subhashof({ a => 'b', x => subbagof('y', 'z') });

I asked about it in #freenode and was pointed towards Test2::Tools::Compare. It was the first time I played with it, so maybe my code is a bit clumsy, but I was able to write a test that passes:

use Test2::Tools::Compare qw{ like hash item field in_set DNE bag }; my $o = bless { x => bless ['y'], 'My::Value' }, 'My::Class'; like({ x => ['y'] }, hash { field a => in_set(DNE(), 'b'); field x => bag { item in_set('y', 'z') }; } ); like $o, hash { field a => in_set(DNE(), 'b'); field x => [ in_set('y', 'z') ]; };

How to do the comparison with Test::Deep? I tried adding another noclass to the value, or even noclass(useclass(...)), but it always failed similarly.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Test::Deep::noclass propagation by choroba

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.