[pm-h] Test::Group

G. Wade Johnson gwadej at anomaly.org
Wed Aug 6 16:22:45 PDT 2008


Test::Group might be able to help with some of this.

On Wed, 6 Aug 2008 11:24:17 -0500
todd.e.rinaldo at jpmorgan.com wrote:

> 
> 
> > -----Original Message-----
> > From: houston-bounces+todd.e.rinaldo=jpmorgan.com at pm.org 
> > [mailto:houston-bounces+todd.e.rinaldo=jpmorgan.com at pm.org] 
> > On Behalf Of G. Wade Johnson
> > Sent: Tuesday, August 05, 2008 10:28 PM
> > To: houston at pm.org
> > Subject: [pm-h] Test::Group
> > 
> > 
> > If you haven't checked out the module Test::Group, it's definitely
> > worth a look. The feature I found most interesting was 
> > described in the
> > section of the docs labelled Reflexivity.
> > 
> > This allows you to easily build new test predicates that 
> > internally can
> > use all of the normal Test::More predicates, but only count 
> > as a single
> > test.
> > 
> > Pretty nice for testing complex objects.
> > 
> > G. Wade
> 
> 
> I like it but it doesn't solve my largest problem, which is testing
> failures on an object. I keep finding myself doing the following ALOT
> 
> 1. Manufacture datastructure I expect to fail
> 2. call sub (sometimes with an eval around it)
> 3. Test ref type for return (possibly multiple if it's an array)
> 4. test result value(s)
> 5. test $@ for expected result
> 6. Clear $@

sub call_fails
{
   my $code = shift;
   my $return_type = shift;
   my $exception = shift;

   test 'call_fails' => sub {
	local $@;
	eval {
            my $ret = $code->();
	    isa_ok( $ret, $return_type );
        };
	is( $@, $exception ) if $@;
   };
}

call_fails( \&failing_sub, 'BadResult', 'The method failed' );

This counts as one test and does one of two tests.

G. Wade

> 
> Makes a single test ugly, but I'm not sure if Test::group solves this
> problem. Does anyone know of any modules that would fix this problem?
> Generally, this communication is for informational purposes only
> and it is not intended as an offer or solicitation for the purchase
> or sale of any financial instrument or as an official confirmation
> of any transaction. In the event you are receiving the offering
> materials attached below related to your interest in hedge funds or
> private equity, this communication may be intended as an offer or
> solicitation for the purchase or sale of such fund(s).  All market
> prices, data and other information are not warranted as to
> completeness or accuracy and are subject to change without notice.
> Any comments or statements made herein do not necessarily reflect
> those of JPMorgan Chase & Co., its subsidiaries and affiliates.
> 
> This transmission may contain information that is privileged,
> confidential, legally privileged, and/or exempt from disclosure
> under applicable law. If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or
> use of the information contained herein (including any reliance
> thereon) is STRICTLY PROHIBITED. Although this transmission and any
> attachments are believed to be free of any virus or other defect
> that might affect any computer system into which it is received and
> opened, it is the responsibility of the recipient to ensure that it
> is virus free and no responsibility is accepted by JPMorgan Chase &
> Co., its subsidiaries and affiliates, as applicable, for any loss
> or damage arising in any way from its use. If you received this
> transmission in error, please immediately contact the sender and
> destroy the material in its entirety, whether in electronic or hard
> copy format. Thank you.
> Please refer to http://www.jpmorgan.com/pages/disclosures for
> disclosures relating to UK legal entities.
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/


-- 
Make no decision out of fear.                      -- Bruce Sterling


More information about the Houston mailing list