Permalink
Browse files

* cmp_ok() now reports warnings and errors as coming from inside cmp…

…_ok,

      as well as reporting the caller's file and line.  This let's the user
      know where cmp_ok() was called from while reminding them that it is
      being run in a different context.

Also change caller() to always return the top of the stack if it goes
too high.  This will solve a lot of issues where $Level isn't set right.
  • Loading branch information...
1 parent 9c56ac7 commit e64a3356008c87e6e9e03c6fc6baf11fd15a6953 @schwern schwern committed Oct 23, 2008
Showing with 23 additions and 11 deletions.
  1. +6 −0 Changes
  2. +13 −7 lib/Test/Builder.pm
  3. +1 −1 t/fail-more.t
  4. +3 −3 t/undef.t
View
@@ -9,6 +9,12 @@
[rt.cpan.org 24186] [code.google.com 16]
* diag() properly escapes blank lines.
+ Feature Changes
+ * cmp_ok() now reports warnings and errors as coming from inside cmp_ok,
+ as well as reporting the caller's file and line. This let's the user
+ know where cmp_ok() was called from while reminding them that it is
+ being run in a different context.
+
0.84 Wed Oct 15 09:06:12 EDT 2008
Other
View
@@ -707,13 +707,12 @@ sub cmp_ok {
local( $@, $!, $SIG{__DIE__} ); # isolate eval
- my $code = $self->_caller_context;
+ my($pack, $file, $line) = $self->caller();
- # Yes, it has to look like this or 5.4.5 won't see the #line
- # directive.
- # Don't ask me, man, I just work here.
- $test = eval "
-$code" . "\$got $type \$expect;";
+ $test = eval qq[
+#line 1 "cmp_ok [from $file line $line]"
+\$got $type \$expect;
+];
$error = $@;
}
local $Level = $Level + 1;
@@ -1842,13 +1841,20 @@ Like the normal caller(), except it reports according to your level().
C<$height> will be added to the level().
+If caller() winds up off the top of the stack it report the highest context.
+
=cut
sub caller { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
my( $self, $height ) = @_;
$height ||= 0;
- my @caller = CORE::caller( $self->level + $height + 1 );
+ my $level = $self->level + $height + 1;
+ my @caller;
+ do {
+ @caller = CORE::caller( $level );
+ $level--;
+ } until @caller;
return wantarray ? @caller : $caller[0];
}
View
@@ -291,7 +291,7 @@ ERR
# expected: foo
ERR
My::Test::like $warnings,
- qq[/^Argument "foo" isn't numeric in .* at $Filename line 211\\\.\n\$/];
+ qr/^Argument "foo" isn't numeric in .* at cmp_ok \[from $Filename line 211\] line 1\.\n$/;
}
View
@@ -32,7 +32,7 @@ sub warnings_is {
}
sub warnings_like {
- $TB->like($warnings, "/$_[0]/");
+ $TB->like($warnings, $_[0]);
$warnings = '';
}
@@ -54,7 +54,7 @@ Test::More->builder->isnt_num(23, undef, 'isnt_num()');
#line 45
like( undef, '/.*/', 'undef is like anything' );
-warnings_like("Use of uninitialized value.* at $Filename line 45\\.\n");
+warnings_like(qr/Use of uninitialized value.* at $Filename line 45\.\n/);
eq_array( [undef, undef], [undef, 23] );
no_warnings;
@@ -74,7 +74,7 @@ no_warnings;
#line 64
cmp_ok( undef, '<=', 2, ' undef <= 2' );
-warnings_like("Use of uninitialized value.* at $Filename line 64\\.\n");
+warnings_like(qr/Use of uninitialized value.* at cmp_ok \[from $Filename line 64\] line 1\.\n/);

0 comments on commit e64a335

Please sign in to comment.