Check lexical warnings functionality

TODO
  check that the warning hierarchy works.

__END__

#  check illegal category is caught
use warnings 'this-should-never-be-a-warning-category' ;
EXPECT
Unknown warnings category 'this-should-never-be-a-warning-category' at - line 3.
BEGIN failed--compilation aborted at - line 3.
########

# Check compile time scope of pragma
use warnings 'syntax' ;
{
    no warnings ;
    my $a =+ 1 ;
}
my $a =+ 1 ;
EXPECT
Reversed += operator at - line 8.
########

# Check compile time scope of pragma
no warnings;
{
    use warnings 'syntax' ;
    my $a =+ 1 ;
}
my $a =+ 1 ;
EXPECT
Reversed += operator at - line 6.
########

# Check runtime scope of pragma
use warnings 'uninitialized' ;
{
    no warnings ;
    my $b ; chop $b ;
}
my $b ; chop $b ;
EXPECT
Use of uninitialized value $b in scalar chop at - line 8.
########

# Check runtime scope of pragma
no warnings ;
{
    use warnings 'uninitialized' ;
    my $b ; chop $b ;
}
my $b ; chop $b ;
EXPECT
Use of uninitialized value $b in scalar chop at - line 6.
########

# Check runtime scope of pragma
no warnings ;
{
    use warnings 'uninitialized' ;
    $a = sub { my $b ; chop $b ; }
}
&$a ;
EXPECT
Use of uninitialized value $b in scalar chop at - line 6.
########

use warnings 'syntax' ;
my $a =+ 1 ;
EXPECT
Reversed += operator at - line 3.
########
-w
no warnings 'reserved' ;
foo.bar;
EXPECT
Useless use of a constant ("foobar") in void context at - line 3.
########

# Check -negative import with no other args
use warnings qw(-syntax);
sub foo { 'foo' }
my $a =+ 1 ;          # syntax:        shouldn't warn, it was never turned on
*foo = sub { 'bar' }; # redefine:      shouldn't warn, it was never turned on
$a = 'foo' . undef;   # uninitialized: shouldn't warn, it was never turned on
EXPECT
########

# Check -negative import after turning all warnings on
use warnings qw(all -syntax);
sub foo { 'foo' }
my $a =+ 1 ;          # syntax:        shouldn't warn, we've turned that off
*foo = sub { 'bar' }; # redefine:      should warn, as there was an explicit 'all'
$a = 'foo' . undef;   # uninitialized: should warn, as there was an explicit 'all'
EXPECT
Subroutine main::foo redefined at - line 6.
Use of uninitialized value in concatenation (.) or string at - line 7.
########

# Check -negative import with an explicit import
use warnings qw(redefine -syntax);
sub foo { 'foo' }
my $a =+ 1 ;          # syntax:        shouldn't warn, it was never turned on
*foo = sub { 'bar' }; # redefine:      should warn, as there was an explicit 'redefine'
$a = 'foo' . undef;   # uninitialized: shouldn't warn, as explicit 'redefine' means no implicit 'all'
EXPECT
Subroutine main::foo redefined at - line 6.
########

# Check multiple -negative imports
use warnings qw(all -syntax -uninitialized);
sub foo { 'foo' }
my $a =+ 1 ;          # syntax:        shouldn't warn, we've turned that off
*foo = sub { 'bar' }; # redefine:      should warn, as there was an explicit 'all'
$a = 'foo' . undef;   # uninitialized: shouldn't warn, we've turned it off
EXPECT
Subroutine main::foo redefined at - line 6.
########

# Check mixed list of +ve and -ve imports
use warnings qw(all -once -syntax parenthesis);
sub foo { 'foo' }
*foo = sub { 'bar' };  # redefined:   should warn, as it was turned on by 'all'
my $a =+ 1 ;           # syntax:      shouldn't warn, we've turned that off
my $foo, $bar = @_;    # parenthesis: should warn, as we turned that back on after disabling 'syntax'
EXPECT
Parentheses missing around "my" list at - line 7.
Subroutine main::foo redefined at - line 5.
########

--FILE-- abc
my $a =+ 1 ;
1;
--FILE-- 
use warnings 'syntax' ;
require "./abc";
EXPECT

########

--FILE-- abc
use warnings 'syntax' ;
1;
--FILE-- 
require "./abc";
my $a =+ 1 ;
EXPECT

########

--FILE-- abc
use warnings 'syntax' ;
my $a =+ 1 ;
1;
--FILE-- 
use warnings 'uninitialized' ;
require "./abc";
my $a ; chop $a ;
EXPECT
Reversed += operator at ./abc line 2.
Use of uninitialized value $a in scalar chop at - line 3.
########

--FILE-- abc.pm
use warnings 'syntax' ;
my $a =+ 1 ;
1;
--FILE-- 
use warnings 'uninitialized' ;
use abc;
my $a ; chop $a ;
EXPECT
Reversed += operator at abc.pm line 2.
Use of uninitialized value $a in scalar chop at - line 3.
########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval {
        my $b ; chop $b ;
    }; print STDERR $@ ;
    my $b ; chop $b ;
}
EXPECT

########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval {
        use warnings 'uninitialized' ;
        my $b ; chop $b ;
    }; print STDERR $@ ;
    my $b ; chop $b ;
}
EXPECT
Use of uninitialized value $b in scalar chop at - line 8.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'uninitialized' ;
    eval {
        my $b ; chop $b ;
    }; print STDERR $@ ;
    my $b ; chop $b ;
}
EXPECT
Use of uninitialized value $b in scalar chop at - line 7.
Use of uninitialized value $b in scalar chop at - line 9.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'uninitialized' ;
    eval {
        no warnings ;
        my $b ; chop $b ;
    }; print STDERR $@ ;
    my $b ; chop $b ;
}
EXPECT
Use of uninitialized value $b in scalar chop at - line 10.
########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval {
        my $a =+ 1 ;
    }; print STDERR $@ ;
    my $a =+ 1 ;
}
EXPECT

########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval {
        use warnings 'syntax' ;
        my $a =+ 1 ;
    }; print STDERR $@ ;
    my $a =+ 1 ;
}
EXPECT
Reversed += operator at - line 8.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'syntax' ;
    eval {
        my $a =+ 1 ;
    }; print STDERR $@ ;
    my $a =+ 1 ;
}
EXPECT
Reversed += operator at - line 7.
Reversed += operator at - line 9.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'syntax' ;
    eval {
        no warnings ;
        my $a =+ 1 ;
    }; print STDERR $@ ;
    my $a =+ 1 ;
}
EXPECT
Reversed += operator at - line 10.
########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval '
        my $b ; chop $b ;
    '; print STDERR $@ ;
    my $b ; chop $b ;
}
EXPECT

########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval q[ 
        use warnings 'uninitialized' ;
        my $b ; chop $b ;
    ]; print STDERR $@;
    my $b ; chop $b ;
}
EXPECT
Use of uninitialized value $b in scalar chop at (eval 1) line 3.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'uninitialized' ;
    eval '
        my $b ; chop $b ;
    '; print STDERR $@ ;
    my $b ; chop $b ;
}
EXPECT
Use of uninitialized value $b in scalar chop at (eval 1) line 2.
Use of uninitialized value $b in scalar chop at - line 9.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'uninitialized' ;
    eval '
        no warnings ;
        my $b ; chop $b ;
    '; print STDERR $@ ;
    my $b ; chop $b ;
}
EXPECT
Use of uninitialized value $b in scalar chop at - line 10.
########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval '
        my $a =+ 1 ;
    '; print STDERR $@ ;
    my $a =+ 1 ;
}
EXPECT

########

# Check scope of pragma with eval
use warnings;
{
    no warnings ;
    eval q[ 
        use warnings 'syntax' ;
        my $a =+ 1 ;
    ]; print STDERR $@;
    my $a =+ 1 ;
}
EXPECT
Reversed += operator at (eval 1) line 3.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'syntax' ;
    eval '
        my $a =+ 1 ;
    '; print STDERR $@;
    my $a =+ 1 ;
}
EXPECT
Reversed += operator at - line 9.
Reversed += operator at (eval 1) line 2.
########

# Check scope of pragma with eval
no warnings;
{
    use warnings 'syntax' ;
    eval '
        no warnings ;
        my $a =+ 1 ;
    '; print STDERR $@;
    my $a =+ 1 ;
}
EXPECT
Reversed += operator at - line 10.
########

# Check the additive nature of the pragma
my $a =+ 1 ;
my $a ; chop $a ;
use warnings 'syntax' ;
$a =+ 1 ;
my $b ; chop $b ;
use warnings 'uninitialized' ;
my $c ; chop $c ;
no warnings 'syntax' ;
$a =+ 1 ;
EXPECT
Reversed += operator at - line 6.
Use of uninitialized value $c in scalar chop at - line 9.
########
