Test::Class would be one solution. Something like this should do the job (untested code):

{ package BlahBlah::Test; use base qw(Test::Class); sub test_object_emit { my ($self, $test_object, $emit_method) = @_; my $ot = output_test->new( $self->current_method ); my $outfile = $ot->openout(); $test_object->$emit_method($outfile); $ot->ok_files_match(); }; sub out1 : Test(tests => 4) { my $self = shift; my $x = new BlahBlah $x->foo(5000); $x->bar(200); $self->test_object_emit($x, "emit"); }; sub out2 : Test(tests => 4) { my $self = shift; my $x = new Fribble $x->ni(12); $self->test_object_emit($x, "super_emit"); }; # ... etc ... }; BlahBlah::Test->runtests;

We name our test methods after each output_test. Since $self->current_method returns the name of the running test method we can use this to create the appropriate output_test object in test_object_emit.

It you die in a Test::Class test method the remaining tests in that method are automatically failed. So if anything in test_object_emit dies all the tests in the calling test method will fail, and you'll go on to the next test case (aka method).

I'm assuming that ok_files_match runs four tests (hence the tests => 4).


In reply to Re: Writing code using Test::More -- how to fail within subs? by adrianh
in thread Writing code using Test::More -- how to fail within subs? by John M. Dlugosz

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.