2009-10-10 16:21:31 +00:00
|
|
|
|
# -*-perl-*-
|
2009-10-10 16:11:25 +00:00
|
|
|
|
# testscript for Config::General Classes by Thomas Linden
|
|
|
|
|
|
#
|
2009-10-10 16:07:21 +00:00
|
|
|
|
# needs to be invoked using the command "make test" from
|
2009-10-10 16:11:25 +00:00
|
|
|
|
# the Config::General source directory.
|
|
|
|
|
|
#
|
|
|
|
|
|
# Under normal circumstances every test should succeed.
|
2009-10-10 16:07:21 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
|
2009-10-10 16:10:12 +00:00
|
|
|
|
use Data::Dumper;
|
2010-04-09 08:56:40 +00:00
|
|
|
|
use Test::More tests => 63;
|
2010-04-08 15:48:03 +00:00
|
|
|
|
#use Test::More qw(no_plan);
|
2009-10-10 16:21:31 +00:00
|
|
|
|
|
2009-10-10 16:45:27 +00:00
|
|
|
|
# ahem, we deliver the test code with a local copy of
|
|
|
|
|
|
# the Tie::IxHash module so we can do tests on sorted
|
|
|
|
|
|
# hashes without dependency to Tie::IxHash.
|
|
|
|
|
|
use lib qw(t);
|
|
|
|
|
|
use Tie::IxHash;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 1
|
|
|
|
|
|
BEGIN { use_ok "Config::General"};
|
|
|
|
|
|
require_ok( 'Config::General' );
|
2009-10-10 16:26:19 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 2 - 7
|
|
|
|
|
|
foreach my $num (2..7) {
|
|
|
|
|
|
my $cfg = "t/cfg.$num";
|
|
|
|
|
|
open T, "<$cfg";
|
|
|
|
|
|
my @file = <T>;
|
|
|
|
|
|
close T;
|
|
|
|
|
|
my $fst = $file[0];
|
|
|
|
|
|
chomp $fst;
|
|
|
|
|
|
$fst =~ s/\#\s*//g;
|
|
|
|
|
|
eval {
|
|
|
|
|
|
my $conf = new Config::General($cfg);
|
|
|
|
|
|
my %hash = $conf->getall;
|
|
|
|
|
|
};
|
|
|
|
|
|
ok(!$@, "$fst");
|
|
|
|
|
|
}
|
2009-10-10 16:21:31 +00:00
|
|
|
|
|
2009-10-10 16:07:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 8
|
2009-10-10 16:10:12 +00:00
|
|
|
|
my $conf = new Config::General("t/cfg.8");
|
2009-10-10 16:07:21 +00:00
|
|
|
|
my %hash = $conf->getall;
|
2009-10-10 16:21:31 +00:00
|
|
|
|
$conf->save_file("t/cfg.out");
|
2009-10-10 16:07:21 +00:00
|
|
|
|
my $copy = new Config::General("t/cfg.out");
|
|
|
|
|
|
my %copyhash = $copy->getall;
|
2009-10-10 16:38:28 +00:00
|
|
|
|
is_deeply(\%hash, \%copyhash, "Writing Config Hash to disk and compare with original");
|
2009-10-10 16:07:21 +00:00
|
|
|
|
|
2009-10-10 16:11:25 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 9
|
2009-10-10 16:21:31 +00:00
|
|
|
|
$conf = new Config::General(
|
2009-10-10 16:38:28 +00:00
|
|
|
|
-ExtendedAccess => 1,
|
|
|
|
|
|
-ConfigFile => "t/test.rc");
|
|
|
|
|
|
ok($conf, "Creating a new object from config file");
|
2009-10-10 16:11:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 10
|
2009-10-10 16:21:31 +00:00
|
|
|
|
my $conf2 = new Config::General(
|
2009-10-10 16:38:28 +00:00
|
|
|
|
-ExtendedAccess => 1,
|
|
|
|
|
|
-ConfigFile => "t/test.rc",
|
|
|
|
|
|
-AllowMultiOptions => "yes"
|
|
|
|
|
|
);
|
|
|
|
|
|
ok($conf2, "Creating a new object using the hash parameter way");
|
2009-10-10 16:11:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 11
|
2009-10-10 16:11:25 +00:00
|
|
|
|
my $domain = $conf->obj("domain");
|
2009-10-10 16:38:28 +00:00
|
|
|
|
ok($domain, "Creating a new object from a block");
|
2009-10-10 16:11:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 12
|
2009-10-10 16:11:25 +00:00
|
|
|
|
my $addr = $domain->obj("bar.de");
|
2009-10-10 16:38:28 +00:00
|
|
|
|
ok($addr, "Creating a new object from a sub block");
|
2009-10-10 16:11:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 13
|
2009-10-10 16:11:25 +00:00
|
|
|
|
my @keys = $conf->keys("domain");
|
2009-10-10 16:38:28 +00:00
|
|
|
|
ok($#keys > -1, "Getting values from the object");
|
2009-10-10 16:11:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 14
|
2009-10-10 16:11:25 +00:00
|
|
|
|
# test various OO methods
|
2009-10-10 16:38:28 +00:00
|
|
|
|
my $a;
|
2009-10-10 16:11:25 +00:00
|
|
|
|
if ($conf->is_hash("domain")) {
|
|
|
|
|
|
my $domains = $conf->obj("domain");
|
|
|
|
|
|
foreach my $domain ($conf->keys("domain")) {
|
|
|
|
|
|
my $domain_obj = $domains->obj($domain);
|
|
|
|
|
|
foreach my $address ($domains->keys($domain)) {
|
2009-10-10 16:38:28 +00:00
|
|
|
|
$a = $domain_obj->value($address);
|
2009-10-10 16:11:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-10-10 16:38:28 +00:00
|
|
|
|
ok($a, "Using keys() and values()");
|
2009-10-10 16:21:31 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 15
|
2009-10-10 16:11:25 +00:00
|
|
|
|
# test AUTOLOAD methods
|
2009-10-10 16:38:28 +00:00
|
|
|
|
eval {
|
|
|
|
|
|
my $conf3 = new Config::General(
|
|
|
|
|
|
-ExtendedAccess => 1,
|
|
|
|
|
|
-ConfigHash => { name => "Moser", prename => "Hannes"}
|
|
|
|
|
|
);
|
|
|
|
|
|
my $n = $conf3->name;
|
|
|
|
|
|
my $p = $conf3->prename;
|
|
|
|
|
|
$conf3->name("Meier");
|
|
|
|
|
|
$conf3->prename("Max");
|
|
|
|
|
|
$conf3->save_file("t/test.cfg");
|
|
|
|
|
|
};
|
|
|
|
|
|
ok (!$@, "Using AUTOLOAD methods");
|
2009-10-10 16:11:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 16
|
2009-10-10 16:17:24 +00:00
|
|
|
|
# testing variable interpolation
|
2009-10-10 16:25:41 +00:00
|
|
|
|
my $conf16 = new Config::General(-ConfigFile => "t/cfg.16", -InterPolateVars => 1, -StrictVars => 0);
|
2009-10-10 16:17:24 +00:00
|
|
|
|
my %h16 = $conf16->getall();
|
2009-10-10 16:38:28 +00:00
|
|
|
|
if($h16{etc}->{log} eq "/usr/log/logfile" and
|
|
|
|
|
|
$h16{etc}->{users}->{home} eq "/usr/home/max" and
|
|
|
|
|
|
exists $h16{dir}->{teri}->{bl}) {
|
|
|
|
|
|
pass("Testing variable interpolation");
|
2009-10-10 16:17:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2009-10-10 16:38:28 +00:00
|
|
|
|
fail("Testing variable interpolation");
|
2009-10-10 16:17:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2.43
- fixed rt.cpan.org#40925, $indichar replaced by internal
configuration variable EOFseparator, which contains
a 256 bit SHA checksum of the date I fixed the bug.
This will prevent future conflicts hopefully. In addition
it makes it possible to make it customizable, if neccessary,
in a future release.
- fixed rt.cpan.org#42721, return undef for empty values
- fixed rt.cpan.org#42331, return undef for empty objects
- fixed rt.cpan.org#44600, comments after blockname
causes parser failure.
- fixed rt.cpan.org#42287, whitespace at beginning or end
of a quoted value gets lost after save().
- fixed rt.cpan.org#46184, variables that were not previously
defined are deleted when -InterPolateEnv is enabled.
- fixed bug in config loader for FileHandle objects, it
supports now any compatible object. Hint by Ingo Schmiegel.
- applied spelling- and speedup patches by Ville Skyttä.
- applied documentation patch by Jordan Macdonald.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@69 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:46:35 +00:00
|
|
|
|
### 16.a
|
|
|
|
|
|
# testing variable interpolation with %ENV use
|
|
|
|
|
|
my $env = "/home/theunexistent";
|
|
|
|
|
|
$ENV{HOME} = $env;
|
|
|
|
|
|
my $conf16a = new Config::General(-ConfigFile => "t/cfg.16a", -InterPolateVars => 1, -InterPolateEnv => 1, -StrictVars => 0);
|
|
|
|
|
|
my %h16a = $conf16a->getall();
|
|
|
|
|
|
if($h16a{etc}->{log} eq "$env/log/logfile") {
|
|
|
|
|
|
pass("Testing environment variable interpolation");
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
fail("Testing environment variable interpolation");
|
|
|
|
|
|
}
|
2009-10-10 16:17:24 +00:00
|
|
|
|
|
2009-10-10 16:42:58 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 17
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
# testing value pre-setting using a hash
|
|
|
|
|
|
my $conf17 = new Config::General(
|
2009-10-10 16:38:28 +00:00
|
|
|
|
-file => "t/cfg.17",
|
2009-10-10 16:42:58 +00:00
|
|
|
|
-DefaultConfig => { home => "/exports/home",
|
|
|
|
|
|
logs => "/var/backlog",
|
|
|
|
|
|
foo => {
|
|
|
|
|
|
bar => "quux"
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
-InterPolateVars => 1,
|
2009-10-10 16:38:28 +00:00
|
|
|
|
-MergeDuplicateOptions => 1,
|
|
|
|
|
|
-MergeDuplicateBlocks => 1
|
|
|
|
|
|
);
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
my %h17 = $conf17->getall();
|
2009-10-10 16:42:58 +00:00
|
|
|
|
ok ($h17{home} eq "/home/users" &&
|
|
|
|
|
|
$h17{foo}{quux} eq "quux",
|
|
|
|
|
|
"Testing value pre-setting using a hash");
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 18
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
# testing value pre-setting using a string
|
|
|
|
|
|
my $conf18 = new Config::General(
|
2009-10-10 16:38:28 +00:00
|
|
|
|
-file => "t/cfg.17", # reuse the file
|
|
|
|
|
|
-DefaultConfig => "home = /exports/home\nlogs = /var/backlog",
|
|
|
|
|
|
-MergeDuplicateOptions => 1,
|
|
|
|
|
|
-MergeDuplicateBlocks => 1
|
|
|
|
|
|
);
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
my %h18 = $conf18->getall();
|
2009-10-10 16:38:28 +00:00
|
|
|
|
ok ($h18{home} eq "/home/users", "Testing value pre-setting using a string");
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 19
|
2009-10-10 16:26:19 +00:00
|
|
|
|
# testing various otion/value assignment notations
|
2009-10-10 16:22:10 +00:00
|
|
|
|
my $conf19 = new Config::General(-file => "t/cfg.19");
|
|
|
|
|
|
my %h19 = $conf19->getall();
|
|
|
|
|
|
my $works = 1;
|
|
|
|
|
|
foreach my $key (keys %h19) {
|
|
|
|
|
|
if ($key =~ /\s/) {
|
|
|
|
|
|
$works = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2009-10-10 16:38:28 +00:00
|
|
|
|
ok ($works, "Testing various otion/value assignment notations");
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 20
|
2009-10-10 16:31:34 +00:00
|
|
|
|
# testing files() method
|
|
|
|
|
|
my $conf20 = Config::General->new(
|
|
|
|
|
|
-file => "t/cfg.20.a",
|
|
|
|
|
|
-MergeDuplicateOptions => 1
|
|
|
|
|
|
);
|
|
|
|
|
|
my %h20 = $conf20->getall();
|
|
|
|
|
|
my %files = map { $_ => 1 } $conf20->files();
|
|
|
|
|
|
my %expected_files = map { $_ => 1 } (
|
|
|
|
|
|
't/cfg.20.a',
|
|
|
|
|
|
't/cfg.20.b',
|
|
|
|
|
|
't/cfg.20.c',
|
|
|
|
|
|
);
|
2009-10-10 16:38:28 +00:00
|
|
|
|
is_deeply (\%files, \%expected_files, "testing files() method");
|
2009-10-10 16:31:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 22
|
2009-10-10 16:31:34 +00:00
|
|
|
|
# testing improved IncludeRelative option
|
|
|
|
|
|
# First try without -IncludeRelative
|
|
|
|
|
|
# this should fail
|
|
|
|
|
|
eval {
|
|
|
|
|
|
my $conf21 = Config::General->new(
|
|
|
|
|
|
-file => "t/sub1/sub2/sub3/cfg.sub3",
|
|
|
|
|
|
-MergeDuplicateOptions => 1,
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
2009-10-10 16:38:28 +00:00
|
|
|
|
ok ($@, "prevented from loading relative cfgs without -IncludeRelative");
|
2009-10-10 16:31:34 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
|
|
|
|
|
|
### 23
|
2009-10-10 16:31:34 +00:00
|
|
|
|
# Now try with -IncludeRelative
|
|
|
|
|
|
# this should fail
|
|
|
|
|
|
my $conf22 = Config::General->new(
|
|
|
|
|
|
-file => "t/sub1/sub2/sub3/cfg.sub3",
|
|
|
|
|
|
-MergeDuplicateOptions => 1,
|
|
|
|
|
|
-IncludeRelative => 1,
|
|
|
|
|
|
);
|
|
|
|
|
|
my %h22 = $conf22->getall;
|
|
|
|
|
|
my %expected_h22 = (
|
2009-10-10 16:36:29 +00:00
|
|
|
|
'sub3_seen' => 'yup',
|
|
|
|
|
|
'sub2_seen' => 'yup',
|
|
|
|
|
|
'sub2b_seen' => 'yup',
|
|
|
|
|
|
'sub1_seen' => 'yup',
|
|
|
|
|
|
'sub1b_seen' => 'yup',
|
|
|
|
|
|
'fruit' => 'mango',
|
2009-10-10 16:31:34 +00:00
|
|
|
|
);
|
2009-10-10 16:38:28 +00:00
|
|
|
|
is_deeply(\%h22, \%expected_h22, "loaded relative to included files");
|
2009-10-10 16:31:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 24
|
2009-10-10 16:36:29 +00:00
|
|
|
|
# Testing IncludeDirectories option
|
|
|
|
|
|
my $conf23 = Config::General->new(
|
|
|
|
|
|
-String => "<<include t/sub1>>",
|
|
|
|
|
|
-IncludeDirectories => 1
|
|
|
|
|
|
);
|
|
|
|
|
|
my %h23 = $conf23->getall;
|
|
|
|
|
|
my %expected_h23 = (
|
|
|
|
|
|
fruit => 'mango',
|
|
|
|
|
|
sub1_seen => 'yup',
|
|
|
|
|
|
sub1b_seen => 'yup',
|
|
|
|
|
|
test => 'value',
|
|
|
|
|
|
test2 => 'value2',
|
|
|
|
|
|
test3 => 'value3'
|
|
|
|
|
|
);
|
2009-10-10 16:38:28 +00:00
|
|
|
|
is_deeply(\%h23, \%expected_h23, "including a directory with -IncludeDirectories");
|
2009-10-10 16:36:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 24
|
2009-10-10 16:36:29 +00:00
|
|
|
|
# Testing IncludeGlob option
|
|
|
|
|
|
my $conf24 = Config::General->new(
|
|
|
|
|
|
-String => "<<include t/sub1/cfg.sub[123]{c,d,e}>>",
|
|
|
|
|
|
-IncludeGlob => 1
|
|
|
|
|
|
);
|
|
|
|
|
|
my %h24 = $conf24->getall;
|
|
|
|
|
|
my %expected_h24 = (
|
|
|
|
|
|
test => 'value',
|
|
|
|
|
|
test2 => 'value2',
|
|
|
|
|
|
test3 => 'value3'
|
|
|
|
|
|
);
|
2009-10-10 16:38:28 +00:00
|
|
|
|
is_deeply(\%h24, \%expected_h24, "including multiple files via glob pattern with -IncludeGlob");
|
2009-10-10 16:36:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 25
|
2009-10-10 16:36:29 +00:00
|
|
|
|
# Testing block and block name quoting
|
|
|
|
|
|
my $conf25 = Config::General->new(
|
|
|
|
|
|
-String => <<TEST,
|
|
|
|
|
|
<block "/">
|
|
|
|
|
|
opt1 val1
|
|
|
|
|
|
</block>
|
|
|
|
|
|
<"block2 /">
|
|
|
|
|
|
opt2 val2
|
|
|
|
|
|
</"block2 /">
|
|
|
|
|
|
<"block 3" "/">
|
|
|
|
|
|
opt3 val3
|
|
|
|
|
|
</"block 3">
|
|
|
|
|
|
<block4 />
|
|
|
|
|
|
opt4 val4
|
|
|
|
|
|
</block4>
|
|
|
|
|
|
TEST
|
|
|
|
|
|
-SlashIsDirectory => 1
|
|
|
|
|
|
);
|
|
|
|
|
|
my %h25 = $conf25->getall;
|
|
|
|
|
|
my %expected_h25 = (
|
|
|
|
|
|
block => { '/' => { opt1 => 'val1' } },
|
|
|
|
|
|
'block2 /' => { opt2 => 'val2' },
|
|
|
|
|
|
'block 3' => { '/' => { opt3 => 'val3' } },
|
|
|
|
|
|
block4 => { '/' => { opt4 => 'val4' } }
|
|
|
|
|
|
);
|
2009-10-10 16:38:28 +00:00
|
|
|
|
is_deeply(\%h25, \%expected_h25, "block and block name quoting");
|
2009-10-10 16:36:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 26
|
|
|
|
|
|
# Testing 0-value handling
|
|
|
|
|
|
my $conf26 = Config::General->new(
|
|
|
|
|
|
-String => <<TEST,
|
|
|
|
|
|
<foo 0>
|
|
|
|
|
|
0
|
|
|
|
|
|
</foo>
|
|
|
|
|
|
TEST
|
|
|
|
|
|
);
|
|
|
|
|
|
my %h26 = $conf26->getall;
|
|
|
|
|
|
my %expected_h26 = (
|
2.43
- fixed rt.cpan.org#40925, $indichar replaced by internal
configuration variable EOFseparator, which contains
a 256 bit SHA checksum of the date I fixed the bug.
This will prevent future conflicts hopefully. In addition
it makes it possible to make it customizable, if neccessary,
in a future release.
- fixed rt.cpan.org#42721, return undef for empty values
- fixed rt.cpan.org#42331, return undef for empty objects
- fixed rt.cpan.org#44600, comments after blockname
causes parser failure.
- fixed rt.cpan.org#42287, whitespace at beginning or end
of a quoted value gets lost after save().
- fixed rt.cpan.org#46184, variables that were not previously
defined are deleted when -InterPolateEnv is enabled.
- fixed bug in config loader for FileHandle objects, it
supports now any compatible object. Hint by Ingo Schmiegel.
- applied spelling- and speedup patches by Ville Skyttä.
- applied documentation patch by Jordan Macdonald.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@69 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:46:35 +00:00
|
|
|
|
foo => { 0 => { 0 => undef } },
|
2009-10-10 16:38:28 +00:00
|
|
|
|
);
|
|
|
|
|
|
is_deeply(\%h26, \%expected_h26, "testing 0-values in block names");
|
2009-10-10 16:31:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
#
|
|
|
|
|
|
# look if invalid input gets rejected right
|
|
|
|
|
|
#
|
1.36 - simplified new() parameter parsing, should be now a little
bit better to understand.
- added new parameter -DefaultConfig, which can hold a hashref
or a string, which will be used to pre-define values
of the resulting hash after parsing a config.
Thanks to Mark Hampton <mark.hampton@qualis.com> for the
suggestion.
- added new parameter -MergeDuplicateOptions, which allows
one to overwrite duplicate options, which is required,
if you turn on -DefaultConfig, because otherwise a
array would be created, which is probably not what you
wanted.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::keys(), which allows to
retrieve the keys of the object itself (which was not
directly possible before)
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::Extended::value(), which allows to
set a value to a (perlish-) nontrue value. This was a
bug.
- added patch by Danial Pearce <danial@infoxchange.net.au>
to Config::General::_parse_value, which fixes a bug in
this method, which in prior versions caused values of
"0" (zero digit) to be wiped out of the config.
- added tests in t/run.t for the new default config feature.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@25 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:19:00 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
### 27
|
|
|
|
|
|
# testing invalid parameter calls, expected to fail
|
|
|
|
|
|
my @pt = (
|
|
|
|
|
|
{
|
|
|
|
|
|
p => {-ConfigHash => "StringNotHash"},
|
|
|
|
|
|
t => "-ConfigHash HASH required"
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
p => {-String => {}},
|
|
|
|
|
|
t => "-String STRING required"
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
p => {-ConfigFile => {}},
|
|
|
|
|
|
t => "-ConfigFile STRING required"
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
p => {-ConfigFile => "NoFile"},
|
|
|
|
|
|
t => "-ConfigFile STRING File must exist and be readable"
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
foreach my $C (@pt) {
|
|
|
|
|
|
eval {
|
|
|
|
|
|
my $cfg = new Config::General(%{$C->{p}});
|
|
|
|
|
|
};
|
|
|
|
|
|
ok ($@, "check parameter failure handling $C->{t}");
|
2009-10-10 16:07:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 32
|
|
|
|
|
|
# check Flagbits
|
|
|
|
|
|
my $cfg28 = new Config::General(
|
|
|
|
|
|
-String => "Mode = CLEAR | UNSECURE",
|
|
|
|
|
|
-FlagBits => {
|
|
|
|
|
|
Mode => {
|
|
|
|
|
|
CLEAR => 1,
|
|
|
|
|
|
STRONG => 1,
|
|
|
|
|
|
UNSECURE => "32bit"
|
2009-10-10 16:07:21 +00:00
|
|
|
|
}
|
2009-10-10 16:38:28 +00:00
|
|
|
|
} );
|
|
|
|
|
|
my %cfg28 = $cfg28->getall();
|
|
|
|
|
|
is_deeply(\%cfg28,
|
|
|
|
|
|
{
|
|
|
|
|
|
'Mode' => {
|
|
|
|
|
|
'STRONG' => undef,
|
|
|
|
|
|
'UNSECURE' => '32bit',
|
|
|
|
|
|
'CLEAR' => 1
|
|
|
|
|
|
}}, "Checking -Flagbits resolving");
|
2009-10-10 16:26:19 +00:00
|
|
|
|
|
2009-10-10 16:38:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 33
|
|
|
|
|
|
# checking functional interface
|
|
|
|
|
|
eval {
|
|
|
|
|
|
my %conf = Config::General::ParseConfig(-ConfigFile => "t/test.rc");
|
|
|
|
|
|
Config::General::SaveConfig("t/test.rc.out", \%conf);
|
|
|
|
|
|
my %next = Config::General::ParseConfig(-ConfigFile => "t/test.rc.out");
|
|
|
|
|
|
my @a = sort keys %conf;
|
|
|
|
|
|
my @b = sort keys %next;
|
|
|
|
|
|
if (@a != @b) {
|
|
|
|
|
|
die "Re-parsed result differs from original";
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
ok(! $@, "Testing functional interface $@");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 34
|
|
|
|
|
|
# testing -AutoTrue
|
|
|
|
|
|
my $cfg34 = new Config::General(-AutoTrue => 1, -ConfigFile => "t/cfg.34");
|
|
|
|
|
|
my %cfg34 = $cfg34->getall();
|
|
|
|
|
|
my %expect34 = (
|
|
|
|
|
|
'a' => {
|
|
|
|
|
|
'var6' => 0,
|
|
|
|
|
|
'var3' => 1,
|
|
|
|
|
|
'var1' => 1,
|
|
|
|
|
|
'var4' => 0,
|
|
|
|
|
|
'var2' => 1,
|
|
|
|
|
|
'var5' => 0
|
|
|
|
|
|
},
|
|
|
|
|
|
'b' => {
|
|
|
|
|
|
'var6' => 0,
|
|
|
|
|
|
'var3' => 1,
|
|
|
|
|
|
'var1' => 1,
|
|
|
|
|
|
'var4' => 0,
|
|
|
|
|
|
'var2' => 1,
|
|
|
|
|
|
'var5' => 0
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
is_deeply(\%cfg34, \%expect34, "Using -AutoTrue");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 35
|
|
|
|
|
|
# testing -SplitPolicy
|
|
|
|
|
|
my %conf35 = Config::General::ParseConfig(
|
|
|
|
|
|
-String =>
|
|
|
|
|
|
qq(var1 :: alpha
|
|
|
|
|
|
var2 :: beta
|
|
|
|
|
|
var3 = gamma # use wrong delimiter by purpose),
|
|
|
|
|
|
-SplitPolicy => 'custom',
|
|
|
|
|
|
-SplitDelimiter => '\s*::\s*'
|
|
|
|
|
|
);
|
|
|
|
|
|
my %expect35 = (
|
2.43
- fixed rt.cpan.org#40925, $indichar replaced by internal
configuration variable EOFseparator, which contains
a 256 bit SHA checksum of the date I fixed the bug.
This will prevent future conflicts hopefully. In addition
it makes it possible to make it customizable, if neccessary,
in a future release.
- fixed rt.cpan.org#42721, return undef for empty values
- fixed rt.cpan.org#42331, return undef for empty objects
- fixed rt.cpan.org#44600, comments after blockname
causes parser failure.
- fixed rt.cpan.org#42287, whitespace at beginning or end
of a quoted value gets lost after save().
- fixed rt.cpan.org#46184, variables that were not previously
defined are deleted when -InterPolateEnv is enabled.
- fixed bug in config loader for FileHandle objects, it
supports now any compatible object. Hint by Ingo Schmiegel.
- applied spelling- and speedup patches by Ville Skyttä.
- applied documentation patch by Jordan Macdonald.
git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@69 be1acefe-a474-0410-9a34-9b3221f2030f
2009-10-10 16:46:35 +00:00
|
|
|
|
'var3 = gamma' => undef,
|
2009-10-10 16:38:28 +00:00
|
|
|
|
'var1' => 'alpha',
|
|
|
|
|
|
'var2' => 'beta'
|
|
|
|
|
|
);
|
|
|
|
|
|
is_deeply(\%conf35, \%expect35, "Using -SplitPolicy and custom -SplitDelimiter");
|
2009-10-10 16:40:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Include both
|
|
|
|
|
|
my $conf36 = Config::General->new( -ConfigFile => "t/dual-include.conf",
|
|
|
|
|
|
-IncludeAgain => 1 );
|
|
|
|
|
|
my %C36 = $conf36->getall;
|
|
|
|
|
|
is_deeply( \%C36, { bit => { one => { honk=>'bonk' },
|
|
|
|
|
|
two => { honk=>'bonk' }
|
|
|
|
|
|
} }, "Included twice" );
|
2009-10-10 16:42:58 +00:00
|
|
|
|
|
2009-10-10 16:40:22 +00:00
|
|
|
|
|
|
|
|
|
|
### Include once
|
|
|
|
|
|
diag "\nPlease ignore the following message about IncludeAgain";
|
|
|
|
|
|
my $conf37 = Config::General->new( "t/dual-include.conf" );
|
|
|
|
|
|
my %C37 = $conf37->getall;
|
|
|
|
|
|
is_deeply( \%C37, { bit => { one => { honk=>'bonk' },
|
|
|
|
|
|
two => {}
|
|
|
|
|
|
} }, "Included once-only" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### apache-style Include
|
|
|
|
|
|
my $conf38 = Config::General->new( -ConfigFile => "t/apache-include.conf",
|
|
|
|
|
|
-IncludeAgain => 1,
|
|
|
|
|
|
-UseApacheInclude => 1 );
|
|
|
|
|
|
my %C38 = $conf38->getall;
|
|
|
|
|
|
is_deeply( \%C38, { bit => { one => { honk=>'bonk' },
|
|
|
|
|
|
two => { honk=>'bonk' }
|
|
|
|
|
|
} }, "Apache-style include" );
|
2009-10-10 16:42:58 +00:00
|
|
|
|
|
|
|
|
|
|
#### 39 verifies bug rt#27225
|
|
|
|
|
|
# testing variable scope.
|
|
|
|
|
|
# a variable shall resolve to the value defined in the current
|
|
|
|
|
|
# scope, not a previous outer scope.
|
|
|
|
|
|
my $conf39 = new Config::General(-ConfigFile => "t/cfg.39", -InterPolateVars => 1, -StrictVars => 0);
|
|
|
|
|
|
my %conf39 = $conf39->getall();
|
|
|
|
|
|
isnt($conf39{outer}->{b1}->{inner}->{ivar},
|
|
|
|
|
|
$conf39{outer}->{b2}->{inner}->{ivar},
|
|
|
|
|
|
"Variable scope test");
|
|
|
|
|
|
|
|
|
|
|
|
### 40 - 42 verify if structural error checks are working
|
|
|
|
|
|
foreach my $pos (40 .. 43) {
|
|
|
|
|
|
eval {
|
|
|
|
|
|
my $conf = new Config::General(-ConfigFile => "t/cfg.$pos");
|
|
|
|
|
|
};
|
|
|
|
|
|
ok($@ =~ /^Config::General/, "$pos: Structural error checks");
|
|
|
|
|
|
}
|
2009-10-10 16:43:18 +00:00
|
|
|
|
|
|
|
|
|
|
my $conf44;
|
|
|
|
|
|
eval {
|
|
|
|
|
|
$conf44 = new Config::General(-String => [ 'foo bar' ]);
|
|
|
|
|
|
};
|
|
|
|
|
|
ok(! $@, "-String arrayref");
|
|
|
|
|
|
is_deeply({ $conf44->getall }, { foo => 'bar' }, "-String arrayref contents");
|
2009-10-10 16:43:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# verifies bug rt#35122
|
|
|
|
|
|
my $conf45 = new Config::General(-ConfigFile => "t/cfg.45", -InterPolateVars => 1, -StrictVars => 0);
|
|
|
|
|
|
my %conf45 = $conf45->getall();
|
|
|
|
|
|
my $expect45 = {
|
|
|
|
|
|
'block1' => {
|
|
|
|
|
|
'param5' => 'value3',
|
|
|
|
|
|
'param4' => 'value1',
|
|
|
|
|
|
'param2' => 'value3'
|
|
|
|
|
|
},
|
|
|
|
|
|
'block2' => {
|
|
|
|
|
|
'param7' => 'value2',
|
|
|
|
|
|
'param6' => 'value1'
|
|
|
|
|
|
},
|
|
|
|
|
|
'param2' => 'value2',
|
|
|
|
|
|
'param1' => 'value1'
|
|
|
|
|
|
};
|
|
|
|
|
|
is_deeply($expect45, \%conf45, "Variable precedence");
|
|
|
|
|
|
|
|
|
|
|
|
# verifies bug rt#35766
|
|
|
|
|
|
my $conf46 = new Config::General(-ConfigFile => "t/cfg.46", -InterPolateVars => 1, -StrictVars => 0);
|
|
|
|
|
|
my %conf46 = $conf46->getall();
|
|
|
|
|
|
my $expect46 = {
|
|
|
|
|
|
'blah' => 'blubber',
|
|
|
|
|
|
'test' => 'bar \'variable $blah should be kept\' and \'$foo too\'',
|
|
|
|
|
|
'foo' => 'bar'
|
|
|
|
|
|
};
|
|
|
|
|
|
is_deeply($expect46, \%conf46, "Variables inside single quotes");
|
2009-10-10 16:44:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
2010-04-08 15:47:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 16:44:49 +00:00
|
|
|
|
# complexity test
|
|
|
|
|
|
# check the combination of various features
|
|
|
|
|
|
my $conf47 = new Config::General(
|
|
|
|
|
|
-ConfigFile => "t/complex.cfg",
|
|
|
|
|
|
-InterPolateVars => 1,
|
|
|
|
|
|
-DefaultConfig => { this => "that", default => "imported" },
|
|
|
|
|
|
-MergeDuplicateBlocks => 1,
|
|
|
|
|
|
-MergeDuplicateOptions => 1,
|
|
|
|
|
|
-StrictVars => 1,
|
|
|
|
|
|
-SplitPolicy => 'custom',
|
|
|
|
|
|
-SplitDelimiter => '\s*=\s*',
|
|
|
|
|
|
-IncludeGlob => 1,
|
|
|
|
|
|
-IncludeAgain => 1,
|
|
|
|
|
|
-IncludeRelative => 1,
|
|
|
|
|
|
-AutoTrue => 1,
|
|
|
|
|
|
-FlagBits => { someflags => { LOCK => 1, RW => 2, TAINT => 3 } },
|
|
|
|
|
|
-StoreDelimiter => ' = ',
|
|
|
|
|
|
-SlashIsDirectory => 1,
|
|
|
|
|
|
-SaveSorted => 1
|
|
|
|
|
|
);
|
|
|
|
|
|
my %conf47 = $conf47->getall();
|
|
|
|
|
|
my $expect47 = {
|
|
|
|
|
|
'var3' => 'blah',
|
|
|
|
|
|
'z1' => {
|
|
|
|
|
|
'blak' => '11111',
|
|
|
|
|
|
'nando' => '9999'
|
|
|
|
|
|
},
|
|
|
|
|
|
'a' => {
|
|
|
|
|
|
'b' => {
|
|
|
|
|
|
'm' => {
|
|
|
|
|
|
'9323' => {
|
|
|
|
|
|
'g' => '000',
|
|
|
|
|
|
'long' => 'another long line'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'x' => '9323',
|
|
|
|
|
|
'z' => 'rewe'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'onflag' => 1,
|
|
|
|
|
|
'var2' => 'zeppelin',
|
2010-04-08 15:47:22 +00:00
|
|
|
|
'ignore' => '$set', # escaped $ should get to plain $, not \\$!
|
2009-10-10 16:44:49 +00:00
|
|
|
|
'quote' => 'this should be \'kept: $set\' and not be \'$set!\'',
|
|
|
|
|
|
'x5' => {
|
|
|
|
|
|
'klack' => '11111'
|
|
|
|
|
|
},
|
|
|
|
|
|
'set' => 'blah',
|
|
|
|
|
|
'line' => 'along line',
|
|
|
|
|
|
'this' => 'that',
|
|
|
|
|
|
'imported' => 'got that from imported config',
|
|
|
|
|
|
'someflags' => {
|
|
|
|
|
|
'RW' => 2,
|
|
|
|
|
|
'LOCK' => 1,
|
|
|
|
|
|
'TAINT' => 3
|
|
|
|
|
|
},
|
|
|
|
|
|
'var1' => 'zero',
|
|
|
|
|
|
'offflag' => 0,
|
|
|
|
|
|
'cmd' => 'mart@gw.intx.foo:22',
|
|
|
|
|
|
'default' => 'imported',
|
|
|
|
|
|
'host' => 'gw.intx.foo',
|
|
|
|
|
|
'nando' => '11111',
|
|
|
|
|
|
'auch <20>tzendes' => 'muss gehen',
|
|
|
|
|
|
'Directory' => {
|
|
|
|
|
|
'/' => {
|
|
|
|
|
|
'mode' => '755'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'hansa' => {
|
|
|
|
|
|
'z1' => {
|
|
|
|
|
|
'blak' => '11111',
|
|
|
|
|
|
'nando' => '9999'
|
|
|
|
|
|
},
|
|
|
|
|
|
'Directory' => {
|
|
|
|
|
|
'/' => {
|
|
|
|
|
|
'mode' => '755'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'block' => {
|
|
|
|
|
|
'0' => {
|
|
|
|
|
|
'value' => 0
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'x5' => {
|
|
|
|
|
|
'klack' => '11111'
|
|
|
|
|
|
},
|
|
|
|
|
|
'Files' => {
|
|
|
|
|
|
'~/*.pl' => {
|
|
|
|
|
|
'Options' => '+Indexes'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'nando' => '11111'
|
|
|
|
|
|
},
|
|
|
|
|
|
'block' => {
|
|
|
|
|
|
'0' => {
|
|
|
|
|
|
'value' => 0
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'Files' => {
|
|
|
|
|
|
'~/*.pl' => {
|
|
|
|
|
|
'Options' => '+Indexes'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
'a [[weird]] heredoc' => 'has to
|
|
|
|
|
|
work
|
|
|
|
|
|
too!'
|
|
|
|
|
|
};
|
2010-04-08 15:47:22 +00:00
|
|
|
|
#scip
|
2009-10-10 16:44:49 +00:00
|
|
|
|
is_deeply($expect47, \%conf47, "complexity test");
|
|
|
|
|
|
|
|
|
|
|
|
# check if sorted save works
|
|
|
|
|
|
$conf47->save_file("t/complex.out", \%conf47);
|
|
|
|
|
|
open T, "<t/complex.out";
|
|
|
|
|
|
my $got47 = join '', <T>;
|
|
|
|
|
|
close T;
|
|
|
|
|
|
my $sorted = qq(
|
|
|
|
|
|
imported = got that from imported config
|
|
|
|
|
|
line = along line
|
|
|
|
|
|
nando = 11111
|
|
|
|
|
|
offflag = 0
|
|
|
|
|
|
onflag = 1);
|
|
|
|
|
|
if ($got47 =~ /\Q$sorted\E/) {
|
|
|
|
|
|
pass("Testing sorted save");
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
fail("Testing sorted save");
|
|
|
|
|
|
}
|
2009-10-10 16:45:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tie my %hash48, "Tie::IxHash";
|
|
|
|
|
|
my $ostr48 =
|
|
|
|
|
|
"zeppelin 1
|
|
|
|
|
|
beach 2
|
|
|
|
|
|
anathem 3
|
|
|
|
|
|
mercury 4\n";
|
|
|
|
|
|
my $cfg48 = new Config::General(
|
|
|
|
|
|
-String => $ostr48,
|
|
|
|
|
|
-Tie => "Tie::IxHash"
|
|
|
|
|
|
);
|
|
|
|
|
|
%hash48 = $cfg48->getall();
|
|
|
|
|
|
my $str48 = $cfg48->save_string(\%hash48);
|
|
|
|
|
|
is( $str48, $ostr48, "tied hash test");
|
2009-10-19 19:45:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
2010-04-08 15:47:22 +00:00
|
|
|
|
|
|
|
|
|
|
# check for undef and -w
|
|
|
|
|
|
{
|
|
|
|
|
|
my $ostr49 = "foo\n";
|
|
|
|
|
|
local $^W = 1;
|
|
|
|
|
|
my $cfg49 = new Config::General( -String => $ostr49 );
|
|
|
|
|
|
my %hash49 = $cfg49->getall();
|
|
|
|
|
|
ok( exists $hash49{foo}, "value for undefined key found");
|
|
|
|
|
|
is( $hash49{foo}, undef, "value returned as expected - undef");
|
|
|
|
|
|
|
|
|
|
|
|
# repeat with interpolation turned on
|
|
|
|
|
|
$cfg49 = new Config::General( -String => $ostr49, -InterPolateVars => 1 );
|
|
|
|
|
|
%hash49 = $cfg49->getall();
|
|
|
|
|
|
ok( exists $hash49{foo}, "value for undefined key found");
|
|
|
|
|
|
is( $hash49{foo}, undef, "value returned as expected - undef");
|
|
|
|
|
|
$^W = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# verifies bug fix rt#54580
|
|
|
|
|
|
# Test handling of values containing *many* single-quoted strings
|
|
|
|
|
|
# when -InterPolateVars option is set
|
|
|
|
|
|
my $dupcount50 = 2000;
|
|
|
|
|
|
my $ostr50;
|
|
|
|
|
|
foreach my $counter ( reverse 1 .. $dupcount50 ) {
|
|
|
|
|
|
$ostr50 .= " 'luck${counter}'";
|
|
|
|
|
|
}
|
|
|
|
|
|
$ostr50 =~ s{\A }{};
|
|
|
|
|
|
my $cfgsrc50 = 'test_single_many ' . $ostr50;
|
|
|
|
|
|
$cfg50 = new Config::General( -String => $cfgsrc50, -InterPolateVars => 1 );
|
|
|
|
|
|
%hash50 = $cfg50->getall();
|
|
|
|
|
|
is($hash50{test_single_many}, $ostr50, "value with single-quote strings is as expected" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# check for escaped chars
|
|
|
|
|
|
my $cfg51 = new Config::General( -ConfigFile => "t/cfg.51" );
|
|
|
|
|
|
my %hash51 = $cfg51->getall();
|
|
|
|
|
|
is($hash51{dollar}, '$foo', "keep escaped dollar character");
|
|
|
|
|
|
is($hash51{backslash}, 'contains \ backslash', "keep escaped backslash character");
|
|
|
|
|
|
is($hash51{prize}, '18 $', "keep un-escaped dollar character");
|
|
|
|
|
|
is($hash51{hostparam}, q("'wsh.dir'"), "keep escaped quote character");
|
|
|
|
|
|
|
|
|
|
|
|
# now save it to a file and re-read it in and see if everything remains escaped
|
|
|
|
|
|
$cfg51->save_file("t/cfg.51.out");
|
|
|
|
|
|
$cfg51 = new Config::General( -ConfigFile => "t/cfg.51.out", -InterPolateVars => 1 );
|
|
|
|
|
|
my %hash51new = $cfg51->getall();
|
|
|
|
|
|
is_deeply(\%hash51, \%hash51new, "compare saved config containing escaped chars");
|
2010-04-09 08:56:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# check if forced single value arrays remain
|
|
|
|
|
|
my $cfg52 = new Config::General( -String => "habeas = [ corpus ]", -ForceArray => 1);
|
|
|
|
|
|
my %hash52 = $cfg52->getall();
|
|
|
|
|
|
my @array52 = qw(corpus);
|
|
|
|
|
|
is_deeply($hash52{habeas}, \@array52, "check -ForceArray single value arrays");
|
|
|
|
|
|
$cfg52->save_file("t/cfg.52.out");
|
|
|
|
|
|
$cfg52 = new Config::General( -ConfigFile => "t/cfg.52.out", -ForceArray => 1);
|
|
|
|
|
|
my %hash52new = $cfg52->getall();
|
|
|
|
|
|
is_deeply(\%hash52new, \%hash52, "check -ForceArray single value arrays during save()");
|