- fixed bug in save(), now blocks containing whitespaces
	   will be saved using quotes, in addition the parser observes
	   the quoting feature, added portion about this to the pod
	   doc. pointed out by Jeff Murphy <jcmurphy@jeffmurphy.org>.

	 - added internal list of files opened so far to avoid
	   reading in the same file multiple times.
	   Suggested by Michael Graham.

	 - added new method files() which returns the above list.

	 - added workaround for foolish perl installation on
	   debian systems (croak() doesn't work anymore as of
	   5.8.4, it's a shame!)

	 - applied patch by Michael Graham which fixes IncludeRelative
	   feature, now an included file is being included relative
	   to the calling config file, not the first one.

	 - added 'make test' targets for files() and include
	   stuff. (by Michael too)


git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@54 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
Thomas von Dein
2009-10-10 16:31:34 +00:00
parent 46b032f1b6
commit c0eafd9b8f
12 changed files with 235 additions and 18 deletions

2
t/cfg.20.b Normal file
View File

@@ -0,0 +1,2 @@
seen_cfg.20.b = true
<<include t/cfg.20.c>>

2
t/cfg.20.c Normal file
View File

@@ -0,0 +1,2 @@
seen_cfg.20.c = true
last = cfg.20.c

83
t/run.t
View File

@@ -6,7 +6,7 @@
#
# Under normal circumstances every test should succeed.
BEGIN { $| = 1; print "1..19\n";}
BEGIN { $| = 1; print "1..22\n";}
use lib "blib/lib";
use Config::General;
use Data::Dumper;
@@ -194,6 +194,87 @@ else {
pause;
# testing files() method
my $conf20 = Config::General->new(
-file => "t/cfg.20.a",
-MergeDuplicateOptions => 1
);
my %h20 = $conf20->getall();
my %expected_h20 = (
'seen_cfg.20.a' => 'true',
'seen_cfg.20.b' => 'true',
'seen_cfg.20.c' => 'true',
'last' => 'cfg.20.c',
);
my %files = map { $_ => 1 } $conf20->files();
my %expected_files = map { $_ => 1 } (
't/cfg.20.a',
't/cfg.20.b',
't/cfg.20.c',
);
if (&comp(\%h20, \%expected_h20) and &comp(\%files, \%expected_files)) {
print "ok\n";
print STDERR " .. ok # testing files() method\n";
}
else {
print "20 not ok\n";
print STDERR "20 not ok\n";
}
pause;
# 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,
);
};
if ($@) {
print "ok\n";
print STDERR " .. ok # prevented from loading relative cfgs without -IncludeRelative\n";
}
else {
print "21 not ok\n";
print STDERR "21 not ok\n";
}
pause;
# 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 = (
'sub3_seen' => 'yup',
'sub2_seen' => 'yup',
'sub1_seen' => 'yup',
'fruit' => 'mango',
);
if (&comp(\%h22, \%expected_h22)) {
print "ok\n";
print STDERR " .. ok # loaded relative to included files\n";
}
else {
print "22 not ok\n";
print STDERR "22 not ok\n";
}
pause;
# all subs here

3
t/sub1/cfg.sub1 Normal file
View File

@@ -0,0 +1,3 @@
fruit = mango
sub3_seen = yup

4
t/sub1/sub2/cfg.sub2 Normal file
View File

@@ -0,0 +1,4 @@
fruit = pear
sub2_seen = yup
<<include ../cfg.sub1>>

View File

@@ -0,0 +1,5 @@
fruit = apple
sub3_seen = yup
<<include ../cfg.sub2>>