This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
SV-based interfaces for dieing and warning
[perl5.git] / t / op / warn.t
CommitLineData
c5df3096
Z
1#!./perl
2#line 3 warn.t
3
4print "1..18\n";
5my $test_num = 0;
6sub ok {
7 print $_[0] ? "" : "not ", "ok ", ++$test_num, "\n";
8}
9
10my @warnings;
11my $wa = []; my $ea = [];
12$SIG{__WARN__} = sub { push @warnings, $_[0] };
13
14@warnings = ();
15$@ = "";
16warn "foo\n";
17ok @warnings==1 && $warnings[0] eq "foo\n";
18
19@warnings = ();
20$@ = "";
21warn "foo", "bar\n";
22ok @warnings==1 && $warnings[0] eq "foobar\n";
23
24@warnings = ();
25$@ = "";
26warn "foo";
27ok @warnings==1 && $warnings[0] eq "foo at warn.t line 26.\n";
28
29@warnings = ();
30$@ = "";
31warn $wa;
32ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $wa;
33
34@warnings = ();
35$@ = "";
36warn "";
37ok @warnings==1 &&
38 $warnings[0] eq "Warning: something's wrong at warn.t line 36.\n";
39
40@warnings = ();
41$@ = "";
42warn;
43ok @warnings==1 &&
44 $warnings[0] eq "Warning: something's wrong at warn.t line 42.\n";
45
46@warnings = ();
47$@ = "ERR\n";
48warn "foo\n";
49ok @warnings==1 && $warnings[0] eq "foo\n";
50
51@warnings = ();
52$@ = "ERR\n";
53warn "foo", "bar\n";
54ok @warnings==1 && $warnings[0] eq "foobar\n";
55
56@warnings = ();
57$@ = "ERR\n";
58warn "foo";
59ok @warnings==1 && $warnings[0] eq "foo at warn.t line 58.\n";
60
61@warnings = ();
62$@ = "ERR\n";
63warn $wa;
64ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $wa;
65
66@warnings = ();
67$@ = "ERR\n";
68warn "";
69ok @warnings==1 &&
70 $warnings[0] eq "ERR\n\t...caught at warn.t line 68.\n";
71
72@warnings = ();
73$@ = "ERR\n";
74warn;
75ok @warnings==1 &&
76 $warnings[0] eq "ERR\n\t...caught at warn.t line 74.\n";
77
78@warnings = ();
79$@ = $ea;
80warn "foo\n";
81ok @warnings==1 && $warnings[0] eq "foo\n";
82
83@warnings = ();
84$@ = $ea;
85warn "foo", "bar\n";
86ok @warnings==1 && $warnings[0] eq "foobar\n";
87
88@warnings = ();
89$@ = $ea;
90warn "foo";
91ok @warnings==1 && $warnings[0] eq "foo at warn.t line 90.\n";
92
93@warnings = ();
94$@ = $ea;
95warn $wa;
96ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $wa;
97
98@warnings = ();
99$@ = $ea;
100warn "";
101ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $ea;
102
103@warnings = ();
104$@ = $ea;
105warn;
106ok @warnings==1 && ref($warnings[0]) eq "ARRAY" && $warnings[0] == $ea;
107
1081;