Skip to content

Commit 9729f84

Browse files
committed
In review, Tony Cook recommended converting two tests from 'package
block' syntax ('package Foo {}') to 'inline package' syntax ('package Foo; ...'). However, keeping these two tests in a file specifically aimed at testing package block syntax felt awkward. Since what we're now focusing on in the behavior of 'goto', these two tests were moved to the principal file testing that function. The tests were updated to use t/test.pl functions and were re-indented to make the labeling more self-documenting.
1 parent 028045f commit 9729f84

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

t/comp/package_block.t

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!./perl
22

3-
print "1..7\n";
3+
print "1..5\n";
44

55
$main::result = "";
66
eval q{
@@ -56,32 +56,4 @@ eval q{
5656
};
5757
print $main::result eq "a(2)b(4)c(6)d(8)e(10)f(12)" ? "ok 5\n" : "not ok 5\n";
5858

59-
$main::result = "";
60-
$main::warning = "";
61-
$SIG{__WARN__} = sub { $main::warning .= $_[0]; };
62-
eval q{
63-
$main::result .= "a(".__PACKAGE__."/".eval("__PACKAGE__").")";
64-
goto l0;
65-
$main::result .= "b(".__PACKAGE__."/".eval("__PACKAGE__").")";
66-
package Foo {
67-
$main::result .= "c(".__PACKAGE__."/".eval("__PACKAGE__").")";
68-
l0:
69-
$main::result .= "d(".__PACKAGE__."/".eval("__PACKAGE__").")";
70-
goto l1;
71-
$main::result .= "e(".__PACKAGE__."/".eval("__PACKAGE__").")";
72-
}
73-
$main::result .= "f(".__PACKAGE__."/".eval("__PACKAGE__").")";
74-
l1:
75-
$main::result .= "g(".__PACKAGE__."/".eval("__PACKAGE__").")";
76-
goto l2;
77-
$main::result .= "h(".__PACKAGE__."/".eval("__PACKAGE__").")";
78-
package Bar {
79-
l2:
80-
$main::result .= "i(".__PACKAGE__."/".eval("__PACKAGE__").")";
81-
}
82-
$main::result .= "j(".__PACKAGE__."/".eval("__PACKAGE__").")";
83-
};
84-
print $main::result eq "a(main/main)" ? "ok 6\n" : "not ok 6\n";
85-
print $main::warning eq '' ? "ok 7\n" : "not ok 7\n";
86-
8759
1;

t/op/goto.t

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BEGIN {
1212
use warnings;
1313
use strict;
1414
use Config;
15-
plan tests => 47;
15+
plan tests => 49;
1616

1717
our $TODO;
1818

@@ -204,7 +204,7 @@ EOT
204204
close $f;
205205

206206
$r = runperl(prog => 'BEGIN { unshift @INC, q[.] } use Op_goto01; print qq[DONE\n]');
207-
is($r, "OK\nDONE\n", "goto within use-d file");
207+
is($r, "OK\nDONE\n", "goto within use-d file");
208208
unlink_all "Op_goto01.pm";
209209

210210
# test for [perl #24108]
@@ -489,3 +489,42 @@ sub _routine {
489489
_routine();
490490
pass("bug 132799");
491491

492+
{
493+
# tests of __PACKAGE__ syntax:
494+
# 2 tests moved from t/comp/package_block.t and modified to use inline
495+
# package syntax
496+
497+
$main::result = "";
498+
$main::warning = "";
499+
$SIG{__WARN__} = sub { $main::warning .= $_[0]; };
500+
eval q{
501+
$main::result .= "a(".__PACKAGE__."/".eval("__PACKAGE__").")";
502+
goto l0;
503+
$main::result .= "b(".__PACKAGE__."/".eval("__PACKAGE__").")";
504+
505+
package Foo;
506+
$main::result .= "c(".__PACKAGE__."/".eval("__PACKAGE__").")";
507+
l0:
508+
$main::result .= "d(".__PACKAGE__."/".eval("__PACKAGE__").")";
509+
goto l1;
510+
$main::result .= "e(".__PACKAGE__."/".eval("__PACKAGE__").")";
511+
512+
package main;
513+
$main::result .= "f(".__PACKAGE__."/".eval("__PACKAGE__").")";
514+
l1:
515+
$main::result .= "g(".__PACKAGE__."/".eval("__PACKAGE__").")";
516+
goto l2;
517+
$main::result .= "h(".__PACKAGE__."/".eval("__PACKAGE__").")";
518+
519+
package Bar;
520+
l2:
521+
$main::result .= "i(".__PACKAGE__."/".eval("__PACKAGE__").")";
522+
523+
package main;
524+
$main::result .= "j(".__PACKAGE__."/".eval("__PACKAGE__").")";
525+
};
526+
my $expected = 'a(main/main)d(Foo/Foo)g(main/main)i(Bar/Bar)j(main/main)';
527+
is($main::result, $expected, "Got expected");
528+
ok(! $main::warning, "Jumping into labels in different packages ran without warnings");
529+
}
530+

0 commit comments

Comments
 (0)