diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-03 13:06:21 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-03 13:16:07 +0200 |
commit | 8fbdd4a7c56de2752c866ce3283d3bdbca3ed8bb (patch) | |
tree | 70e40d98777ce5a748dd48b07c1ab8ab460506b1 /t | |
parent | c437dd558ef7d4e2f3b511d998d100d395c5ba26 (diff) | |
download | beam-8fbdd4a7c56de2752c866ce3283d3bdbca3ed8bb.tar.gz beam-8fbdd4a7c56de2752c866ce3283d3bdbca3ed8bb.tar.bz2 |
Implement lint() method
* lib/App/Beam/Config.pm: Keep count of errors in the error_count member.
(getref): Take into account the {ci} setting.
(flatten): Minor fix.
(lint): New method.
* t/TestConfig.pm (lint): Overload method.
* t/conf06.t: New test case.
Diffstat (limited to 't')
-rw-r--r-- | t/TestConfig.pm | 15 | ||||
-rw-r--r-- | t/conf06.t | 48 |
2 files changed, 63 insertions, 0 deletions
diff --git a/t/TestConfig.pm b/t/TestConfig.pm index 63b9d06..7f8f232 100644 --- a/t/TestConfig.pm +++ b/t/TestConfig.pm @@ -88,3 +88,18 @@ sub errors { return undef if $self->success; return @{$self->{errors}}; } + +sub lint { + my $self = shift; + my $synt = shift; + local %_ = @_; + my $exp = $self->{expected_errors} = delete $_{expect}; + carp "unknown parameters: " . join(', ', keys(%_)) if (keys(%_)); + + $self->SUPER::lint($synt); + + if ($exp && @{$self->{expected_errors}}) { + $self->{status} = 0; + $self->error("not all expected errors reported"); + } +} diff --git a/t/conf06.t b/t/conf06.t new file mode 100644 index 0000000..219a5e4 --- /dev/null +++ b/t/conf06.t @@ -0,0 +1,48 @@ +# -*- 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, + } + }, + '*' => 1 +); + +my $cfg = new TestConfig(locations => 1, parameters => \%keywords); +ok($cfg->canonical, 'backend.file.level=3 backend.file.local=1 core.retain-interval=10 core.tempdir="/tmp"'); + +my %subkw = ( + backend => { + section => { + file => { + section => { + name => { mandatory => 1 }, + local => 1 + } + } + } + } +); + +ok(!$cfg->lint(\%subkw, + expect => [ 'keyword "level" is unknown', + 'mandatory variable "backend.file.name" not set' ])); + +__DATA__ +# This is a sample configuration file +[core] + retain-interval = 10 + tempdir = /tmp +[backend file] + local = 1 + level = 3 |