aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/TestConfig.pm28
-rw-r--r--t/conf01l.t20
-rw-r--r--t/conf02l.t45
-rw-r--r--t/conf03l.t32
-rw-r--r--t/conf04l.t40
-rw-r--r--t/conf05l.t30
-rw-r--r--t/locus.t34
7 files changed, 209 insertions, 20 deletions
diff --git a/t/TestConfig.pm b/t/TestConfig.pm
index ef5ce1d..daafe56 100644
--- a/t/TestConfig.pm
+++ b/t/TestConfig.pm
@@ -69,26 +69,14 @@ sub expected_error {
}
sub error {
- my ($self, $err) = @_;
- if ($err =~ /^(.+?):(.+?): (.+)/) {
- unless (exists($self->{first_line})) {
- if (open(my $fd, '<', $0)) {
- $self->{first_line} = 0;
- while (<$fd>) {
- $self->{first_line}++;
- chomp;
- last if /^__DATA__$/;
- }
- close $fd;
- }
- }
- my $line = $2 + $self->{first_line};
- push @{$self->{errors}}, { file => $0,
- orig => $1,
- line => $line,
- message => $3 };
- print STDERR "$0:$line: $3\n"
- unless $self->expected_error($3);
+ my $self = shift;
+ my $err = shift;
+ local %_ = @_;
+
+ if (exists($_{locus})) {
+ push @{$self->{errors}}, { message => $err };
+ print STDERR $_{locus}->format($err)."\n"
+ unless $self->expected_error($err);
} else {
push @{$self->{errors}}, { message => $err };
print STDERR "$err\n"
diff --git a/t/conf01l.t b/t/conf01l.t
new file mode 100644
index 0000000..0436df0
--- /dev/null
+++ b/t/conf01l.t
@@ -0,0 +1,20 @@
+# -*- perl -*-
+use lib 't';
+use strict;
+use Test;
+use TestConfig;
+
+plan(tests => 1);
+
+my $cfg = new TestConfig(locations => 1);
+ok($cfg->canonical, 'backend.foo.file="a" core.retain-interval=10 core.tempdir="/tmp"');
+
+__DATA__
+# This is a sample configuration file
+[core]
+ retain-interval = 10
+ tempdir = /tmp
+[backend foo]
+ file = a
+
+
diff --git a/t/conf02l.t b/t/conf02l.t
new file mode 100644
index 0000000..c57b0ae
--- /dev/null
+++ b/t/conf02l.t
@@ -0,0 +1,45 @@
+# -*- perl -*-
+use lib 't';
+use strict;
+use Test;
+use TestConfig;
+
+plan(tests => 7);
+
+my %keywords = (
+ core => {
+ section => {
+ 'retain-interval' => { mandatory => 1 },
+ 'tempdir' => 1,
+ 'verbose' => 1,
+ }
+ },
+ backend => {
+ section => {
+ file => 1
+ }
+ }
+);
+
+my $cfg = new TestConfig(parameters => \%keywords, locations => 1);
+ok($cfg->isset('backend','foo','file'));
+ok($cfg->isscalar('backend','foo','file'));
+ok($cfg->get('backend','foo','file'), 'foo');
+
+ok($cfg->isset('core', 'verbose') == 0);
+
+ok($cfg->issection('backend','foo'));
+
+$cfg->set('core','verbose','On');
+ok($cfg->get('core','verbose'),'On');
+
+$cfg->unset('core','tmpdir');
+ok($cfg->isset('core','tmpdir') == 0);
+
+__DATA__
+# This is a sample configuration file
+[core]
+ retain-interval = 10
+ tempdir = /tmp
+[backend foo]
+ file = foo
diff --git a/t/conf03l.t b/t/conf03l.t
new file mode 100644
index 0000000..ff14596
--- /dev/null
+++ b/t/conf03l.t
@@ -0,0 +1,32 @@
+# -*- perl -*-
+
+use lib 't';
+use strict;
+use Test;
+use TestConfig;
+
+plan(tests => 1);
+
+my %keywords = (
+ core => {
+ section => {
+ 'tempdir' => 1,
+ 'verbose' => 1,
+ }
+ },
+ backend => {
+ section => {
+ file => 1
+ }
+ }
+);
+my $cfg = new TestConfig(parameters => \%keywords,
+ locations => 1,
+ expect => [ 'keyword "output" is unknown' ]);
+ok($cfg->errors() == 1);
+__DATA__
+# This is a sample configuration file
+[core]
+ tempdir = /tmp
+ output = file
+
diff --git a/t/conf04l.t b/t/conf04l.t
new file mode 100644
index 0000000..1ea5477
--- /dev/null
+++ b/t/conf04l.t
@@ -0,0 +1,40 @@
+# -*- perl -*-
+use lib 't';
+use strict;
+use Test;
+use TestConfig;
+
+plan(tests => 1);
+
+my %keywords = (
+ core => {
+ section => {
+ 'retain-interval' => { mandatory => 1 },
+ 'tempdir' => 1,
+ 'verbose' => 1,
+ }
+ },
+ backend => {
+ section => {
+ file => {
+ section => {
+ name => { mandatory => 1 },
+ local => 1
+ }
+ }
+ }
+ }
+);
+
+my $cfg = new TestConfig(parameters => \%keywords,
+ locations => 1,
+ expect => [ 'mandatory variable "core.retain-interval" not set',
+ 'mandatory variable "backend.file.name" not set' ]);
+ok($cfg->errors()==2);
+
+__DATA__
+# This is a sample configuration file
+[core]
+ tempdir = /tmp
+[backend file]
+ local = 1
diff --git a/t/conf05l.t b/t/conf05l.t
new file mode 100644
index 0000000..11f9cb1
--- /dev/null
+++ b/t/conf05l.t
@@ -0,0 +1,30 @@
+# -*- perl -*-
+use lib 't';
+use strict;
+use Test;
+use TestConfig;
+
+plan(tests => 1);
+
+my %keywords = (
+ core => {
+ section => {
+ list => {
+ array => 1
+ },
+ pidfile => 1
+ }
+ }
+);
+
+my $cfg = new TestConfig(parameters => \%keywords, locations => 1);
+ok($cfg->canonical(),'core.list=["en","to",5] core.pidfile="file2"');
+
+__END__
+[core]
+ list = en
+ list = to
+ list = 5
+
+ pidfile = file1
+ pidfile = file2
diff --git a/t/locus.t b/t/locus.t
new file mode 100644
index 0000000..a08280b
--- /dev/null
+++ b/t/locus.t
@@ -0,0 +1,34 @@
+# -*- perl -*-
+use strict;
+use Test;
+use App::Beam::Config::Locus;
+
+plan(tests => 7);
+
+my $loc = new App::Beam::Config::Locus;
+$loc->add('foo', 10);
+ok($loc->format, "foo:10");
+
+$loc->add('foo', 11);
+$loc->add('foo', 12);
+$loc->add('foo', 13);
+ok($loc->format, "foo:10-13");
+
+$loc->add('foo', 24);
+$loc->add('foo', 28);
+ok($loc->format, "foo:10-13,24,28");
+
+$loc->add('bar', 1);
+$loc->add('baz', 8);
+$loc->add('baz', 9);
+$loc->add('bar', 5);
+ok($loc->format, "foo:10-13,24,28;bar:1,5;baz:8-9");
+
+$loc->fixup_names('foo' => 'Foo', 'bar' => 'BAR');
+ok($loc->format, "Foo:10-13,24,28;BAR:1,5;baz:8-9");
+
+$loc->fixup_lines('Foo' => -1, 'baz' => 2);
+ok($loc->format, "Foo:9-12,23,27;BAR:1,5;baz:10-11");
+
+$loc->fixup_lines(3);
+ok($loc->format, "Foo:12-15,26,30;BAR:4,8;baz:13-14");

Return to:

Send suggestions and report system problems to the System administrator.