Skip to content

Commit 5d584a7

Browse files
committed
Some tidying of lib/B/Deparse.t
Standardize on 4 wordspaces for tabs -- but keep some all-whitespace lines where that was part of the plan to exercise Deparse edge cases. Lexicalize $b to avoid confusion with the special $b for sort. Remove one outdated comment.
1 parent a1489e1 commit 5d584a7

File tree

1 file changed

+44
-46
lines changed

1 file changed

+44
-46
lines changed

lib/B/Deparse.t

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,42 @@ $/ = "\n####\n";
2626
while (<DATA>) {
2727
chomp;
2828
$tests ++;
29-
# This code is pinched from the t/lib/common.pl for TODO.
30-
# It's not clear how to avoid duplication
3129
my %meta = (context => '');
3230
foreach my $what (qw(skip todo context options)) {
33-
s/^#\s*\U$what\E\s*(.*)\n//m and $meta{$what} = $1;
34-
# If the SKIP reason starts ? then it's taken as a code snippet to
35-
# evaluate. This provides the flexibility to have conditional SKIPs
36-
if ($meta{$what} && $meta{$what} =~ s/^\?//) {
37-
my $temp = eval $meta{$what};
38-
if ($@) {
39-
die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
40-
}
41-
$meta{$what} = $temp;
42-
}
31+
s/^#\s*\U$what\E\s*(.*)\n//m and $meta{$what} = $1;
32+
# If the SKIP reason starts ? then it's taken as a code snippet to
33+
# evaluate. This provides the flexibility to have conditional SKIPs
34+
if ($meta{$what} && $meta{$what} =~ s/^\?//) {
35+
my $temp = eval $meta{$what};
36+
if ($@) {
37+
die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
38+
}
39+
$meta{$what} = $temp;
40+
}
4341
}
4442

4543
s/^\s*#\s*(.*)$//mg;
4644
my $desc = $1;
4745
die "Missing name in test $_" unless defined $desc;
4846

4947
if ($meta{skip}) {
50-
SKIP: { skip($meta{skip}) };
51-
next;
48+
SKIP: { skip($meta{skip}) };
49+
next;
5250
}
5351

5452
my ($input, $expected);
5553
if (/(.*)\n>>>>\n(.*)/s) {
56-
($input, $expected) = ($1, $2);
54+
($input, $expected) = ($1, $2);
5755
}
5856
else {
59-
($input, $expected) = ($_, $_);
57+
($input, $expected) = ($_, $_);
6058
}
6159

6260
# parse options if necessary
6361
my $deparse = $meta{options}
64-
? $deparse{$meta{options}} ||=
65-
B::Deparse->new(split /,/, $meta{options})
66-
: $deparse;
62+
? $deparse{$meta{options}} ||=
63+
B::Deparse->new(split /,/, $meta{options})
64+
: $deparse;
6765

6866
my $code = "$meta{context};\n" . <<'EOC' . "sub {$input\n}";
6967
# Tell B::Deparse about our ambient pragmas
@@ -73,17 +71,17 @@ EOC
7371

7472
local $::TODO = $meta{todo};
7573
if ($@) {
76-
is($@, "", "compilation of $desc")
74+
is($@, "", "compilation of $desc")
7775
or diag "=============================================\n"
7876
. "CODE:\n--------\n$code\n--------\n"
7977
. "=============================================\n";
8078
}
8179
else {
82-
my $deparsed = $deparse->coderef2text( $coderef );
83-
my $regex = $expected;
84-
$regex =~ s/(\S+)/\Q$1/g;
85-
$regex =~ s/\s+/\\s+/g;
86-
$regex = '^\{\s*' . $regex . '\s*\}$';
80+
my $deparsed = $deparse->coderef2text( $coderef );
81+
my $regex = $expected;
82+
$regex =~ s/(\S+)/\Q$1/g;
83+
$regex =~ s/\s+/\\s+/g;
84+
$regex = '^\{\s*' . $regex . '\s*\}$';
8785

8886
like($deparsed, qr/$regex/, $desc)
8987
or diag "=============================================\n"
@@ -115,9 +113,9 @@ my $path = join " ", map { qq["-I$_"] } @INC;
115113

116114
$a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
117115
$a =~ s/-e syntax OK\n//g;
118-
$a =~ s/.*possible typo.*\n//; # Remove warning line
119-
$a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
120-
$b = quotemeta <<'EOF';
116+
$a =~ s/.*possible typo.*\n//; # Remove warning line
117+
$a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
118+
my $b = quotemeta <<'EOF';
121119
BEGIN { $^I = ".bak"; }
122120
BEGIN { $^W = 1; }
123121
BEGIN { $/ = "\n"; $\ = "\n"; }
@@ -178,7 +176,7 @@ sub test {
178176
my $val = shift;
179177
my $res = B::Deparse::Wrapper::getcode($val);
180178
like($res, qr/use warnings/,
181-
'[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
179+
'[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
182180
}
183181
my ($q,$p);
184182
my $x=sub { ++$q,++$p };
@@ -267,15 +265,15 @@ unlike($a, qr/BEGIN/,
267265
SKIP: {
268266
skip "requires 5.11", 1 unless $] >= 5.011;
269267
eval q`
270-
BEGIN {
271-
# Clear out all hints
272-
%^H = ();
273-
$^H = 0;
274-
B::Deparse->new->ambient_pragmas(strict => 'all');
275-
}
276-
use 5.011; # should enable strict
277-
ok !eval '$do_noT_create_a_variable_with_this_name = 1',
278-
'ambient_pragmas do not mess with compiling scope';
268+
BEGIN {
269+
# Clear out all hints
270+
%^H = ();
271+
$^H = 0;
272+
B::Deparse->new->ambient_pragmas(strict => 'all');
273+
}
274+
use 5.011; # should enable strict
275+
ok !eval '$do_noT_create_a_variable_with_this_name = 1',
276+
'ambient_pragmas do not mess with compiling scope';
279277
`;
280278
}
281279

@@ -713,15 +711,15 @@ $test /= 2 if ++$test;
713711
# lvalue sub
714712
{
715713
my $test = sub : lvalue {
716-
my $x;
714+
my $x;
717715
}
718716
;
719717
}
720718
####
721719
# method
722720
{
723721
my $test = sub : method {
724-
my $x;
722+
my $x;
725723
}
726724
;
727725
}
@@ -1372,8 +1370,8 @@ no warnings;
13721370
foreach (0..3) {
13731371
my $x = 2;
13741372
{
1375-
my $x if 0;
1376-
print ++$x, "\n";
1373+
my $x if 0;
1374+
print ++$x, "\n";
13771375
}
13781376
}
13791377
####
@@ -1505,7 +1503,7 @@ print /a/u, s/b/c/u;
15051503
}
15061504
{
15071505
BEGIN { $^H{'reflags'} = '0';
1508-
$^H{'reflags_charset'} = '2'; }
1506+
$^H{'reflags_charset'} = '2'; }
15091507
print /a/d, s/b/c/d;
15101508
}
15111509
{
@@ -1696,7 +1694,7 @@ s/@a(??{ die $b; })//;
16961694
####
16971695
# /(?x)<newline><tab>/
16981696
/(?x)
1699-
/;
1697+
/;
17001698
####
17011699
# y///r
17021700
tr/a/b/r + $a =~ tr/p/q/r;
@@ -2265,7 +2263,7 @@ my sub f {}
22652263
print f();
22662264
>>>>
22672265
my sub f {
2268-
2266+
22692267
}
22702268
print f();
22712269
####
@@ -2277,7 +2275,7 @@ state sub f {}
22772275
print f();
22782276
>>>>
22792277
state sub f {
2280-
2278+
22812279
}
22822280
print f();
22832281
####

0 commit comments

Comments
 (0)