Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Bad test functions in Test::Exception: msg#00228

lang.perl.quality-assurance

Subject: Re: Bad test functions in Test::Exception

Subject: Bad test functions in Test::Exception
From: Nadim Khemir <nadim@xxxxxxxxxx>
Date: Tue, 30 Jan 2007 18:17:38 +0100

}I like Test::Exception, it's a very fundamental test module with
}Text::NoWarning, Test::Deep and other goodies. Still, I believe some of the
}functions made available should not be there at all.

Not everyone uses Perl the way you do. Different people have needs for
different functions. Saying "I don't use this and can't think of a reason
for it, so get rid of it" makes a lot of assumptions, many of which
probably aren't true.

} # Check that something died
} dies_ok { $foo->method1 } 'expecting to die';
}
}Am I the only one who got this to pass, to find out later that what cause the
}error had nothing to do with the message I displayed.

No, you're not - but shunning all possible uses of dies_ok becasue you
didn't write a test as complete as you could have isn't the fault of
Test::Exception.

How about code that dies with an object? dies_ok lets you inspect the
object in $@, whereas throws_ok only lets you see if it's part of a class.
What if you want to see if $@ meets multiple criteria? There's plenty of
valid cases where throws_ok just isn't enough.

And finally, what if I truly don't care why something dies, just that it
did? Why should I be penalized for writing *any* test?

} # Check that something did not die
} lives_ok { $foo->method2 } 'expecting to live';
}
}Is the above realy a test? Ok but testing what? why wouldn't we wrap all our
}test in lives_ok? No, I don't think lives_ok makes any sense. I'd be very
}happy to see real examples of lives_ok that add anything to a test suite.

I have this in the production code where I work, and it's very necessary.
If you have an interface that requires you to die on invalid input, it's a
life-saver, especially during debugging. While I won't paste code from my
work here, consider your exact case:

} # Check that a test runs without an exception
} lives_and { is $foo->method, 42 } 'method is 42';
}Isn't this equivalent to is($foo->method, 42 , 'method is 42') ?

No! If the latter fails, the test stops where it is, and no further tests
proceed. If the former fails, it's another 'nok' to investigate, but the
rest of your tests have an opportunity to run.

}I postulate that Test::Exception would be even better if we removed the bad
}guys.

And I postulate that you're not willing to change all the code in the
world that uses them, for reasons I've stated above and more.

Besides which, if you remove those functions, people will either stop
using the module (and possibly stop testing as much) or will invoke the
laziness part of Perl and do this:

throws_ok { $foo->method } qr//, 'method dies'

People have personal and organizational code standards to meet, and that's
to be expected. Be sure to update yours to the things you've mentioned.
TIMTOWTDI rules here, though, and PBP isn't a rulebook - it's a set of
guidelines that work for Damian. Other people use them to varying
degrees, and P::C even implements them, but at some point, people are on
their own.

-Pete K
--
Pete Krawczyk
perl at bsod dot net



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
user-groups.jax...    php.zend.framew...    os.solaris.open...    web.quixote.use...    java.openjdk.ho...    ietf.secmech/20...    gnu.glpk/2004-0...    recreation.cars...    network.smokepi...    linux.drivers.i...    cms.opencms.dev...    fonts.gfontview...    text.xml.soap.u...    voip.nist-sip/2...    debian.ports.hp...    xfree86.interna...    science.biology...    qnx.openqnx.dev...    mail.sylpheed.c...    busybox/bios/20...    emulators.kvm.s...    hardware.openco...    apple.fink.begi...    kde.german/2006...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation