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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
use strict;
use warnings;
use Test::More tests => 30;
use Test::NoWarnings;
use lib './lib';
use File::Util;
my $ftl;
# one recognized instantiation setting
$ftl = File::Util->new( use_flock => 0 );
is ref $ftl, 'File::Util',
'new() is blessed correctly after flock toggle invocation';
is $ftl->use_flock() , 0,
'flock off-toggle sticks after blessing';
# another recognized instantiation setting
$ftl = File::Util->new( readlimit => 1234567890 );
is ref $ftl, 'File::Util',
'new() is blessed correctly after readlimit-set invocation';
cmp_ok $ftl->readlimit , '==', 1234567890,
'readlimit (legacy) setting sticks after blessing';
cmp_ok $ftl->read_limit , '==', 1234567890,
'read_limit (new-style) setting sticks after blessing';
# yet another recognized instantiation setting
$ftl = File::Util->new( abort_depth => 9876543210 );
is ref $ftl, 'File::Util',
'new() is blessed right after abort_depth-set invocation';
cmp_ok $ftl->abort_depth, '==', 9876543210,
'abort_depth toggle sticks after abort_depth-set invocation';
# all recognized per-instantiation settings
$ftl = File::Util->new
(
use_flock => 1,
read_limit => 1111111,
abort_depth => 2222222
);
is ref $ftl, 'File::Util',
'new() blessed right with multi-toggle';
is $ftl->use_flock() , 1,
'use_flock sticks after multi-toggle';
cmp_ok $ftl->readlimit, '==', 1111111,
'readlimit (legacy) sticks after multi-toggle blessing';
cmp_ok $ftl->read_limit, '==', 1111111,
'read_limit (new-style) sticks after multi-toggle blessing';
cmp_ok $ftl->abort_depth, '==', 2222222,
'abort_depth sticks after multi-toggle blessing';
# one recognized flag
$ftl = File::Util->new( '--fatals-as-warning' );
is ref $ftl, 'File::Util',
'new() blessed right with fatals toggle';
cmp_ok $ftl->{opts}{fatals_as_warning}, '==', 1,
'modern internal setting matches toggle';
cmp_ok $ftl->{opts}{'--fatals-as-warning'}, '==', 1,
'classic internal setting matches toggle';
# another recognized flag
$ftl = File::Util->new( '--fatals-as-status' );
is ref $ftl, 'File::Util', 'blessed ok after classic instantiation';
is $ftl->{opts}{fatals_as_status}, 1,
'peek at internals looks good for "fatals_as_status"';
is $ftl->{opts}{'--fatals-as-status'}, 1,
'peek at internals looks good for "--fatals_as_status"';
# yet another recognized flag
$ftl = File::Util->new( '--fatals-as-errmsg' );
is ref $ftl, 'File::Util', 'blessed ok after classic instantiation';
is $ftl->{opts}{fatals_as_errmsg}, 1,
'peek at internals looks good for "fatals_as_errmsg"';
is $ftl->{opts}{'--fatals-as-errmsg'}, 1,
'peek at internals looks good for "--fatals-as-errmsg"';
# all settings and one recognized flag, using ::Modern syntax
$ftl = File::Util->new(
{
use_flock => 0,
readlimit => 1111111,
abort_depth => 2222222,
fatals_as_status => 1,
warn_also => 1
}
);
is ref $ftl, 'File::Util',
'blessed ok after modern instantiation with multiple opts';
is $ftl->use_flock(), 0,
'flock toggle correct after modern multi-opt instantiation';
cmp_ok $ftl->readlimit(), '==', 1111111,
'readlimit setting correct after modern multi-opt instantiation';
cmp_ok $ftl->abort_depth(), '==', 2222222,
'abort_depth setting correct after modern multi-opt instantiation';
is $ftl->{opts}{fatals_as_status}, 1,
'peek at internals ok for "fatals_as_status"';
is $ftl->{opts}{warn_also}, 1,
'peek at internals ok for "warn_also"';
is $ftl->{opts}{fatals_as_warning}, undef,
'peek at internals ok for !defined "fatals_as_warning"';
is $ftl->{opts}{fatals_as_errmsg}, undef,
'peek at internals ok for !defined "fatals_as_errmsg"';
exit;
|