aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-03-04 18:05:51 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2017-03-04 18:05:51 +0200
commit9dbc51556ad400f03495b3b85b0b5995362cd35c (patch)
tree20416ffc86e3a3c5d0614a37cebe629bc30479cc /t
parentbf855bb78bb759d1f733cdb21032e5fbfa403572 (diff)
downloadbeam-9dbc51556ad400f03495b3b85b0b5995362cd35c.tar.gz
beam-9dbc51556ad400f03495b3b85b0b5995362cd35c.tar.bz2
Improve config syntax verification.
Fix processing of the '*' entry in the syntax hashes. The entry '*' => '*' in the syntax hash declares that any settings and any subsections are also allowed.
Diffstat (limited to 't')
-rw-r--r--t/TestConfig.pm3
-rw-r--r--t/conf02.t6
-rw-r--r--t/conf06.t2
-rw-r--r--t/conf07.t57
4 files changed, 65 insertions, 3 deletions
diff --git a/t/TestConfig.pm b/t/TestConfig.pm
index 7f8f232..f1577a5 100644
--- a/t/TestConfig.pm
+++ b/t/TestConfig.pm
@@ -96,10 +96,11 @@ sub lint {
my $exp = $self->{expected_errors} = delete $_{expect};
carp "unknown parameters: " . join(', ', keys(%_)) if (keys(%_));
- $self->SUPER::lint($synt);
+ my $ret = $self->SUPER::lint($synt);
if ($exp && @{$self->{expected_errors}}) {
$self->{status} = 0;
$self->error("not all expected errors reported");
}
+ return $ret;
}
diff --git a/t/conf02.t b/t/conf02.t
index 55e7b86..b6a45d6 100644
--- a/t/conf02.t
+++ b/t/conf02.t
@@ -16,7 +16,11 @@ my %keywords = (
},
backend => {
section => {
- file => 1
+ '*' => {
+ section => {
+ file => 1
+ }
+ }
}
}
);
diff --git a/t/conf06.t b/t/conf06.t
index af40c24..5e5176f 100644
--- a/t/conf06.t
+++ b/t/conf06.t
@@ -15,7 +15,7 @@ my %keywords = (
'verbose' => 1,
}
},
- '*' => 1
+ '*' => '*'
);
my $cfg = new TestConfig(parameters => \%keywords);
diff --git a/t/conf07.t b/t/conf07.t
new file mode 100644
index 0000000..20b2ecf
--- /dev/null
+++ b/t/conf07.t
@@ -0,0 +1,57 @@
+# -*- perl -*-
+use lib 't';
+use strict;
+use Test;
+use TestConfig;
+use Data::Dumper;
+
+plan(tests => 2);
+
+my %keywords = (
+ core => {
+ section => {
+ 'retain-interval' => { mandatory => 1 },
+ 'tempdir' => 1,
+ 'verbose' => 1,
+ }
+ },
+ '*' => '*'
+);
+
+my $cfg = new TestConfig(parameters => \%keywords);
+ok($cfg->canonical, 'core.retain-interval=10 item.bar.backend="mysql" item.bar.database="quux" item.foo.backend="tar" item.foo.directory="baz"');
+
+my %subkw = (
+ item => {
+ section => {
+ '*' => {
+ select => sub {
+ my ($vref) = @_;
+ return 0 unless ref($vref) eq 'HASH';
+ return $vref->{backend}->{-value} eq 'tar';
+ },
+ section => {
+ backend => 1,
+ directory => {
+ mandatory => 1,
+ }
+ }
+ }
+ }
+ }
+);
+
+ok($cfg->lint(\%subkw));
+
+__DATA__
+# This is a sample configuration file
+[core]
+ retain-interval = 10
+[item foo]
+ backend = tar
+ directory = baz
+[item bar]
+ backend = mysql
+ database = quux
+
+

Return to:

Send suggestions and report system problems to the System administrator.