Michael G Schwern wrote at Sun, 07 Jul 2002 04:06:02 +0200: > 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.
Yep. > 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: That's it. I'll adopt your idea. > > warn_is { foo() } '', 'no warnings from foo'; warn_is { foo() } undef, 'no warnings from foo'; has the same idea, but reads better to me. As I wanted to write warns_ok as a shortcut of the sentence "It warns, ok ?", I think to a more readable version than warn_is: "warning_is". (The 3 extra letters won't kill as, but from my point of view it reads better, doesn't it ?) I also have to think that more than one warning in a subroutine is possible. So I think to method names like warning_is BLOCK STRING, [TEST_NAME] warnings_are BLOCK \(STRING1, STRING2, ...), [TEST_NAME] warning_like BLOCK REGEX, [TEST_NAME] warnings_like BLOCK \(REGEX1, REGEX2, ...), [TEST_NAME] Thanks a lot for the suggestions, Janek