File: 002_strict_and_warnings.t

package info (click to toggle)
libdancer-perl 1.3521%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,460 kB
  • sloc: perl: 7,436; xml: 2,211; sh: 54; makefile: 32; sql: 5
file content (61 lines) | stat: -rw-r--r-- 1,579 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use Test::More tests => 10, import => ['!pass'];

{
    package Webapp;
    use Dancer ':syntax';

    # strict
    eval '$foo = 5;';
    ::ok($@, 'got an error because strict is on');
    ::like $@, qr/Global symbol "\$foo" requires explicit package name/,
        'got the right error';

    # checking warnings are on by default
    {
        my $warn;
        local $SIG{__WARN__} = sub { $warn = $_[0] };

        ::ok(!$warn, 'no warning yet');
                
        eval 'my $bar = 1 + "hello"';
        
        ::ok($warn, 'got a warning - default');
        ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, 
            'got the right warning');
    }

    # check that we can disable it
    {
        # setting import_warnings => 0;
        #        
        # Since we're importing warnings in Dancer.pm as documented,
        # no warnings; should be used instead of import_warnings;
        no warnings;

        my $warn;
        local $SIG{__WARN__} = sub { $warn = $_[0] };

        ::ok( !$warn, 'no warnings yet' );

        eval 'my $bar = 1 + "hello"';

        ::ok( !$warn, 'no warnings now either' );
    }

    # check that we can enable it
    {
        setting global_warnings => 1;

        my $warn;
        local $SIG{__WARN__} = sub { $warn = $_[0] };

        ::ok(!$warn, 'no warning yet');

        eval 'my $bar = 1 + "hello"';

        ::ok($warn, 'got a warning - after enabling import');
        ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/,
            'got the right warning');
    }

}