I asked about this on IRC today, nwetters alerted me to the existence of the 'fail' method in Test::More, and eventually I came up with a solution that seems to work pretty well, so I'm posting it here now so you can all tell me whether there's a better way to do it.
I wanted a test that's like use_ok, but which fails if any warnings (such as that below in [0]) come up during the 'use'. But I only wanted it to fail once, however many warnings I got, and I wanted it to pass (as opposed to not be run) if I got no warnings. This is what I did: ---------------------------------------------------------------------- #!/usr/bin/perl -w use strict; use Test::More tests => 1; my $done_test; eval { local $SIG{__WARN__} = sub { fail("use My::Module throws no warnings"); $SIG{__WARN__} = sub { }; $done_test = 1; }; require My::Module; }; pass("use My::Module throws no warnings") unless $done_test; ---------------------------------------------------------------------- Good? Bad? Ugly? Kake [0] In case anyone's interested, and just for completeness of background story, this desire was sparked by getting: defined(%hash) is deprecated at ../lib/My/Module.pm line 281. (Maybe you should just omit the defined()?) -- http://www.earth.li/~kake/cookery/ - vegan recipes, now with new search feature http://grault.net/grubstreet/ - the open-source guide to London http://www.penseroso.com/ - websites for the fine art and antique trade