File: void-context.t

package info (click to toggle)
libfile-pushd-perl 1.016-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 263; makefile: 7
file content (48 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More 0.96;
use File::pushd;

my @warnings;

$SIG{__WARN__} = sub {
    push @warnings, $_[0];
};

{
    no warnings 'void';

    @warnings = ();
    pushd; # Calling in void context
    is_deeply( \@warnings, [], 'no warning if "void" category disabled' );
    @warnings = ();
    tempd; # Calling in void context
    is_deeply( \@warnings, [], 'no warning if "void" category disabled' );

    @warnings = ();
}

{
    no warnings;
    use warnings 'void';

    @warnings = ();
    #<<< No perltidy
    pushd; # Calling in void context
    my $expected = 'Useless use of File::pushd::pushd in void context at '.__FILE__.' line '.(__LINE__-1);
    #>>>
    is( scalar @warnings, 1, "pushd: got one warning" );
    like( $warnings[0], qr/^\Q$expected\E/, 'warning if "void" category enabled' );

    @warnings = ();
    #<<< No perltidy
    tempd; # Calling in void context
    $expected = 'Useless use of File::pushd::tempd in void context at '.__FILE__.' line '.(__LINE__-1);
    #>>>
    is( scalar @warnings, 1, "tempd: got one warning" );
    like( $warnings[0], qr/^\Q$expected\E/, 'warning if "void" category enabled' );

    @warnings = ();
}

done_testing;