Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
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 2 changed files with 18 additions and 4 deletions. Show diff stats Hide diff stats

  1. 3  Changes
  2. 19  lib/Test/Fatal.pm
3  Changes
@@ -2,6 +2,9 @@ Revision history for {{$dist->name}}
2 2
 
3 3
 {{$NEXT}}
4 4
 
  5
+0.009     2012-02-09 15:26:11 America/New_York
  6
+          advise against using isnt(exception{...},undef)
  7
+
5 8
 0.008     2011-11-06 21:10:14 America/New_York
6 9
           no changes since 0.007
7 10
 
19  lib/Test/Fatal.pm
@@ -16,10 +16,10 @@ package Test::Fatal;
16 16
     "the code lived",
17 17
   );
18 18
 
19  
-  isnt(
  19
+  like(
20 20
     exception { might_die; },
21  
-    undef,
22  
-    "the code died",
  21
+    qr/turns out it died/,
  22
+    "the code died as expected",
23 23
   );
24 24
 
25 25
   isa_ok(
@@ -53,7 +53,7 @@ our @EXPORT_OK = qw(exception success dies_ok lives_ok);
53 53
 C<exception> takes a bare block of code and returns the exception thrown by
54 54
 that block.  If no exception was thrown, it returns undef.
55 55
 
56  
-B<ACHTUNG!>  If the block results in a I<false> exception, such as 0 or the
  56
+B<Achtung!>  If the block results in a I<false> exception, such as 0 or the
57 57
 empty string, Test::Fatal itself will die.  Since either of these cases
58 58
 indicates a serious problem with the system under testing, this behavior is
59 59
 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:
82 82
   my $exception = exception { ... };
83 83
   like( $exception, qr/foo/, "foo appears in the exception" );
84 84
 
  85
+B<Achtung>: One final bad idea:
  86
+
  87
+  isnt( exception { ... }, undef, "my code died!");
  88
+
  89
+It's true that this tests that your code died, but you should really test that
  90
+it died I<for the right reason>.  For example, if you make an unrelated mistake
  91
+in the block, like using the wrong dereference, your test will pass even though
  92
+the code to be tested isn't really run at all.  If you're expecting an
  93
+inspectable exception with an identifier or class, test that.  If you're
  94
+expecting a string exception, consider using C<like>.
  95
+
85 96
 =cut
86 97
 
87 98
 sub exception (&) {

No commit comments for this range

Something went wrong with that request. Please try again.