require './test.pl';
}
-plan 18;
+plan 30;
my @warnings;
my $wa = []; my $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);
+fresh_perl_like(
+ '
+ $a = "\xee\n";
+ print STDERR $a; warn $a;
+ utf8::upgrade($a);
+ print STDERR $a; warn $a;
+ ',
+ qr/^\xc3\xae(?:\r?\n\xc3\xae){3}/,
+ { switches => ['-CE'] },
+ 'warn respects :utf8 layer'
+);
+}
+
+fresh_perl_like(
+ 'warn chr 300',
+ qr/^Wide character in warn .*\n\xc4\xac 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';
+
1;