xref: /openbsd/gnu/usr.bin/perl/t/lib/warnings/1global (revision 6fb12b70)
155745691SmillertCheck existing $^W functionality
255745691Smillert
355745691Smillert
455745691Smillert__END__
555745691Smillert
655745691Smillert# warnable code, warnings disabled
755745691Smillert$a =+ 3 ;
855745691SmillertEXPECT
955745691Smillert
1055745691Smillert########
1155745691Smillert-w
1255745691Smillert# warnable code, warnings enabled via command line switch
13*6fb12b70Safresh1$c =+ 3 ;
1455745691SmillertEXPECT
1555745691SmillertReversed += operator at - line 3.
16*6fb12b70Safresh1Name "main::c" used only once: possible typo at - line 3.
1755745691Smillert########
1855745691Smillert#! perl -w
1955745691Smillert# warnable code, warnings enabled via #! line
20*6fb12b70Safresh1$c =+ 3 ;
2155745691SmillertEXPECT
2255745691SmillertReversed += operator at - line 3.
23*6fb12b70Safresh1Name "main::c" used only once: possible typo at - line 3.
2455745691Smillert########
2555745691Smillert
2655745691Smillert# warnable code, warnings enabled via compile time $^W
2755745691SmillertBEGIN { $^W = 1 }
28*6fb12b70Safresh1$c =+ 3 ;
2955745691SmillertEXPECT
3055745691SmillertReversed += operator at - line 4.
31*6fb12b70Safresh1Name "main::c" used only once: possible typo at - line 4.
3255745691Smillert########
33898184e3Ssthen-w
34898184e3Ssthen# warnable code, warnings enabled via command line switch
35898184e3Ssthenuse utf8;
36898184e3Ssthenuse open qw( :utf8 :std );
37898184e3Ssthen$Ằ =+ 3 ;
38898184e3SsthenEXPECT
39898184e3SsthenReversed += operator at - line 5.
40898184e3SsthenName "main::Ằ" used only once: possible typo at - line 5.
41898184e3Ssthen########
42898184e3Ssthen#! perl -w
43898184e3Ssthen# warnable code, warnings enabled via #! line
44898184e3Ssthenuse utf8;
45898184e3Ssthenuse open qw( :utf8 :std );
46898184e3Ssthen$Ằ =+ 3 ;
47898184e3SsthenEXPECT
48898184e3SsthenReversed += operator at - line 5.
49898184e3SsthenName "main::Ằ" used only once: possible typo at - line 5.
50898184e3Ssthen########
51898184e3Ssthen
52898184e3Ssthen# warnable code, warnings enabled via compile time $^W
53898184e3SsthenBEGIN { $^W = 1 }
54898184e3Ssthenuse utf8;
55898184e3Ssthenuse open qw( :utf8 :std );
56898184e3Ssthen$Ằ =+ 3 ;
57898184e3SsthenEXPECT
58898184e3SsthenReversed += operator at - line 6.
59898184e3SsthenName "main::Ằ" used only once: possible typo at - line 6.
60898184e3Ssthen
61898184e3Ssthen########
6255745691Smillert
6355745691Smillert# compile-time warnable code, warnings enabled via runtime $^W
6455745691Smillert# so no warning printed.
6555745691Smillert$^W = 1 ;
6655745691Smillert$a =+ 3 ;
6755745691SmillertEXPECT
6855745691Smillert
6955745691Smillert########
7055745691Smillert
7155745691Smillert# warnable code, warnings enabled via runtime $^W
7255745691Smillert$^W = 1 ;
7355745691Smillertmy $b ; chop $b ;
7455745691SmillertEXPECT
75850e2753SmillertUse of uninitialized value $b in scalar chop at - line 4.
7655745691Smillert########
7755745691Smillert
7855745691Smillert# warnings enabled at compile time, disabled at run time
7955745691SmillertBEGIN { $^W = 1 }
8055745691Smillert$^W = 0 ;
8155745691Smillertmy $b ; chop $b ;
8255745691SmillertEXPECT
8355745691Smillert
8455745691Smillert########
8555745691Smillert
8655745691Smillert# warnings disabled at compile time, enabled at run time
8755745691SmillertBEGIN { $^W = 0 }
8855745691Smillert$^W = 1 ;
8955745691Smillertmy $b ; chop $b ;
9055745691SmillertEXPECT
91850e2753SmillertUse of uninitialized value $b in scalar chop at - line 5.
9255745691Smillert########
9355745691Smillert-w
9455745691Smillert--FILE-- abcd
9555745691Smillertmy $b ; chop $b ;
9655745691Smillert1 ;
9755745691Smillert--FILE--
9855745691Smillertrequire "./abcd";
9955745691SmillertEXPECT
100850e2753SmillertUse of uninitialized value $b in scalar chop at ./abcd line 1.
10155745691Smillert########
10255745691Smillert
10355745691Smillert--FILE-- abcd
10455745691Smillertmy $b ; chop $b ;
10555745691Smillert1 ;
10655745691Smillert--FILE--
10755745691Smillert#! perl -w
10855745691Smillertrequire "./abcd";
10955745691SmillertEXPECT
110850e2753SmillertUse of uninitialized value $b in scalar chop at ./abcd line 1.
11155745691Smillert########
11255745691Smillert
11355745691Smillert--FILE-- abcd
11455745691Smillertmy $b ; chop $b ;
11555745691Smillert1 ;
11655745691Smillert--FILE--
11755745691Smillert$^W =1 ;
11855745691Smillertrequire "./abcd";
11955745691SmillertEXPECT
120850e2753SmillertUse of uninitialized value $b in scalar chop at ./abcd line 1.
12155745691Smillert########
12255745691Smillert
12355745691Smillert--FILE-- abcd
12455745691Smillert$^W = 0;
12555745691Smillertmy $b ; chop $b ;
12655745691Smillert1 ;
12755745691Smillert--FILE--
12855745691Smillert$^W =1 ;
12955745691Smillertrequire "./abcd";
13055745691SmillertEXPECT
13155745691Smillert
13255745691Smillert########
13355745691Smillert
13455745691Smillert--FILE-- abcd
13555745691Smillert$^W = 1;
13655745691Smillert1 ;
13755745691Smillert--FILE--
13855745691Smillert$^W =0 ;
13955745691Smillertrequire "./abcd";
14055745691Smillertmy $b ; chop $b ;
14155745691SmillertEXPECT
142850e2753SmillertUse of uninitialized value $b in scalar chop at - line 3.
14355745691Smillert########
14455745691Smillert
14555745691Smillert$^W = 1;
14655745691Smillerteval 'my $b ; chop $b ;' ;
14755745691Smillertprint $@ ;
14855745691SmillertEXPECT
149850e2753SmillertUse of uninitialized value $b in scalar chop at (eval 1) line 1.
15055745691Smillert########
15155745691Smillert
15255745691Smillerteval '$^W = 1;' ;
15355745691Smillertprint $@ ;
15455745691Smillertmy $b ; chop $b ;
15555745691SmillertEXPECT
156850e2753SmillertUse of uninitialized value $b in scalar chop at - line 4.
15755745691Smillert########
15855745691Smillert
15955745691Smillerteval {$^W = 1;} ;
16055745691Smillertprint $@ ;
16155745691Smillertmy $b ; chop $b ;
16255745691SmillertEXPECT
163850e2753SmillertUse of uninitialized value $b in scalar chop at - line 4.
16455745691Smillert########
16555745691Smillert
16655745691Smillert{
16755745691Smillert    local ($^W) = 1;
16855745691Smillert}
16955745691Smillertmy $b ; chop $b ;
17055745691SmillertEXPECT
17155745691Smillert
17255745691Smillert########
17355745691Smillert
17455745691Smillertmy $a ; chop $a ;
17555745691Smillert{
17655745691Smillert    local ($^W) = 1;
17755745691Smillert    my $b ; chop $b ;
17855745691Smillert}
17955745691Smillertmy $c ; chop $c ;
18055745691SmillertEXPECT
181850e2753SmillertUse of uninitialized value $b in scalar chop at - line 5.
18255745691Smillert########
18355745691Smillert-w
18455745691Smillert-e undef
18555745691SmillertEXPECT
18655745691SmillertUse of uninitialized value in -e at - line 2.
18755745691Smillert########
18855745691Smillert
18955745691Smillert$^W = 1 + 2 ;
19055745691SmillertEXPECT
19155745691Smillert
19255745691Smillert########
19355745691Smillert
19455745691Smillert$^W = $a ;
19555745691SmillertEXPECT
19655745691Smillert
19755745691Smillert########
19855745691Smillert
19955745691Smillertsub fred {}
20055745691Smillert$^W = fred() ;
20155745691SmillertEXPECT
20255745691Smillert
20355745691Smillert########
20455745691Smillert
20555745691Smillertsub fred { my $b ; chop $b ;}
20655745691Smillert{ local $^W = 0 ;
20755745691Smillert  fred() ;
20855745691Smillert}
20955745691SmillertEXPECT
21055745691Smillert
21155745691Smillert########
21255745691Smillert
21355745691Smillertsub fred { my $b ; chop $b ;}
21455745691Smillert{ local $^W = 1 ;
21555745691Smillert  fred() ;
21655745691Smillert}
21755745691SmillertEXPECT
218850e2753SmillertUse of uninitialized value $b in scalar chop at - line 2.
219