summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorMarcus Holland-Moritz <mhx-perl@gmx.net>2012-05-23 14:50:31 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-05-23 17:59:22 -0700
commit21361d0729743e699b2954b542f05a2e4eabd980 (patch)
treeb4f46494969725415a45b9c85172af1ba8cf0d24 /t
parent909564a7d63dd41ca03b7bc9659d8c7b695220d2 (diff)
downloadperl-21361d0729743e699b2954b542f05a2e4eabd980.tar.gz
[perl #60204] Unhelpful error message from unpack
Nigel Sandever said: > The error message produced by the following snippets is very unhelpful: > > c:\>perl -wle"print unpack 'v/a*', qq[a]" > '/' must follow a numeric type in unpack at -e line 1. > > c:\>perl -wle"print unpack 'v/a*', ''" > '/' must follow a numeric type in unpack at -e line 1. > > c:\>perl -wle"print unpack 'v/a*', ' '" > '/' must follow a numeric type in unpack at -e line 1. The "problem" is that the data string is too short. But unpack doesn't generate a warning (or croak) in this case for simple patterns: mhx@r2d2 $ perl -MData::Dumper -we'print Dumper([unpack "n", "a"])' $VAR1 = []; So, I'd say your code should just behave in exactly the same way. No warning, no return values.
Diffstat (limited to 't')
-rw-r--r--t/op/pack.t12
1 files changed, 10 insertions, 2 deletions
diff --git a/t/op/pack.t b/t/op/pack.t
index 43189ab538..34097adaa6 100644
--- a/t/op/pack.t
+++ b/t/op/pack.t
@@ -12,7 +12,7 @@ my $no_endianness = $] > 5.009 ? '' :
my $no_signedness = $] > 5.009 ? '' :
"Signed/unsigned pack modifiers not available on this perl";
-plan tests => 14700;
+plan tests => 14704;
use strict;
use warnings qw(FATAL all);
@@ -816,13 +816,21 @@ SKIP: {
{
# /
- my ($x, $y, $z);
+ my ($x, $y, $z, @a);
eval { ($x) = unpack '/a*','hello' };
like($@, qr!'/' must follow a numeric type!);
undef $x;
eval { $x = unpack '/a*','hello' };
like($@, qr!'/' must follow a numeric type!);
+ # [perl #60204] Unhelpful error message from unpack
+ eval { @a = unpack 'v/a*','h' };
+ is($@, '');
+ is(scalar @a, 0);
+ eval { $x = unpack 'v/a*','h' };
+ is($@, '');
+ is($x, undef);
+
undef $x;
eval { ($z,$x,$y) = unpack 'a3/A C/a* C/Z', "003ok \003yes\004z\000abc" };
is($@, '');