1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
#!./perl
#line 3 warn.t
BEGIN {
chdir 't' if -d 't';
require './test.pl';
set_up_inc('../lib');
require './charset_tools.pl';
}
plan 34;
my @warnings;
my $wa = []; my $ea = [];
$SIG{__WARN__} = sub { push @warnings, $_[0] };
@warnings = ();
$@ = "";
warn "foo\n";
ok @warnings==1 && $warnings[0] eq "foo\n";
@warnings = ();
$@ = "";
warn "foo", "bar\n";
ok @warnings==1 && $warnings[0] eq "foobar\n";
@warnings = ();
$@ = "";
warn "foo";
ok @warnings==1 && $warnings[0] eq "foo at warn.t line 29.\n";
@warnings = ();
$@ = "";
warn $wa;
ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $wa;
@warnings = ();
$@ = "";
warn "";
ok @warnings==1 &&
$warnings[0] eq "Warning: something's wrong at warn.t line 39.\n";
@warnings = ();
$@ = "";
warn;
ok @warnings==1 &&
$warnings[0] eq "Warning: something's wrong at warn.t line 45.\n";
@warnings = ();
$@ = "ERR\n";
warn "foo\n";
ok @warnings==1 && $warnings[0] eq "foo\n";
@warnings = ();
$@ = "ERR\n";
warn "foo", "bar\n";
ok @warnings==1 && $warnings[0] eq "foobar\n";
@warnings = ();
$@ = "ERR\n";
warn "foo";
ok @warnings==1 && $warnings[0] eq "foo at warn.t line 61.\n";
@warnings = ();
$@ = "ERR\n";
warn $wa;
ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $wa;
@warnings = ();
$@ = "ERR\n";
warn "";
ok @warnings==1 &&
$warnings[0] eq "ERR\n\t...caught at warn.t line 71.\n";
@warnings = ();
$@ = "ERR\n";
warn;
ok @warnings==1 &&
$warnings[0] eq "ERR\n\t...caught at warn.t line 77.\n";
@warnings = ();
$@ = $ea;
warn "foo\n";
ok @warnings==1 && $warnings[0] eq "foo\n";
@warnings = ();
$@ = $ea;
warn "foo", "bar\n";
ok @warnings==1 && $warnings[0] eq "foobar\n";
@warnings = ();
$@ = $ea;
warn "foo";
ok @warnings==1 && $warnings[0] eq "foo at warn.t line 93.\n";
@warnings = ();
$@ = $ea;
warn $wa;
ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $wa;
@warnings = ();
$@ = $ea;
warn "";
ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $ea;
@warnings = ();
$@ = $ea;
warn;
ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $ea;
fresh_perl_like(
'
$a = "\xee\n";
print STDERR $a; warn $a;
utf8::upgrade($a);
print STDERR $a; warn $a;
',
qr/^\xee(?:\r?\n\xee){3}/,
{ switches => [ "-C0" ] },
'warn emits logical characters, not internal bytes [perl #45549]'
);
SKIP: {
skip_if_miniperl('miniperl ignores -C', 1);
$ee = uni_to_native("\xee");
$bytes = byte_utf8a_to_utf8n("\xc3\xae");
fresh_perl_like(
"
\$a = \"$ee\n\";
print STDERR \$a; warn \$a;
utf8::upgrade(\$a);
print STDERR \$a; warn \$a;
",
qr/^$bytes(?:\r?\n$bytes){3}/,
{ switches => ['-CE'] },
'warn respects :utf8 layer'
);
}
$bytes = byte_utf8a_to_utf8n("\xc4\xac");
fresh_perl_like(
'warn chr 300',
qr/^Wide character in warn .*\n$bytes at /,
{ switches => [ "-C0" ] },
'Wide character in warn (not print)'
);
fresh_perl_like(
'warn []',
qr/^ARRAY\(0x[\da-f]+\) at /a,
{ },
'warn stringifies in the absence of $SIG{__WARN__}'
);
use Tie::Scalar;
tie $@, "Tie::StdScalar";
$@ = "foo\n";
@warnings = ();
warn;
is @warnings, 1;
like $warnings[0], qr/^foo\n\t\.\.\.caught at warn\.t /,
'...caught is appended to tied $@';
$@ = \$_;
@warnings = ();
{
local *{ref(tied $@) . "::STORE"} = sub {};
undef $@;
}
warn;
is @warnings, 1;
is $warnings[0], \$_, '!SvOK tied $@ that returns ref is used';
untie $@;
@warnings = ();
{
package o;
use overload '""' => sub { "" };
}
tie $t, Tie::StdScalar;
$t = bless [], o;
{
local *{ref(tied $t) . "::STORE"} = sub {};
undef $t;
}
warn $t;
is @warnings, 1;
object_ok $warnings[0], 'o',
'warn $tie_returning_object_that_stringifes_emptily';
@warnings = ();
eval "#line 42 Cholmondeley\n \$\@ = '3'; warn";
eval "#line 42 Cholmondeley\n \$\@ = 3; warn";
is @warnings, 2;
is $warnings[1], $warnings[0], 'warn treats $@=3 and $@="3" the same way';
fresh_perl_is(<<'EOF', "should be line 4 at - line 4.\n", {stderr => 1}, "");
${
foo
} = "should be line 4";
warn $foo;
EOF
TODO: {
local $::TODO = "Line numbers don't yet match up for \${ EXPR }";
my $expected = <<'EOF';
line 1 at - line 1.
line 4 at - line 3.
also line 4 at - line 4.
line 5 at - line 5.
EOF
fresh_perl_is(<<'EOF', $expected, {stderr => 1}, "");
warn "line 1";
(${
foo
} = "line 5") && warn("line 4"); warn("also line 4");
warn $foo;
EOF
}
1;
# RT #132602 pp_warn in scalar context was extending the stack then
# setting SP back to the old, freed stack frame
fresh_perl_is(<<'EOF', "OK\n", {stderr => 1}, "RT #132602");
$SIG{__WARN__} = sub {};
my (@a, @b);
for my $i (1..300) {
push @a, $i;
() = (@a, warn);
}
# mess with the stack some more for ASan's benefit
for my $i (1..100) {
push @a, $i;
@b = @a;
}
print "OK\n";
EOF
fresh_perl_is(<<~'EOF', "good\n", {}, "GH #22987 (warn)");
sub foo { warn "good\n" }
sub bar { { local $SIG{__WARN__}; } goto &foo }
$SIG{__WARN__} = \&bar;
warn "bad";
EOF
|