This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Provide option to build with -D__USE_MINGW_ANSI_STDIO
[perl5.git] / t / lib / warnings / 9enabled
CommitLineData
8d93267c
GS
1Check warnings::enabled & warnings::warn
2
3__END__
4
a95b6808
JH
5--FILE-- abc0.pm
6package abc0 ;
8d93267c 7use warnings "io" ;
d3a7d8c7 8print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
9print "ok2\n" if ! warnings::enabled("io") ;
101;
a95b6808 11--FILE--
8d93267c 12no warnings;
a95b6808 13use abc0 ;
8d93267c
GS
14EXPECT
15ok1
16ok2
17########
18
a95b6808
JH
19--FILE-- abc1.pm
20package abc1 ;
8d93267c 21no warnings ;
d3a7d8c7 22print "ok1\n" if !warnings::enabled('all') ;
8d93267c
GS
23print "ok2\n" if warnings::enabled("syntax") ;
241;
a95b6808 25--FILE--
8d93267c 26use warnings 'syntax' ;
a95b6808 27use abc1 ;
8d93267c
GS
28EXPECT
29ok1
30ok2
31########
32
a95b6808
JH
33--FILE-- abc2.pm
34package abc2 ;
8d93267c 35use warnings 'syntax' ;
d3a7d8c7 36print "ok1\n" if warnings::enabled('io') ;
8d93267c
GS
37print "ok2\n" if ! warnings::enabled("syntax") ;
381;
a95b6808 39--FILE--
8d93267c 40use warnings 'io' ;
a95b6808 41use abc2 ;
8d93267c
GS
42EXPECT
43ok1
44ok2
45########
46
a95b6808 47--FILE-- abc3
8d93267c 48no warnings ;
d3a7d8c7 49print "ok1\n" if !warnings::enabled('all') ;
4f527b71 50print "ok2\n" if !warnings::enabled("syntax") ;
8d93267c 511;
a95b6808 52--FILE--
8d93267c 53use warnings 'syntax' ;
a95b6808 54require "abc3" ;
8d93267c
GS
55EXPECT
56ok1
57ok2
58########
59
a95b6808 60--FILE-- abc4
8d93267c 61use warnings 'syntax' ;
d3a7d8c7 62print "ok1\n" if ! warnings::enabled('all') ;
8d93267c 63print "ok2\n" if ! warnings::enabled("syntax") ;
4f527b71 64print "ok3\n" if ! warnings::enabled("io") ;
8d93267c 651;
a95b6808 66--FILE--
8d93267c 67use warnings 'io' ;
a95b6808 68require "abc4" ;
8d93267c
GS
69EXPECT
70ok1
71ok2
72ok3
73########
74
a95b6808
JH
75--FILE-- abc5.pm
76package abc5 ;
8d93267c
GS
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;
a95b6808 83--FILE--
8d93267c 84use warnings 'syntax' ;
a95b6808
JH
85use abc5 ;
86abc5::check() ;
8d93267c
GS
87EXPECT
88ok1
89ok2
90########
91
a95b6808
JH
92--FILE-- abc6.pm
93package abc6 ;
8d93267c
GS
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;
a95b6808 101--FILE--
8d93267c 102use warnings 'syntax' ;
a95b6808
JH
103use abc6 ;
104abc6::check() ;
8d93267c
GS
105EXPECT
106ok1
107ok2
108ok3
109########
110
a95b6808
JH
111--FILE-- abc7
112package abc7 ;
8d93267c
GS
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;
a95b6808 119--FILE--
8d93267c 120use warnings 'syntax' ;
a95b6808
JH
121require "abc7" ;
122abc7::check() ;
8d93267c
GS
123EXPECT
124ok1
125ok2
126########
127
a95b6808
JH
128--FILE-- abc8
129package abc8 ;
8d93267c
GS
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;
a95b6808 137--FILE--
8d93267c 138use warnings 'syntax' ;
a95b6808
JH
139require "abc8" ;
140abc8::check() ;
8d93267c
GS
141EXPECT
142ok1
143ok2
144ok3
145########
146
a95b6808
JH
147--FILE-- abc9.pm
148package abc9 ;
8d93267c 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 155no warnings;
a95b6808 156use abc9 ;
8d93267c 1571;
a95b6808 158--FILE--
8d93267c
GS
159use warnings;
160use def ;
161EXPECT
162ok1
163ok2
164########
165
a95b6808
JH
166--FILE-- abc10.pm
167package abc10 ;
8d93267c 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') ;
4f527b71 176print "ok5\n" if !warnings::enabled("io") ;
a95b6808 177use abc10 ;
8d93267c
GS
1781;
179--FILE--
180use warnings 'io' ;
181use def ;
182EXPECT
183ok1
184ok2
185ok3
186ok4
187ok5
188########
189
a95b6808
JH
190--FILE-- abc11.pm
191package abc11 ;
8d93267c
GS
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;
a95b6808 198--FILE--
8d93267c 199use warnings 'syntax' ;
a95b6808
JH
200use abc11 ;
201eval {
202 abc11::check() ;
c3186b65 203};
8d93267c
GS
204print $@ ;
205EXPECT
206ok1
207ok2
208########
209
a95b6808
JH
210--FILE-- abc12.pm
211package abc12 ;
8d93267c
GS
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;
a95b6808 219--FILE--
8d93267c 220use warnings 'syntax' ;
a95b6808
JH
221use abc12 ;
222eval {
223 abc12::check() ;
c3186b65 224 } ;
8d93267c
GS
225print $@ ;
226EXPECT
227ok1
228ok2
229ok3
230########
231
a95b6808
JH
232--FILE-- abc13
233package abc13 ;
8d93267c
GS
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;
a95b6808 240--FILE--
8d93267c 241use warnings 'syntax' ;
a95b6808
JH
242require "abc13" ;
243eval {
244 abc13::check() ;
c3186b65 245 } ;
8d93267c
GS
246print $@ ;
247EXPECT
248ok1
249ok2
250########
251
a95b6808
JH
252--FILE-- abc14
253package abc14 ;
8d93267c
GS
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;
a95b6808 261--FILE--
8d93267c 262use warnings 'syntax' ;
a95b6808
JH
263require "abc14" ;
264eval {
265 use warnings 'io' ;
266 abc14::check() ;
c3186b65 267};
a95b6808 268abc14::check() ;
8d93267c
GS
269print $@ ;
270EXPECT
271ok1
272ok2
273ok3
274ok1
275ok2
276########
277
a95b6808
JH
278--FILE-- abc15.pm
279package abc15 ;
8d93267c
GS
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;
a95b6808 287--FILE--
8d93267c 288use warnings 'syntax' ;
a95b6808
JH
289use abc15 ;
290sub fred { abc15::check() }
8d93267c
GS
291fred() ;
292EXPECT
293ok1
294ok2
295ok3
296########
297
a95b6808
JH
298--FILE-- abc16.pm
299package abc16 ;
8d93267c
GS
300use warnings 'io' ;
301sub check {
d3a7d8c7 302 print "ok1\n" if ! warnings::enabled('all') ;
8d93267c
GS
303}
3041;
a95b6808 305--FILE--
8d93267c 306use warnings 'syntax' ;
a95b6808
JH
307use abc16 ;
308sub fred { no warnings ; abc16::check() }
8d93267c
GS
309fred() ;
310EXPECT
311ok1
312########
313
a95b6808
JH
314--FILE-- abc17.pm
315package abc17 ;
8d93267c
GS
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;
a95b6808 324--FILE--
8d93267c 325use warnings 'syntax' ;
a95b6808
JH
326use abc17 ;
327sub fred { use warnings 'io' ; abc17::check() }
8d93267c
GS
328fred() ;
329EXPECT
330ok1
331ok2
332ok3
333ok4
334########
335
336# check warnings::warn
337use warnings ;
a95b6808
JH
338eval {
339 warnings::warn()
c3186b65 340 } ;
8d93267c 341print $@ ;
a95b6808
JH
342eval {
343 warnings::warn("fred", "joe")
c3186b65 344 } ;
8d93267c
GS
345print $@ ;
346EXPECT
879b0cab
Z
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 ;
a95b6808
JH
353eval {
354 warnings::warnif()
c3186b65 355} ;
7e6d00f8 356print $@ ;
a95b6808
JH
357eval {
358 warnings::warnif("fred", "joe")
c3186b65 359} ;
7e6d00f8
PM
360print $@ ;
361EXPECT
879b0cab
Z
362Usage: warnings::warnif([category,] 'message') at - line 5.
363Unknown warnings category 'fred' at - line 9.
8d93267c
GS
364########
365
a95b6808
JH
366--FILE-- abc18.pm
367package abc18 ;
8d93267c
GS
368use warnings 'misc' ;
369sub check { warnings::warn("io", "hello") }
3701;
371--FILE--
372use warnings "io" ;
a95b6808
JH
373use abc18;
374abc18::check() ;
8d93267c 375EXPECT
879b0cab 376hello at - line 3.
8d93267c
GS
377########
378
a95b6808
JH
379--FILE-- abc19.pm
380package abc19 ;
8d93267c
GS
381use warnings 'misc' ;
382sub check { warnings::warn("misc", "hello") }
3831;
384--FILE--
385use warnings "io" ;
a95b6808
JH
386use abc19;
387abc19::check() ;
8d93267c 388EXPECT
879b0cab 389hello at - line 3.
8d93267c
GS
390########
391
a95b6808
JH
392--FILE-- abc20.pm
393package abc20 ;
8d93267c
GS
394use warnings 'misc' ;
395sub check { warnings::warn("io", "hello") }
3961;
397--FILE--
398use warnings qw( FATAL deprecated ) ;
a95b6808
JH
399use abc20;
400eval {
401 abc20::check() ;
c3186b65 402 } ;
8d93267c
GS
403print "[[$@]]\n";
404EXPECT
879b0cab 405hello at - line 4.
8d93267c
GS
406[[]]
407########
408
a95b6808
JH
409--FILE-- abc21.pm
410package abc21 ;
8d93267c
GS
411use warnings 'misc' ;
412sub check { warnings::warn("io", "hello") }
4131;
414--FILE--
415use warnings qw( FATAL io ) ;
a95b6808
JH
416use abc21;
417eval {
418 abc21::check() ;
c3186b65 419} ;
8d93267c
GS
420print "[[$@]]\n";
421EXPECT
879b0cab 422[[hello at - line 4.
8d93267c 423]]
d3a7d8c7
GS
424########
425-W
a95b6808
JH
426--FILE-- abc22.pm
427package abc22 ;
d3a7d8c7
GS
428use warnings "io" ;
429print "ok1\n" if warnings::enabled("io") ;
430print "ok2\n" if warnings::enabled("all") ;
4311;
a95b6808 432--FILE--
d3a7d8c7 433no warnings;
a95b6808 434use abc22 ;
d3a7d8c7
GS
435EXPECT
436ok1
437ok2
438########
439-X
a95b6808
JH
440--FILE-- abc23.pm
441package abc23 ;
d3a7d8c7
GS
442use warnings "io" ;
443print "ok1\n" if !warnings::enabled("io") ;
444print "ok2\n" if !warnings::enabled("all") ;
4451;
a95b6808 446--FILE--
d3a7d8c7 447use warnings;
a95b6808 448use abc23 ;
d3a7d8c7
GS
449EXPECT
450ok1
451ok2
452########
453
a95b6808
JH
454--FILE-- abc24.pm
455package abc24 ;
d3a7d8c7
GS
456no warnings ;
457sub check {
458 print "ok\n" if ! warnings::enabled() ;
459}
4601;
a95b6808 461--FILE--
d3a7d8c7 462use warnings 'syntax' ;
a95b6808
JH
463use abc24 ;
464abc24::check() ;
d3a7d8c7 465EXPECT
879b0cab 466package 'abc24' not registered for warnings at abc24.pm line 4.
7e6d00f8
PM
467########
468
a95b6808
JH
469--FILE-- abc25.pm
470package abc25 ;
7e6d00f8
PM
471no warnings ;
472sub check {
473 warnings::warn("fred") ;
474}
4751;
a95b6808 476--FILE--
7e6d00f8 477use warnings 'syntax' ;
a95b6808
JH
478use abc25 ;
479abc25::check() ;
7e6d00f8 480EXPECT
879b0cab 481package 'abc25' not registered for warnings at abc25.pm line 4.
7e6d00f8
PM
482########
483
a95b6808
JH
484--FILE-- abc26.pm
485package abc26 ;
7e6d00f8
PM
486no warnings ;
487sub check {
488 warnings::warnif("fred") ;
489}
4901;
a95b6808 491--FILE--
7e6d00f8 492use warnings 'syntax' ;
a95b6808
JH
493use abc26 ;
494abc26::check() ;
7e6d00f8 495EXPECT
879b0cab 496package 'abc26' not registered for warnings at abc26.pm line 4.
d3a7d8c7
GS
497########
498
a95b6808
JH
499--FILE-- abc27.pm
500package abc27 ;
d3a7d8c7
GS
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;
a95b6808 509--FILE--
d3a7d8c7 510use warnings 'syntax' ;
a95b6808
JH
511use abc27 ;
512use warnings 'abc27' ;
513abc27::check() ;
d3a7d8c7
GS
514EXPECT
515ok1
516ok2
517ok3
518########
519
a95b6808
JH
520--FILE-- abc28.pm
521package abc28 ;
d3a7d8c7
GS
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;
a95b6808 530--FILE--
d3a7d8c7 531use warnings 'syntax' ;
a95b6808
JH
532use abc28 ;
533abc28::check() ;
d3a7d8c7
GS
534EXPECT
535ok1
536ok2
537ok3
538########
539
a95b6808
JH
540--FILE-- abc29.pm
541package abc29 ;
d3a7d8c7
GS
542no warnings ;
543use warnings::register ;
544sub check {
545 print "ok1\n" if warnings::enabled ;
546 print "ok2\n" if warnings::enabled("syntax") ;
547}
5481;
a95b6808 549--FILE--
d3a7d8c7 550use warnings 'syntax' ;
a95b6808
JH
551use abc29 ;
552use warnings 'abc29' ;
553eval { abc29::check() ; };
d3a7d8c7
GS
554print $@ ;
555EXPECT
556ok1
557ok2
558########
559
a95b6808
JH
560--FILE-- abc30.pm
561package abc30 ;
d3a7d8c7
GS
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;
a95b6808 570--FILE--
d3a7d8c7 571use warnings 'syntax' ;
a95b6808
JH
572use abc30 ;
573eval { abc30::check() ; } ;
d3a7d8c7
GS
574print $@ ;
575EXPECT
576ok1
577ok2
578ok3
579########
580
a95b6808
JH
581--FILE-- abc31.pm
582package abc31 ;
d3a7d8c7
GS
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;
a95b6808 591--FILE--
d3a7d8c7 592use warnings 'syntax' ;
a95b6808
JH
593use abc31 ;
594use warnings 'abc31' ;
595sub fred { abc31::check() }
d3a7d8c7
GS
596fred() ;
597EXPECT
598ok1
599ok2
600ok3
601########
602
a95b6808
JH
603--FILE-- abc32.pm
604package abc32 ;
d3a7d8c7
GS
605use warnings 'io' ;
606use warnings::register ;
607sub check {
608 print "ok1\n" if ! warnings::enabled ;
609}
6101;
a95b6808 611--FILE--
d3a7d8c7 612use warnings 'syntax' ;
a95b6808
JH
613use abc32 ;
614sub fred { no warnings ; abc32::check() }
d3a7d8c7
GS
615fred() ;
616EXPECT
617ok1
618########
619
a95b6808
JH
620--FILE-- abc33.pm
621package abc33 ;
d3a7d8c7
GS
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;
a95b6808 631--FILE--
d3a7d8c7 632use warnings 'syntax' ;
a95b6808
JH
633use abc33 ;
634use warnings 'abc33' ;
635sub fred { use warnings 'io' ; abc33::check() }
d3a7d8c7
GS
636fred() ;
637EXPECT
638ok1
639ok2
640ok3
641ok4
642########
643
a95b6808
JH
644--FILE-- abc34.pm
645package abc34 ;
d3a7d8c7
GS
646use warnings 'misc' ;
647use warnings::register;
648sub check { warnings::warn("hello") }
6491;
650--FILE--
a95b6808
JH
651use abc34;
652use warnings "abc34" ;
653abc34::check() ;
d3a7d8c7 654EXPECT
879b0cab 655hello at - line 3.
d3a7d8c7
GS
656########
657
a95b6808
JH
658--FILE-- abc35.pm
659package abc35 ;
d3a7d8c7
GS
660use warnings::register;
661sub check { warnings::warn("hello") }
6621;
663--FILE--
a95b6808
JH
664use abc35;
665abc35::check() ;
d3a7d8c7 666EXPECT
879b0cab 667hello at - line 2.
d3a7d8c7
GS
668########
669
a95b6808
JH
670--FILE-- abc36.pm
671package abc36 ;
d3a7d8c7
GS
672use warnings::register ;
673sub check { warnings::warn("hello") }
6741;
675--FILE--
a95b6808 676use abc36;
d3a7d8c7 677use warnings qw( FATAL deprecated ) ;
c3186b65 678eval {
a95b6808 679 abc36::check() ;
c3186b65 680 } ;
d3a7d8c7
GS
681print "[[$@]]\n";
682EXPECT
879b0cab 683hello at - line 4.
d3a7d8c7
GS
684[[]]
685########
686
a95b6808
JH
687--FILE-- abc37.pm
688package abc37 ;
d3a7d8c7
GS
689use warnings::register ;
690sub check { warnings::warn("hello") }
6911;
692--FILE--
a95b6808
JH
693use abc37;
694use warnings qw( FATAL abc37 ) ;
695eval {
696 abc37::check() ;
c3186b65 697 } ;
d3a7d8c7
GS
698print "[[$@]]\n";
699EXPECT
879b0cab 700[[hello at - line 4.
d3a7d8c7
GS
701]]
702########
703-W
a95b6808
JH
704--FILE-- abc38.pm
705package abc38 ;
d3a7d8c7
GS
706use warnings "io" ;
707use warnings::register ;
a95b6808 708sub check {
d3a7d8c7
GS
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;
a95b6808 714--FILE--
d3a7d8c7 715no warnings;
a95b6808
JH
716use abc38 ;
717abc38::check() ;
d3a7d8c7
GS
718EXPECT
719ok1
720ok2
721ok3
722########
723-X
a95b6808
JH
724--FILE-- abc39.pm
725package abc39 ;
d3a7d8c7
GS
726use warnings "io" ;
727use warnings::register ;
a95b6808 728sub check {
d3a7d8c7
GS
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;
a95b6808 734--FILE--
d3a7d8c7 735no warnings;
a95b6808
JH
736use abc39 ;
737abc39::check() ;
d3a7d8c7
GS
738EXPECT
739ok1
740ok2
741ok3
742########
743
a95b6808
JH
744--FILE-- abc40.pm
745package abc40 ;
d3a7d8c7
GS
746use warnings "io" ;
747use warnings::register ;
a95b6808 748sub check {
d3a7d8c7
GS
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;
a95b6808 754--FILE--
d3a7d8c7 755use warnings 'all';
a95b6808
JH
756use abc40 ;
757abc40::check() ;
d3a7d8c7
GS
758EXPECT
759ok1
760ok2
761ok3
762########
763
a95b6808
JH
764--FILE-- abc41.pm
765package abc41 ;
d3a7d8c7
GS
766use warnings "io" ;
767use warnings::register ;
a95b6808 768sub check {
d3a7d8c7
GS
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;
a95b6808
JH
774--FILE--
775use abc41 ;
d3a7d8c7 776no warnings ;
a95b6808 777abc41::check() ;
d3a7d8c7
GS
778EXPECT
779ok1
780ok2
781ok3
782########
783
a95b6808
JH
784--FILE-- abc42.pm
785package abc42 ;
d3a7d8c7
GS
786use warnings "io" ;
787use warnings::register ;
a95b6808 788sub check {
d3a7d8c7
GS
789 print "ok1\n" if !warnings::enabled() ;
790 print "ok2\n" if !warnings::enabled("io") ;
791 print "ok3\n" if !warnings::enabled("all") ;
7e6d00f8 792 warnings::warnif("my message 1") ;
a95b6808 793 warnings::warnif('abc42', "my message 2") ;
7e6d00f8
PM
794 warnings::warnif('io', "my message 3") ;
795 warnings::warnif('all', "my message 4") ;
d3a7d8c7
GS
796}
7971;
a95b6808
JH
798--FILE--
799use abc42 ;
800use warnings 'abc42';
d3a7d8c7 801no warnings ;
a95b6808 802abc42::check() ;
d3a7d8c7
GS
803EXPECT
804ok1
805ok2
806ok3
807########
808
a95b6808
JH
809--FILE-- abc43.pm
810package abc43 ;
d3a7d8c7
GS
811use warnings "io" ;
812use warnings::register ;
a95b6808
JH
813sub check {
814 print "abc43 self" . (warnings::enabled() ? "" : " not") . " enabled\n" ;
815 print "abc43 def" . (warnings::enabled('def') ? "" : " not") . " enabled\n" ;
816 print "abc43 all" . (warnings::enabled('all') ? "" : " not") . " enabled\n" ;
d3a7d8c7
GS
817}
8181;
819--FILE-- def.pm
820package def ;
821use warnings "io" ;
822use warnings::register ;
a95b6808 823sub check {
d3a7d8c7 824 print "def self" . (warnings::enabled() ? "" : " not") . " enabled\n" ;
a95b6808 825 print "def abc43" . (warnings::enabled('abc43') ? "" : " not") . " enabled\n" ;
d3a7d8c7
GS
826 print "def all" . (warnings::enabled('all') ? "" : " not") . " enabled\n" ;
827}
8281;
a95b6808
JH
829--FILE--
830use abc43 ;
d3a7d8c7 831use def ;
a95b6808
JH
832use warnings 'abc43';
833abc43::check() ;
d3a7d8c7 834def::check() ;
a95b6808 835no warnings 'abc43' ;
d3a7d8c7 836use warnings 'def' ;
a95b6808 837abc43::check() ;
d3a7d8c7 838def::check() ;
a95b6808 839use warnings 'abc43' ;
d3a7d8c7 840use warnings 'def' ;
a95b6808 841abc43::check() ;
d3a7d8c7 842def::check() ;
a95b6808 843no warnings 'abc43' ;
d3a7d8c7 844no warnings 'def' ;
a95b6808 845abc43::check() ;
d3a7d8c7
GS
846def::check() ;
847use warnings;
a95b6808 848abc43::check() ;
d3a7d8c7 849def::check() ;
a95b6808
JH
850no warnings 'abc43' ;
851abc43::check() ;
d3a7d8c7
GS
852def::check() ;
853EXPECT
a95b6808
JH
854abc43 self enabled
855abc43 def not enabled
856abc43 all not enabled
d3a7d8c7 857def self not enabled
a95b6808 858def abc43 enabled
d3a7d8c7 859def all not enabled
a95b6808
JH
860abc43 self not enabled
861abc43 def enabled
862abc43 all not enabled
d3a7d8c7 863def self enabled
a95b6808 864def abc43 not enabled
d3a7d8c7 865def all not enabled
a95b6808
JH
866abc43 self enabled
867abc43 def enabled
868abc43 all not enabled
d3a7d8c7 869def self enabled
a95b6808 870def abc43 enabled
d3a7d8c7 871def all not enabled
a95b6808
JH
872abc43 self not enabled
873abc43 def not enabled
874abc43 all not enabled
d3a7d8c7 875def self not enabled
a95b6808 876def abc43 not enabled
d3a7d8c7 877def all not enabled
a95b6808
JH
878abc43 self enabled
879abc43 def enabled
880abc43 all enabled
d3a7d8c7 881def self enabled
a95b6808 882def abc43 enabled
d3a7d8c7 883def all enabled
a95b6808
JH
884abc43 self not enabled
885abc43 def enabled
886abc43 all not enabled
d3a7d8c7 887def self enabled
a95b6808 888def abc43 not enabled
d3a7d8c7 889def all not enabled
114bafba
GS
890########
891-w
a95b6808
JH
892--FILE-- abc44.pm
893package abc44 ;
114bafba
GS
894no warnings ;
895use warnings::register ;
a95b6808 896sub check {
114bafba
GS
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;
a95b6808
JH
902--FILE--
903use abc44 ;
904abc44::check() ;
114bafba
GS
905EXPECT
906ok1
907ok2
908ok3
909########
910-w
a95b6808
JH
911--FILE-- abc45.pm
912package abc45 ;
114bafba
GS
913no warnings ;
914use warnings::register ;
a95b6808 915sub check {
114bafba
GS
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;
a95b6808
JH
921--FILE--
922use abc45 ;
923use warnings 'abc45';
114bafba 924no warnings ;
a95b6808 925abc45::check() ;
114bafba
GS
926EXPECT
927ok1
928ok2
929ok3
930########
931
a95b6808
JH
932--FILE-- abc46.pm
933package abc46 ;
114bafba
GS
934no warnings ;
935use warnings::register ;
a95b6808 936sub check {
114bafba
GS
937 print "ok1\n" if !warnings::enabled() ;
938 print "ok2\n" if !warnings::enabled("io") ;
939 print "ok3\n" if !warnings::enabled("all") ;
7e6d00f8 940 warnings::warnif("my message 1") ;
a95b6808 941 warnings::warnif('abc46', "my message 2") ;
7e6d00f8
PM
942 warnings::warnif('io', "my message 3") ;
943 warnings::warnif('all', "my message 4") ;
114bafba
GS
944}
9451;
a95b6808
JH
946--FILE--
947use abc46 ;
948use warnings 'abc46';
114bafba
GS
949no warnings ;
950BEGIN { $^W = 1 ; }
a95b6808 951abc46::check() ;
114bafba
GS
952EXPECT
953ok1
954ok2
955ok3
956########
957
a95b6808
JH
958--FILE-- abc47.pm
959package abc47 ;
114bafba
GS
960no warnings ;
961use warnings::register ;
a95b6808 962sub check {
114bafba
GS
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;
a95b6808
JH
968--FILE--
969use abc47 ;
970use warnings 'abc47';
114bafba
GS
971no warnings ;
972$^W = 1 ;
a95b6808 973abc47::check() ;
114bafba
GS
974EXPECT
975ok1
976ok2
977ok3
7e6d00f8
PM
978########
979
a95b6808 980--FILE-- abc48.pm
a781f7c3 981$| = 1;
a95b6808 982package abc48 ;
7e6d00f8
PM
983no warnings ;
984use warnings::register ;
a95b6808 985sub check {
7e6d00f8
PM
986 print "ok1\n" if warnings::enabled() ;
987 print "ok2\n" if !warnings::enabled("io") ;
988 print "ok3\n" if !warnings::enabled("all") ;
a95b6808 989 print "ok4\n" if warnings::enabled("abc48") ;
7e6d00f8
PM
990 warnings::warn("my message 1") ;
991 warnings::warnif("my message 2") ;
a95b6808 992 warnings::warnif('abc48', "my message 3") ;
7e6d00f8
PM
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;
a95b6808
JH
999--FILE--
1000use abc48 ;
1001use warnings 'abc48';
1002abc48::in1() ;
7e6d00f8 1003EXPECT
7e6d00f8
PM
1004ok1
1005ok2
1006ok3
1007ok4
879b0cab
Z
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 ;
a95b6808 1017sub check {
7e6d00f8
PM
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;
a95b6808 1031--FILE-- abc49.pm
a781f7c3 1032$| = 1;
a95b6808 1033package abc49 ;
7e6d00f8
PM
1034use def ;
1035use warnings 'def';
1036sub in1 { def::in1() ; }
10371;
a95b6808
JH
1038--FILE--
1039use abc49 ;
7e6d00f8 1040no warnings;
a95b6808 1041abc49::in1() ;
7e6d00f8 1042EXPECT
7e6d00f8
PM
1043ok1
1044ok2
1045ok3
1046ok4
879b0cab
Z
1047my message 1 at abc49.pm line 5.
1048my message 2 at abc49.pm line 5.
1049my message 3 at abc49.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 ) ;
a95b6808 1060sub check {
7e6d00f8
PM
1061 print "ok1\n" if warnings::enabled() ;
1062 print "ok2\n" if !warnings::enabled("io") ;
1063 print "ok3\n" if !warnings::enabled("all") ;
a95b6808 1064 print "ok4\n" if warnings::enabled("abc50") ;
7e6d00f8
PM
1065 print "ok5\n" if !warnings::enabled("def") ;
1066 warnings::warn("my message 1") ;
1067 warnings::warnif("my message 2") ;
a95b6808 1068 warnings::warnif('abc50', "my message 3") ;
7e6d00f8
PM
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;
a95b6808
JH
1076--FILE-- abc50.pm
1077package abc50 ;
7e6d00f8
PM
1078use warnings::register ;
1079use def ;
1080#@ISA = qw(def) ;
10811;
a95b6808
JH
1082--FILE--
1083use abc50 ;
7e6d00f8 1084no warnings;
a95b6808
JH
1085use warnings 'abc50';
1086abc50::in1() ;
7e6d00f8 1087EXPECT
7e6d00f8
PM
1088ok2
1089ok3
1090ok4
1091ok5
879b0cab
Z
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
a95b6808
JH
1107sub check
1108{
7e6d00f8
PM
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") ;
a95b6808 1113 print "ok4\n" if warnings::enabled("abc51") ;
7e6d00f8
PM
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") ;
a95b6808 1121 warnings::warnif('abc51', "my message 4") ;
7e6d00f8
PM
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}
a95b6808 1127sub in2
7e6d00f8 1128{
a95b6808 1129 no warnings ;
7e6d00f8
PM
1130 my $self = shift ;
1131 $self->check() ;
1132}
a95b6808
JH
1133sub in1
1134{
7e6d00f8
PM
1135 no warnings ;
1136 my $self = shift ;
1137 $self->in2();
1138}
11391;
a95b6808 1140--FILE-- abc51.pm
a781f7c3 1141$| = 1;
a95b6808 1142package abc51 ;
7e6d00f8
PM
1143use warnings::register ;
1144use def ;
1145@ISA = qw(def) ;
1146sub new
1147{
1148 my $class = shift ;
1149 bless [], $class ;
1150}
1151
11521;
a95b6808
JH
1153--FILE--
1154use abc51 ;
7e6d00f8 1155no warnings;
a95b6808
JH
1156use warnings 'abc51';
1157$a = new abc51 ;
7e6d00f8
PM
1158$a->in1() ;
1159print "**\n";
1160$b = new def ;
1161$b->in1() ;
1162EXPECT
7e6d00f8
PM
1163ok1
1164ok2
1165ok3
1166ok4
1167ok5
1168ok6
879b0cab
Z
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
879b0cab
Z
1179my message 1 at - line 8.
1180my message 2 at - line 8.
1181my message 4 at - line 8.
4f527b71
AS
1182########
1183
572bfd36
RS
1184--FILE-- abc52.pm
1185package abc52 ;
1186use warnings::register ('foo', 'bar');
1187sub check {
1188 warnings::warnif('abc52', "hello");
1189 warnings::warnif('abc52::foo', "hello foo");
1190 warnings::warnif('abc52::bar', "hello bar");
1191}
11921;
1193--FILE--
1194use abc52;
1195use warnings("abc52", "abc52::bar");
1196abc52::check() ;
1197EXPECT
879b0cab
Z
1198hello at - line 3.
1199hello bar at - line 3.
572bfd36
RS
1200########
1201
4f527b71
AS
1202--FILE--
1203# test for bug [perl #15395]
1204my ( $warn_cat, # warning category we'll try to control
1205 $warn_msg, # the error message to catch
1206);
1207
1208package SomeModule;
1209use warnings::register;
1210
1211BEGIN {
1212 $warn_cat = __PACKAGE__;
1213 $warn_msg = 'from ' . __PACKAGE__;
1214}
1215
1216# a sub that generates a random warning
1217sub gen_warning {
1218 warnings::warnif( $warn_msg );
1219}
1220
1221package ClientModule;
1222# use SomeModule; (would go here)
1223our @CARP_NOT = ( $warn_cat ); # deliver warnings to *our* client
1224
1225# call_warner provokes a warning. It is delivered to its caller,
1226# who should also be able to control it
1227sub call_warner {
1228 SomeModule::gen_warning();
1229}
1230
1231# user
1232
1233package main;
1234my $warn_line = __LINE__ + 3; # this line should be in the error message
1235eval {
1236 use warnings FATAL => $warn_cat; # we want to know if this works
1237 ClientModule::call_warner();
1238};
1239
1240# have we caught an error, and is it the one we generated?
1241print "ok1\n" if $@ =~ /$warn_msg/;
1242
1243# does it indicate the right line?
a95b6808 1244print "ok2\n" if $@ =~ /line $warn_line/;
4f527b71
AS
1245EXPECT
1246ok1
1247ok2
68a00014
AR
1248########
1249
1250--FILE-- fatal1.pm
1251package fatal1 ;
1252no warnings ;
1253print "ok1\n" if !warnings::fatal_enabled('all') ;
1254print "ok2\n" if !warnings::fatal_enabled("syntax") ;
12551;
1256--FILE--
1257use fatal1 ;
1258EXPECT
1259ok1
1260ok2
1261########
1262
1263--FILE-- fatal2.pm
1264package fatal2;
1265no warnings ;
1266print "ok1\n" if !warnings::fatal_enabled('all') ;
1267print "ok2\n" if warnings::fatal_enabled("syntax") ;
12681;
1269--FILE--
1270use warnings FATAL => 'syntax' ;
1271use fatal2 ;
1272EXPECT
1273ok1
1274ok2
1275########
1276
1277--FILE-- fatal3.pm
1278package fatal3 ;
1279no warnings ;
1280print "ok1\n" if warnings::fatal_enabled('all') ;
1281print "ok2\n" if warnings::fatal_enabled("syntax") ;
12821;
1283--FILE--
1284use warnings FATAL => 'all' ;
1285use fatal3 ;
1286EXPECT
1287ok1
1288ok2
1289########
1290
1291--FILE-- fatal4.pm
1292package fatal4 ;
1293no warnings ;
1294print "ok1\n" if !warnings::fatal_enabled('all') ;
1295print "ok2\n" if warnings::fatal_enabled("void") ;
1296print "ok3\n" if !warnings::fatal_enabled("syntax") ;
12971;
1298--FILE--
1299use warnings FATAL => 'all', NONFATAL => 'syntax' ;
1300use fatal4 ;
1301EXPECT
1302ok1
1303ok2
1304ok3