Subject: | [PATCH] DumpLex tests |
DumpLex is a little bit buggy. It does not print the lexical name for
simple scalars. It spews warnings, same problem as in bug #28053.
Fix with tests attached.
Subject: | 0001-DumpLex-tests.patch |
From f9cfca44401cf596516a68fbf255cc1445ea4390 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Lars=20D=C9=AA=E1=B4=87=E1=B4=84=E1=B4=8B=E1=B4=8F=E1=B4=A1?= <daxim@cpan.org>
Date: Fri, 27 Mar 2009 11:43:43 +0100
Subject: [PATCH] DumpLex tests
---
lib/Data/Dump/Streamer.pm | 4 ++--
t/dumplex.t | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 t/dumplex.t
diff --git a/lib/Data/Dump/Streamer.pm b/lib/Data/Dump/Streamer.pm
index d843fd6..6a1215b 100644
--- a/lib/Data/Dump/Streamer.pm
+++ b/lib/Data/Dump/Streamer.pm
@@ -1173,7 +1173,7 @@ sub DumpLex {
return $obj;
} else {
$obj||=__PACKAGE__;
- return $obj->Data(@_)->Names(@names)->Out();
+ return $obj->Names(@names)->Data(@_)->Out();
}
}
@@ -3003,7 +3003,7 @@ sub Names {
Carp::confess "Bad name '$_'"
if $s && $s!~/^\*?\w+$/;
$s
- } @$v ];
+ } grep {defined} @$v ];
return $self;
} elsif (! defined wantarray ) {
$self->{unames}=[];
diff --git a/t/dumplex.t b/t/dumplex.t
new file mode 100644
index 0000000..6019e98
--- /dev/null
+++ b/t/dumplex.t
@@ -0,0 +1,20 @@
+use Test::More;
+my $have_padwalker = eval q(use PadWalker '1'; 1;);
+my $have_tnw = eval q(use Test::NoWarnings; 1;);
+if ($have_padwalker) {
+ plan tests => 2;
+} else {
+ plan skip_all => 'DumpLex requires PadWalker => 1.0';
+};
+
+use Data::Dump::Streamer;
+
+my $foo = "bar";
+is DumpLex($foo)->Out, q($foo = 'bar';) . "\n",
+ 'lexical name instead of generic $VAR1';
+
+SKIP: {
+ skip 'requires Test::NoWarnings', 1 unless $have_tnw;
+ diag q(provoke 'uninitialized' warning like bug 28053);
+ diag DumpLex([[q(), undef]]);
+};
--
1.6.1.3