Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: 4cb18a
...
compare: 116df1
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 09, 2012
Ricardo Signes advise against isnt(e{}, undef) 97571f9
Ricardo Signes elaborate on previous advice a0a2027
Ricardo Signes v0.009
          advise against using isnt(exception{...},undef)
116df1c
Showing with 18 additions and 4 deletions.
  1. +3 −0  Changes
  2. +15 −4 lib/Test/Fatal.pm
3  Changes
View
@@ -2,6 +2,9 @@ Revision history for {{$dist->name}}
{{$NEXT}}
+0.009 2012-02-09 15:26:11 America/New_York
+ advise against using isnt(exception{...},undef)
+
0.008 2011-11-06 21:10:14 America/New_York
no changes since 0.007
19 lib/Test/Fatal.pm
View
@@ -16,10 +16,10 @@ package Test::Fatal;
"the code lived",
);
- isnt(
+ like(
exception { might_die; },
- undef,
- "the code died",
+ qr/turns out it died/,
+ "the code died as expected",
);
isa_ok(
@@ -53,7 +53,7 @@ our @EXPORT_OK = qw(exception success dies_ok lives_ok);
C<exception> takes a bare block of code and returns the exception thrown by
that block. If no exception was thrown, it returns undef.
-B<ACHTUNG!> If the block results in a I<false> exception, such as 0 or the
+B<Achtung!> If the block results in a I<false> exception, such as 0 or the
empty string, Test::Fatal itself will die. Since either of these cases
indicates a serious problem with the system under testing, this behavior is
considered a I<feature>. If you must test for these conditions, you should use
@@ -82,6 +82,17 @@ exception" will itself be matched by the regex. Instead, write this:
my $exception = exception { ... };
like( $exception, qr/foo/, "foo appears in the exception" );
+B<Achtung>: One final bad idea:
+
+ isnt( exception { ... }, undef, "my code died!");
+
+It's true that this tests that your code died, but you should really test that
+it died I<for the right reason>. For example, if you make an unrelated mistake
+in the block, like using the wrong dereference, your test will pass even though
+the code to be tested isn't really run at all. If you're expecting an
+inspectable exception with an identifier or class, test that. If you're
+expecting a string exception, consider using C<like>.
+
=cut
sub exception (&) {

No commit comments for this range

Something went wrong with that request. Please try again.