File: 31-env.t

package info (click to toggle)
libdevel-nytprof-perl 4.04-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,124 kB
  • ctags: 1,330
  • sloc: perl: 4,392; ansic: 92; makefile: 19
file content (43 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (5)
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
use Test::More;
require XSLoader;

# Disable "once" warnings
BEGIN {
    my $ok = eval { require warnings; 1 };
    if ( $ok ) {
        warnings->unimport( qw( once redefine ) );
    }
    else {
        $^W = 0;
    }
}

my @tests = (
    [ 'start=no:file=nytprof.out'  => { start => 'no', file => 'nytprof.out' } ],
    [ 'start=no:file=nytprof\:out' => { start => 'no', file => 'nytprof:out' } ],
    [ 'start=no:file=nytprof\=out' => { start => 'no', file => 'nytprof=out' } ],
);

plan( tests => 1 * @tests );
for my $test ( @tests ) {
    my ( $nytprof, $expected ) = @$test;

    # Abrogate the XSLoader used to load the XS function DB::set_option.
    local *XSLoader::load = sub {};

    # Hook the function used to set options to capture it's parsing.
    my %got;
    local *DB::set_option = sub {
        my ( $k, $v ) = @_;
        $got{$k} = $v;
    };
    
    # (pretend to) Unload the class.
    delete $INC{'Devel/NYTProf/Core.pm'};

    # Test the class's parsing.
    local $ENV{NYTPROF} = $nytprof;
    require Devel::NYTProf::Core;
    is_deeply( \%got, $expected, "Parsed \$ENV{NYTPROF}='$nytprof' ok" );
}