~ubuntu-branches/ubuntu/natty/libconfig-inifiles-perl/natty-updates

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
#!/usr/bin/perl
# This script is a regression test for:
#
# https://rt.cpan.org/Ticket/Display.html?id=45997
#
# Failure to read the ini file contents from a filehandle made out of a scalar

use Test::More;

use strict;
use warnings;

use Carp qw(cluck);
use English qw(-no_match_vars);

use Config::IniFiles;

if ( ! eval { require IO::Scalar; } )
{
    plan skip_all => "IO::Scalar is not available";
}
else
{
    plan tests => 2;
}

{
    my $contents = <<'EOF';
[section1]
key = val
EOF

    open my $scalar_fh, "<", \$contents;

    my $conf = eval {
        $WARNING = 1;
        $SIG{__WARN__} = \&Carp::croak;
        Config::IniFiles->new( -file => $scalar_fh);
    } or warn $EVAL_ERROR;

    # TEST
    ok(!$EVAL_ERROR, "Object was initialised from filehandle made out of a scalar.");

    # TEST
    is ($conf->val("section1", "key"), 
        "val",
        "Object works."
    );

    undef $conf;
    close $scalar_fh;
}