Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created March 7, 2015 04:01
Show Gist options
  • Save dagolden/5df0dfe553a5848cfa38 to your computer and use it in GitHub Desktop.
Save dagolden/5df0dfe553a5848cfa38 to your computer and use it in GitHub Desktop.
diff --git a/lib/Test/Fatal.pm b/lib/Test/Fatal.pm
index 97cb69f..0c53ba7 100644
--- a/lib/Test/Fatal.pm
+++ b/lib/Test/Fatal.pm
@@ -36,6 +36,12 @@ with about the same amount of typing.
It exports one routine by default: C<exception>.
+NOTE: C<exception> intentionally does not manipulate the call stack.
+User-written test functions that use C<exception> must be careful to avoid
+false positives if exceptions use stack traces that show arguments. For a more
+magical approach involving globally overriding C<caller>, see
+L<Test::Exception>.
+
=cut
use Carp ();
@@ -87,6 +93,17 @@ regex. Instead, write this:
like( exception { ... }, qr/foo/, 'foo appears in the exception' );
+If you really want a test function that passes the test name, wrap the
+arguments in an array reference to hide the literal text from a stack trace:
+
+ sub exception_like(&$) {
+ my ($code, $args) = @_;
+ my ($pattern, $name) = @$args;
+ like( &exception($code), $pattern, $name );
+ }
+
+ exception_like(sub { }, [ qr/foo/, 'foo appears in the exception' ] );
+
B<Achtung>: One final bad idea:
isnt( exception { ... }, undef, "my code died!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment