On Thu, Jun 27, 2002 at 04:32:31PM +0200, Janek Schleicher wrote: > I couldn't find a module doing this job on CPAN, > so I'm ready to write a Test::Warn module. > > I thought that two methods should be implemented: > warns_ok BLOCK REGEX, TEST_NAME (regex and test_name are optional) > no_warns_ok BLOCK TEST_NAME (test_name is optional) > > (similar to throws_ok and lives_ok from Test::Exception)
You have to be extra careful about preserving the call stack, since the BLOCK is called inside warns_ok() as a subroutine. Consider: # line 5 "foo.pl" warns_ok { warn "Foo" } /^Foo in foo.pl at line 5$/; Gotta make sure this comes out ok. Test::Exception does this using Sub::Uplevel. Rather than restricting it to a regex, you might want to write functions analgous to Test::More: warn_is BLOCK STRING, [TEST_NAME] warn_like BLOCK REGEX, [TEST_NAME] this also eliminates the awkward "no_warns_ok". Instead, you just do: warn_is { foo() } '', 'no warnings from foo'; -- This sig file temporarily out of order.