This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove the warning in perlfaq about using map in void context :
[perl5.git] / t / lib / warnings / 9enabled
CommitLineData
8d93267c
GS
1Check warnings::enabled & warnings::warn
2
3__END__
4
5--FILE-- abc.pm
6package abc ;
7use warnings "io" ;
d3a7d8c7 8print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
9print "ok2\n" if ! warnings::enabled("io") ;
101;
11--FILE--
12no warnings;
13use abc ;
14EXPECT
15ok1
16ok2
17########
18
19--FILE-- abc.pm
20package abc ;
21no warnings ;
d3a7d8c7 22print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
23print "ok2\n" if warnings::enabled("syntax") ;
241;
25--FILE--
26use warnings 'syntax' ;
27use abc ;
28EXPECT
29ok1
30ok2
31########
32
33--FILE-- abc.pm
34package abc ;
35use warnings 'syntax' ;
d3a7d8c7 36print "ok1\n" if warnings::enabled('io') ;
8d93267c
GS
37print "ok2\n" if ! warnings::enabled("syntax") ;
381;
39--FILE--
40use warnings 'io' ;
41use abc ;
42EXPECT
43ok1
44ok2
45########
46
47--FILE-- abc
48no warnings ;
d3a7d8c7 49print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
50print "ok2\n" if warnings::enabled("syntax") ;
511;
52--FILE--
53use warnings 'syntax' ;
54require "abc" ;
55EXPECT
56ok1
57ok2
58########
59
60--FILE-- abc
61use warnings 'syntax' ;
d3a7d8c7 62print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
63print "ok2\n" if ! warnings::enabled("syntax") ;
64print "ok3\n" if warnings::enabled("io") ;
651;
66--FILE--
67use warnings 'io' ;
68require "abc" ;
69EXPECT
70ok1
71ok2
72ok3
73########
74
75--FILE-- abc.pm
76package abc ;
77no warnings ;
78sub check {
d3a7d8c7 79 print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
80 print "ok2\n" if warnings::enabled("syntax") ;
81}
821;
83--FILE--
84use warnings 'syntax' ;
85use abc ;
86abc::check() ;
87EXPECT
88ok1
89ok2
90########
91
92--FILE-- abc.pm
93package abc ;
94use warnings 'io' ;
95sub check {
d3a7d8c7
GS
96 print "ok1\n" if ! warnings::enabled('all') ;
97 print "ok2\n" if warnings::enabled("syntax") ;
8d93267c
GS
98 print "ok3\n" if ! warnings::enabled("io") ;
99}
1001;
101--FILE--
102use warnings 'syntax' ;
103use abc ;
104abc::check() ;
105EXPECT
106ok1
107ok2
108ok3
109########
110
111--FILE-- abc
112package abc ;
113no warnings ;
114sub check {
d3a7d8c7 115 print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
116 print "ok2\n" if warnings::enabled("syntax") ;
117}
1181;
119--FILE--
120use warnings 'syntax' ;
121require "abc" ;
122abc::check() ;
123EXPECT
124ok1
125ok2
126########
127
128--FILE-- abc
129package abc ;
130use warnings 'io' ;
131sub check {
d3a7d8c7
GS
132 print "ok1\n" if ! warnings::enabled('all') ;
133 print "ok2\n" if warnings::enabled("syntax") ;
8d93267c
GS
134 print "ok3\n" if ! warnings::enabled("io") ;
135}
1361;
137--FILE--
138use warnings 'syntax' ;
139require "abc" ;
140abc::check() ;
141EXPECT
142ok1
143ok2
144ok3
145########
146
147--FILE-- abc.pm
148package abc ;
149use warnings "io" ;
d3a7d8c7 150print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
151print "ok2\n" if ! warnings::enabled("io") ;
1521;
153--FILE-- def.pm
f89e79d6 154package def;
8d93267c
GS
155no warnings;
156use abc ;
1571;
158--FILE--
159use warnings;
160use def ;
161EXPECT
162ok1
163ok2
164########
165
166--FILE-- abc.pm
167package abc ;
168no warnings ;
d3a7d8c7 169print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
170print "ok2\n" if warnings::enabled("syntax") ;
171print "ok3\n" if !warnings::enabled("io") ;
1721;
173--FILE-- def.pm
174use warnings 'syntax' ;
d3a7d8c7 175print "ok4\n" if !warnings::enabled('all') ;
8d93267c
GS
176print "ok5\n" if warnings::enabled("io") ;
177use abc ;
1781;
179--FILE--
180use warnings 'io' ;
181use def ;
182EXPECT
183ok1
184ok2
185ok3
186ok4
187ok5
188########
189
190--FILE-- abc.pm
191package abc ;
192no warnings ;
193sub check {
d3a7d8c7 194 print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
195 print "ok2\n" if warnings::enabled("syntax") ;
196}
1971;
198--FILE--
199use warnings 'syntax' ;
200use abc ;
c3186b65
PM
201eval {
202 abc::check() ;
203};
8d93267c
GS
204print $@ ;
205EXPECT
206ok1
207ok2
208########
209
210--FILE-- abc.pm
211package abc ;
212use warnings 'io' ;
213sub check {
d3a7d8c7
GS
214 print "ok1\n" if ! warnings::enabled('all') ;
215 print "ok2\n" if warnings::enabled("syntax") ;
8d93267c
GS
216 print "ok3\n" if ! warnings::enabled("io") ;
217}
2181;
219--FILE--
220use warnings 'syntax' ;
221use abc ;
c3186b65
PM
222eval {
223 abc::check() ;
224 } ;
8d93267c
GS
225print $@ ;
226EXPECT
227ok1
228ok2
229ok3
230########
231
232--FILE-- abc
233package abc ;
234no warnings ;
235sub check {
d3a7d8c7 236 print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
237 print "ok2\n" if warnings::enabled("syntax") ;
238}
2391;
240--FILE--
241use warnings 'syntax' ;
242require "abc" ;
c3186b65
PM
243eval {
244 abc::check() ;
245 } ;
8d93267c
GS
246print $@ ;
247EXPECT
248ok1
249ok2
250########
251
252--FILE-- abc
253package abc ;
254use warnings 'io' ;
255sub check {
d3a7d8c7 256 print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
257 print "ok2\n" if warnings::enabled("syntax") ;
258 print "ok3\n" if warnings::enabled("io") ;
259}
2601;
261--FILE--
262use warnings 'syntax' ;
263require "abc" ;
c3186b65
PM
264eval {
265 use warnings 'io' ;
266 abc::check() ;
267};
8d93267c
GS
268abc::check() ;
269print $@ ;
270EXPECT
271ok1
272ok2
273ok3
274ok1
275ok2
276########
277
278--FILE-- abc.pm
279package abc ;
280use warnings 'io' ;
281sub check {
d3a7d8c7 282 print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
283 print "ok2\n" if warnings::enabled("syntax") ;
284 print "ok3\n" if ! warnings::enabled("io") ;
285}
2861;
287--FILE--
288use warnings 'syntax' ;
289use abc ;
290sub fred { abc::check() }
291fred() ;
292EXPECT
293ok1
294ok2
295ok3
296########
297
298--FILE-- abc.pm
299package abc ;
300use warnings 'io' ;
301sub check {
d3a7d8c7 302 print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
303}
3041;
305--FILE--
306use warnings 'syntax' ;
307use abc ;
308sub fred { no warnings ; abc::check() }
309fred() ;
310EXPECT
311ok1
312########
313
314--FILE-- abc.pm
315package abc ;
316use warnings 'misc' ;
317sub check {
d3a7d8c7 318 print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
319 print "ok2\n" if warnings::enabled("syntax") ;
320 print "ok3\n" if warnings::enabled("io") ;
321 print "ok4\n" if ! warnings::enabled("misc") ;
322}
3231;
324--FILE--
325use warnings 'syntax' ;
326use abc ;
327sub fred { use warnings 'io' ; abc::check() }
328fred() ;
329EXPECT
330ok1
331ok2
332ok3
333ok4
334########
335
336# check warnings::warn
337use warnings ;
c3186b65
PM
338eval {
339 warnings::warn()
340 } ;
8d93267c 341print $@ ;
c3186b65
PM
342eval {
343 warnings::warn("fred", "joe")
344 } ;
8d93267c
GS
345print $@ ;
346EXPECT
c3186b65
PM
347Usage: warnings::warn([category,] 'message') at - line 5
348Unknown warnings category 'fred' at - line 9
7e6d00f8
PM
349########
350
351# check warnings::warnif
352use warnings ;
c3186b65
PM
353eval {
354 warnings::warnif()
355} ;
7e6d00f8 356print $@ ;
c3186b65
PM
357eval {
358 warnings::warnif("fred", "joe")
359} ;
7e6d00f8
PM
360print $@ ;
361EXPECT
c3186b65
PM
362Usage: warnings::warnif([category,] 'message') at - line 5
363Unknown warnings category 'fred' at - line 9
8d93267c
GS
364########
365
366--FILE-- abc.pm
367package abc ;
368use warnings 'misc' ;
369sub check { warnings::warn("io", "hello") }
3701;
371--FILE--
372use warnings "io" ;
373use abc;
374abc::check() ;
375EXPECT
376hello at - line 3
377########
378
379--FILE-- abc.pm
380package abc ;
381use warnings 'misc' ;
382sub check { warnings::warn("misc", "hello") }
3831;
384--FILE--
385use warnings "io" ;
386use abc;
387abc::check() ;
388EXPECT
389hello at - line 3
390########
391
392--FILE-- abc.pm
393package abc ;
394use warnings 'misc' ;
395sub check { warnings::warn("io", "hello") }
3961;
397--FILE--
398use warnings qw( FATAL deprecated ) ;
399use abc;
c3186b65
PM
400eval {
401 abc::check() ;
402 } ;
8d93267c
GS
403print "[[$@]]\n";
404EXPECT
c3186b65 405hello at - line 4
8d93267c
GS
406[[]]
407########
408
409--FILE-- abc.pm
410package abc ;
411use warnings 'misc' ;
412sub check { warnings::warn("io", "hello") }
4131;
414--FILE--
415use warnings qw( FATAL io ) ;
416use abc;
c3186b65
PM
417eval {
418 abc::check() ;
419} ;
8d93267c
GS
420print "[[$@]]\n";
421EXPECT
c3186b65 422[[hello at - line 4
8d93267c 423]]
d3a7d8c7
GS
424########
425-W
426--FILE-- abc.pm
427package abc ;
428use warnings "io" ;
429print "ok1\n" if warnings::enabled("io") ;
430print "ok2\n" if warnings::enabled("all") ;
4311;
432--FILE--
433no warnings;
434use abc ;
435EXPECT
436ok1
437ok2
438########
439-X
440--FILE-- abc.pm
441package abc ;
442use warnings "io" ;
443print "ok1\n" if !warnings::enabled("io") ;
444print "ok2\n" if !warnings::enabled("all") ;
4451;
446--FILE--
447use warnings;
448use abc ;
449EXPECT
450ok1
451ok2
452########
453
454--FILE-- abc.pm
455package abc ;
456no warnings ;
457sub check {
458 print "ok\n" if ! warnings::enabled() ;
459}
4601;
461--FILE--
462use warnings 'syntax' ;
463use abc ;
464abc::check() ;
465EXPECT
7e6d00f8
PM
466package 'abc' not registered for warnings at abc.pm line 4
467########
468
469--FILE-- abc.pm
470package abc ;
471no warnings ;
472sub check {
473 warnings::warn("fred") ;
474}
4751;
476--FILE--
477use warnings 'syntax' ;
478use abc ;
479abc::check() ;
480EXPECT
481package 'abc' not registered for warnings at abc.pm line 4
482########
483
484--FILE-- abc.pm
485package abc ;
486no warnings ;
487sub check {
488 warnings::warnif("fred") ;
489}
4901;
491--FILE--
492use warnings 'syntax' ;
493use abc ;
494abc::check() ;
495EXPECT
496package 'abc' not registered for warnings at abc.pm line 4
d3a7d8c7
GS
497########
498
499--FILE-- abc.pm
500package abc ;
501use warnings 'io' ;
502use warnings::register ;
503sub check {
504 print "ok1\n" if warnings::enabled ;
505 print "ok2\n" if warnings::enabled("syntax") ;
506 print "ok3\n" if !warnings::enabled("io") ;
507}
5081;
509--FILE--
510use warnings 'syntax' ;
511use abc ;
512use warnings 'abc' ;
513abc::check() ;
514EXPECT
515ok1
516ok2
517ok3
518########
519
520--FILE-- abc.pm
521package abc ;
522use warnings 'io' ;
523use warnings::register ;
524sub check {
525 print "ok1\n" if !warnings::enabled ;
526 print "ok2\n" if warnings::enabled("syntax") ;
527 print "ok3\n" if !warnings::enabled("io") ;
528}
5291;
530--FILE--
531use warnings 'syntax' ;
532use abc ;
533abc::check() ;
534EXPECT
535ok1
536ok2
537ok3
538########
539
540--FILE-- abc.pm
541package abc ;
542no warnings ;
543use warnings::register ;
544sub check {
545 print "ok1\n" if warnings::enabled ;
546 print "ok2\n" if warnings::enabled("syntax") ;
547}
5481;
549--FILE--
550use warnings 'syntax' ;
551use abc ;
552use warnings 'abc' ;
553eval { abc::check() ; };
554print $@ ;
555EXPECT
556ok1
557ok2
558########
559
560--FILE-- abc.pm
561package abc ;
562use warnings 'io' ;
563use warnings::register ;
564sub check {
565 print "ok1\n" if !warnings::enabled ;
566 print "ok2\n" if warnings::enabled("syntax") ;
567 print "ok3\n" if !warnings::enabled("io") ;
568}
5691;
570--FILE--
571use warnings 'syntax' ;
572use abc ;
573eval { abc::check() ; } ;
574print $@ ;
575EXPECT
576ok1
577ok2
578ok3
579########
580
581--FILE-- abc.pm
582package abc ;
583use warnings 'io' ;
584use warnings::register ;
585sub check {
586 print "ok1\n" if warnings::enabled ;
587 print "ok2\n" if warnings::enabled("syntax") ;
588 print "ok3\n" if !warnings::enabled("io") ;
589}
5901;
591--FILE--
592use warnings 'syntax' ;
593use abc ;
594use warnings 'abc' ;
595sub fred { abc::check() }
596fred() ;
597EXPECT
598ok1
599ok2
600ok3
601########
602
603--FILE-- abc.pm
604package abc ;
605use warnings 'io' ;
606use warnings::register ;
607sub check {
608 print "ok1\n" if ! warnings::enabled ;
609}
6101;
611--FILE--
612use warnings 'syntax' ;
613use abc ;
614sub fred { no warnings ; abc::check() }
615fred() ;
616EXPECT
617ok1
618########
619
620--FILE-- abc.pm
621package abc ;
622use warnings 'misc' ;
623use warnings::register;
624sub check {
625 print "ok1\n" if warnings::enabled ;
626 print "ok2\n" if warnings::enabled("syntax") ;
627 print "ok3\n" if warnings::enabled("io") ;
628 print "ok4\n" if ! warnings::enabled("misc") ;
629}
6301;
631--FILE--
632use warnings 'syntax' ;
633use abc ;
634use warnings 'abc' ;
635sub fred { use warnings 'io' ; abc::check() }
636fred() ;
637EXPECT
638ok1
639ok2
640ok3
641ok4
642########
643
644--FILE-- abc.pm
645package abc ;
646use warnings 'misc' ;
647use warnings::register;
648sub check { warnings::warn("hello") }
6491;
650--FILE--
651use abc;
652use warnings "abc" ;
653abc::check() ;
654EXPECT
655hello at - line 3
656########
657
658--FILE-- abc.pm
659package abc ;
660use warnings::register;
661sub check { warnings::warn("hello") }
6621;
663--FILE--
664use abc;
665abc::check() ;
666EXPECT
667hello at - line 2
668########
669
670--FILE-- abc.pm
671package abc ;
672use warnings::register ;
673sub check { warnings::warn("hello") }
6741;
675--FILE--
676use abc;
677use warnings qw( FATAL deprecated ) ;
c3186b65
PM
678eval {
679 abc::check() ;
680 } ;
d3a7d8c7
GS
681print "[[$@]]\n";
682EXPECT
c3186b65 683hello at - line 4
d3a7d8c7
GS
684[[]]
685########
686
687--FILE-- abc.pm
688package abc ;
689use warnings::register ;
690sub check { warnings::warn("hello") }
6911;
692--FILE--
693use abc;
694use warnings qw( FATAL abc ) ;
c3186b65
PM
695eval {
696 abc::check() ;
697 } ;
d3a7d8c7
GS
698print "[[$@]]\n";
699EXPECT
c3186b65 700[[hello at - line 4
d3a7d8c7
GS
701]]
702########
703-W
704--FILE-- abc.pm
705package abc ;
706use warnings "io" ;
707use warnings::register ;
708sub check {
709 print "ok1\n" if warnings::enabled() ;
710 print "ok2\n" if warnings::enabled("io") ;
711 print "ok3\n" if warnings::enabled("all") ;
712}
7131;
714--FILE--
715no warnings;
716use abc ;
717abc::check() ;
718EXPECT
719ok1
720ok2
721ok3
722########
723-X
724--FILE-- abc.pm
725package abc ;
726use warnings "io" ;
727use warnings::register ;
728sub check {
729 print "ok1\n" if !warnings::enabled() ;
730 print "ok2\n" if !warnings::enabled("io") ;
731 print "ok3\n" if !warnings::enabled("all") ;
732}
7331;
734--FILE--
735no warnings;
736use abc ;
737abc::check() ;
738EXPECT
739ok1
740ok2
741ok3
742########
743
744--FILE-- abc.pm
745package abc ;
746use warnings "io" ;
747use warnings::register ;
748sub check {
749 print "ok1\n" if warnings::enabled() ;
750 print "ok2\n" if warnings::enabled("io") ;
751 print "ok3\n" if warnings::enabled("all") ;
752}
7531;
754--FILE--
755use warnings 'all';
756use abc ;
757abc::check() ;
758EXPECT
759ok1
760ok2
761ok3
762########
763
764--FILE-- abc.pm
765package abc ;
766use warnings "io" ;
767use warnings::register ;
768sub check {
769 print "ok1\n" if !warnings::enabled() ;
770 print "ok2\n" if !warnings::enabled("io") ;
771 print "ok3\n" if !warnings::enabled("all") ;
772}
7731;
774--FILE--
775use abc ;
776no warnings ;
777abc::check() ;
778EXPECT
779ok1
780ok2
781ok3
782########
783
784--FILE-- abc.pm
785package abc ;
786use warnings "io" ;
787use warnings::register ;
788sub check {
789 print "ok1\n" if !warnings::enabled() ;
790 print "ok2\n" if !warnings::enabled("io") ;
791 print "ok3\n" if !warnings::enabled("all") ;
7e6d00f8
PM
792 warnings::warnif("my message 1") ;
793 warnings::warnif('abc', "my message 2") ;
794 warnings::warnif('io', "my message 3") ;
795 warnings::warnif('all', "my message 4") ;
d3a7d8c7
GS
796}
7971;
798--FILE--
799use abc ;
800use warnings 'abc';
801no warnings ;
802abc::check() ;
803EXPECT
804ok1
805ok2
806ok3
807########
808
809--FILE-- abc.pm
810package abc ;
811use warnings "io" ;
812use warnings::register ;
813sub check {
814 print "abc self" . (warnings::enabled() ? "" : " not") . " enabled\n" ;
815 print "abc def" . (warnings::enabled('def') ? "" : " not") . " enabled\n" ;
816 print "abc all" . (warnings::enabled('all') ? "" : " not") . " enabled\n" ;
817}
8181;
819--FILE-- def.pm
820package def ;
821use warnings "io" ;
822use warnings::register ;
823sub check {
824 print "def self" . (warnings::enabled() ? "" : " not") . " enabled\n" ;
825 print "def abc" . (warnings::enabled('abc') ? "" : " not") . " enabled\n" ;
826 print "def all" . (warnings::enabled('all') ? "" : " not") . " enabled\n" ;
827}
8281;
829--FILE--
830use abc ;
831use def ;
832use warnings 'abc';
833abc::check() ;
834def::check() ;
835no warnings 'abc' ;
836use warnings 'def' ;
837abc::check() ;
838def::check() ;
839use warnings 'abc' ;
840use warnings 'def' ;
841abc::check() ;
842def::check() ;
843no warnings 'abc' ;
844no warnings 'def' ;
845abc::check() ;
846def::check() ;
847use warnings;
848abc::check() ;
849def::check() ;
850no warnings 'abc' ;
851abc::check() ;
852def::check() ;
853EXPECT
854abc self enabled
855abc def not enabled
856abc all not enabled
857def self not enabled
858def abc enabled
859def all not enabled
860abc self not enabled
861abc def enabled
862abc all not enabled
863def self enabled
864def abc not enabled
865def all not enabled
866abc self enabled
867abc def enabled
868abc all not enabled
869def self enabled
870def abc enabled
871def all not enabled
872abc self not enabled
873abc def not enabled
874abc all not enabled
875def self not enabled
876def abc not enabled
877def all not enabled
878abc self enabled
879abc def enabled
880abc all enabled
881def self enabled
882def abc enabled
883def all enabled
884abc self not enabled
885abc def enabled
886abc all not enabled
887def self enabled
888def abc not enabled
889def all not enabled
114bafba
GS
890########
891-w
892--FILE-- abc.pm
893package abc ;
894no warnings ;
895use warnings::register ;
896sub check {
897 print "ok1\n" if warnings::enabled() ;
898 print "ok2\n" if warnings::enabled("io") ;
899 print "ok3\n" if warnings::enabled("all") ;
900}
9011;
902--FILE--
903use abc ;
904abc::check() ;
905EXPECT
906ok1
907ok2
908ok3
909########
910-w
911--FILE-- abc.pm
912package abc ;
913no warnings ;
914use warnings::register ;
915sub check {
916 print "ok1\n" if !warnings::enabled() ;
917 print "ok2\n" if !warnings::enabled("io") ;
918 print "ok3\n" if !warnings::enabled("all") ;
919}
9201;
921--FILE--
922use abc ;
923use warnings 'abc';
924no warnings ;
925abc::check() ;
926EXPECT
927ok1
928ok2
929ok3
930########
931
932--FILE-- abc.pm
933package abc ;
934no warnings ;
935use warnings::register ;
936sub check {
937 print "ok1\n" if !warnings::enabled() ;
938 print "ok2\n" if !warnings::enabled("io") ;
939 print "ok3\n" if !warnings::enabled("all") ;
7e6d00f8
PM
940 warnings::warnif("my message 1") ;
941 warnings::warnif('abc', "my message 2") ;
942 warnings::warnif('io', "my message 3") ;
943 warnings::warnif('all', "my message 4") ;
114bafba
GS
944}
9451;
946--FILE--
947use abc ;
948use warnings 'abc';
949no warnings ;
950BEGIN { $^W = 1 ; }
951abc::check() ;
952EXPECT
953ok1
954ok2
955ok3
956########
957
958--FILE-- abc.pm
959package abc ;
960no warnings ;
961use warnings::register ;
962sub check {
963 print "ok1\n" if !warnings::enabled() ;
964 print "ok2\n" if !warnings::enabled("io") ;
965 print "ok3\n" if !warnings::enabled("all") ;
966}
9671;
968--FILE--
969use abc ;
970use warnings 'abc';
971no warnings ;
972$^W = 1 ;
973abc::check() ;
974EXPECT
975ok1
976ok2
977ok3
7e6d00f8
PM
978########
979
980--FILE-- abc.pm
a781f7c3 981$| = 1;
7e6d00f8
PM
982package abc ;
983no warnings ;
984use warnings::register ;
985sub check {
986 print "ok1\n" if warnings::enabled() ;
987 print "ok2\n" if !warnings::enabled("io") ;
988 print "ok3\n" if !warnings::enabled("all") ;
989 print "ok4\n" if warnings::enabled("abc") ;
990 warnings::warn("my message 1") ;
991 warnings::warnif("my message 2") ;
992 warnings::warnif('abc', "my message 3") ;
993 warnings::warnif('io', "my message 4") ;
994 warnings::warnif('all', "my message 5") ;
995}
996sub in2 { no warnings ; check() }
997sub in1 { no warnings ; in2() }
9981;
999--FILE--
1000use abc ;
1001use warnings 'abc';
1002abc::in1() ;
1003EXPECT
7e6d00f8
PM
1004ok1
1005ok2
1006ok3
1007ok4
a781f7c3
FE
1008my message 1 at - line 3
1009my message 2 at - line 3
1010my message 3 at - line 3
7e6d00f8
PM
1011########
1012
1013--FILE-- def.pm
1014package def ;
1015no warnings ;
1016use warnings::register ;
1017sub check {
1018 print "ok1\n" if warnings::enabled() ;
1019 print "ok2\n" if !warnings::enabled("io") ;
1020 print "ok3\n" if !warnings::enabled("all") ;
1021 print "ok4\n" if warnings::enabled("def") ;
1022 warnings::warn("my message 1") ;
1023 warnings::warnif("my message 2") ;
1024 warnings::warnif('def', "my message 3") ;
1025 warnings::warnif('io', "my message 4") ;
1026 warnings::warnif('all', "my message 5") ;
1027}
1028sub in2 { no warnings ; check() }
1029sub in1 { no warnings ; in2() }
10301;
1031--FILE-- abc.pm
a781f7c3 1032$| = 1;
7e6d00f8
PM
1033package abc ;
1034use def ;
1035use warnings 'def';
1036sub in1 { def::in1() ; }
10371;
1038--FILE--
1039use abc ;
1040no warnings;
1041abc::in1() ;
1042EXPECT
7e6d00f8
PM
1043ok1
1044ok2
1045ok3
1046ok4
a781f7c3 1047my message 1 at abc.pm line 5
a781f7c3 1048my message 2 at abc.pm line 5
a781f7c3 1049my message 3 at abc.pm line 5
7e6d00f8
PM
1050########
1051
1052--FILE-- def.pm
a781f7c3 1053$| = 1;
7e6d00f8
PM
1054package def ;
1055no warnings ;
1056use warnings::register ;
1057require Exporter;
1058@ISA = qw( Exporter ) ;
1059@EXPORT = qw( in1 ) ;
1060sub check {
1061 print "ok1\n" if warnings::enabled() ;
1062 print "ok2\n" if !warnings::enabled("io") ;
1063 print "ok3\n" if !warnings::enabled("all") ;
1064 print "ok4\n" if warnings::enabled("abc") ;
1065 print "ok5\n" if !warnings::enabled("def") ;
1066 warnings::warn("my message 1") ;
1067 warnings::warnif("my message 2") ;
1068 warnings::warnif('abc', "my message 3") ;
1069 warnings::warnif('def', "my message 4") ;
1070 warnings::warnif('io', "my message 5") ;
1071 warnings::warnif('all', "my message 6") ;
1072}
1073sub in2 { no warnings ; check() }
1074sub in1 { no warnings ; in2() }
10751;
1076--FILE-- abc.pm
1077package abc ;
1078use warnings::register ;
1079use def ;
1080#@ISA = qw(def) ;
10811;
1082--FILE--
1083use abc ;
1084no warnings;
1085use warnings 'abc';
1086abc::in1() ;
1087EXPECT
7e6d00f8
PM
1088ok2
1089ok3
1090ok4
1091ok5
a781f7c3
FE
1092my message 1 at - line 4
1093my message 3 at - line 4
7e6d00f8
PM
1094########
1095
1096--FILE-- def.pm
1097package def ;
1098no warnings ;
1099use warnings::register ;
1100
1101sub new
1102{
1103 my $class = shift ;
1104 bless [], $class ;
1105}
1106
1107sub check
1108{
1109 my $self = shift ;
1110 print "ok1\n" if !warnings::enabled() ;
1111 print "ok2\n" if !warnings::enabled("io") ;
1112 print "ok3\n" if !warnings::enabled("all") ;
1113 print "ok4\n" if warnings::enabled("abc") ;
1114 print "ok5\n" if !warnings::enabled("def") ;
1115 print "ok6\n" if warnings::enabled($self) ;
1116
1117 warnings::warn("my message 1") ;
1118 warnings::warn($self, "my message 2") ;
1119
1120 warnings::warnif("my message 3") ;
1121 warnings::warnif('abc', "my message 4") ;
1122 warnings::warnif('def', "my message 5") ;
1123 warnings::warnif('io', "my message 6") ;
1124 warnings::warnif('all', "my message 7") ;
1125 warnings::warnif($self, "my message 8") ;
1126}
1127sub in2
1128{
1129 no warnings ;
1130 my $self = shift ;
1131 $self->check() ;
1132}
1133sub in1
1134{
1135 no warnings ;
1136 my $self = shift ;
1137 $self->in2();
1138}
11391;
1140--FILE-- abc.pm
a781f7c3 1141$| = 1;
7e6d00f8
PM
1142package abc ;
1143use warnings::register ;
1144use def ;
1145@ISA = qw(def) ;
1146sub new
1147{
1148 my $class = shift ;
1149 bless [], $class ;
1150}
1151
11521;
1153--FILE--
1154use abc ;
1155no warnings;
1156use warnings 'abc';
1157$a = new abc ;
1158$a->in1() ;
1159print "**\n";
1160$b = new def ;
1161$b->in1() ;
1162EXPECT
7e6d00f8
PM
1163ok1
1164ok2
1165ok3
1166ok4
1167ok5
1168ok6
a781f7c3
FE
1169my message 1 at - line 5
1170my message 2 at - line 5
1171my message 4 at - line 5
1172my message 8 at - line 5
7e6d00f8
PM
1173**
1174ok1
1175ok2
1176ok3
1177ok4
1178ok5
a781f7c3
FE
1179my message 1 at - line 8
1180my message 2 at - line 8
1181my message 4 at - line 8