Skip to content
This repository
Browse code

Make throws_ok() report the correct line number.

  • Loading branch information...
commit 9926aef46f341a5fc3eba7a07a150cc9bef1e997 1 parent f84468b
Michael G. Schwern authored December 01, 2011

Showing 1 changed file with 7 additions and 4 deletions. Show diff stats Hide diff stats

  1. 11  t/lib/Test/perl5i.pm
11  t/lib/Test/perl5i.pm
@@ -3,7 +3,7 @@ package Test::perl5i;
3 3
 use strict;
4 4
 use warnings;
5 5
 
6  
-use Test::More;
  6
+use Test::More ();
7 7
 
8 8
 use base qw(Exporter);
9 9
 our @EXPORT = qw(throws_ok dies_ok lives_ok);
@@ -14,17 +14,20 @@ our @EXPORT = qw(throws_ok dies_ok lives_ok);
14 14
 # Could use Test::Exception::LessClever but that's not testing on Windows
15 15
 sub throws_ok(&$;$) {
16 16
     my($code, $regex, $name) = @_;
  17
+
  18
+    my $tb = Test::More->builder;
  19
+
17 20
     my $lived = eval { $code->(); 1 };
18 21
     if( $lived ) {
19  
-        fail($name);
20  
-        diag("It lived when it should have died");
  22
+        $tb->ok(0, $name);
  23
+        $tb->diag("It lived when it should have died");
21 24
     }
22  
-    my $tb = Test::More->builder;
23 25
     return $tb->like($@, $regex, $name);
24 26
 }
25 27
 
26 28
 sub dies_ok(&;$) {
27 29
     my($code, $name) = @_;
  30
+
28 31
     my $lived = eval { $code->(); 1 };
29 32
 
30 33
     my $tb = Test::More->builder;

0 notes on commit 9926aef

Please sign in to comment.
Something went wrong with that request. Please try again.