[libconfig-model-tester-perl] 01/03: Imported Upstream version 2.051
dod at debian.org
dod at debian.org
Fri May 29 19:43:41 UTC 2015
This is an automated email from the git hooks/post-receive script.
dod pushed a commit to branch master
in repository libconfig-model-tester-perl.
commit 71974a8b2d00340eb4afe9f3391426cc17418125
Author: Dominique Dumont <dod at debian.org>
Date: Fri May 29 21:39:59 2015 +0200
Imported Upstream version 2.051
---
Build.PL | 2 +-
Changes | 6 ++++
LICENSE | 2 +-
META.json | 4 +--
META.yml | 4 +--
lib/Config/Model/Tester.pm | 76 +++++++++++++++++++++++++++++++++++++++++++---
6 files changed, 84 insertions(+), 10 deletions(-)
diff --git a/Build.PL b/Build.PL
index 6a8039c..7c493dd 100644
--- a/Build.PL
+++ b/Build.PL
@@ -18,7 +18,7 @@ my %module_build_args = (
"Dominique Dumont"
],
"dist_name" => "Config-Model-Tester",
- "dist_version" => "2.050",
+ "dist_version" => "2.051",
"license" => "lgpl",
"module_name" => "Config::Model::Tester",
"recommends" => {},
diff --git a/Changes b/Changes
index 3d1a60a..036830e 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,9 @@
+2.051 2015-05-20
+
+ * New features:
+ + Added has_key and has_not_key parameters to check hash
+ element content
+
2.050 2015-03-29
* Bug fix:
diff --git a/LICENSE b/LICENSE
index 214c2b0..dc26452 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-This software is Copyright (c) 2014 by Dominique Dumont.
+This software is Copyright (c) 2015 by Dominique Dumont.
This is free software, licensed under:
diff --git a/META.json b/META.json
index 5dae0e1..ae02472 100644
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
"Dominique Dumont"
],
"dynamic_config" : 0,
- "generated_by" : "Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.142690",
+ "generated_by" : "Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.150001",
"license" : [
"lgpl_2_1"
],
@@ -52,6 +52,6 @@
"web" : "http://github.com/dod38fr/config-model-tester.git"
}
},
- "version" : "2.050"
+ "version" : "2.051"
}
diff --git a/META.yml b/META.yml
index 606ffd9..ce4f17b 100644
--- a/META.yml
+++ b/META.yml
@@ -7,7 +7,7 @@ build_requires:
configure_requires:
Module::Build: '0.34'
dynamic_config: 0
-generated_by: 'Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.142690'
+generated_by: 'Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.150001'
license: lgpl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -28,4 +28,4 @@ resources:
bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-Model-Tester
homepage: https://github.com/dod38fr/config-model/wiki
repository: git://github.com/dod38fr/config-model-tester.git
-version: '2.050'
+version: '2.051'
diff --git a/lib/Config/Model/Tester.pm b/lib/Config/Model/Tester.pm
index 5c208da..fc21411 100644
--- a/lib/Config/Model/Tester.pm
+++ b/lib/Config/Model/Tester.pm
@@ -1,7 +1,7 @@
#
# This file is part of Config-Model-Tester
#
-# This software is Copyright (c) 2014 by Dominique Dumont.
+# This software is Copyright (c) 2015 by Dominique Dumont.
#
# This is free software, licensed under:
#
@@ -9,7 +9,7 @@
#
package Config::Model::Tester;
# ABSTRACT: Test framework for Config::Model
-$Config::Model::Tester::VERSION = '2.050';
+$Config::Model::Tester::VERSION = '2.051';
use warnings;
use strict;
use locale;
@@ -257,6 +257,52 @@ sub check_annotation {
}
}
+sub has_key {
+ my ($root, $c, $nw) = @_;
+
+ _test_key($root, $c, $nw, 0);
+}
+
+sub has_not_key {
+ my ($root, $c, $nw) = @_;
+
+ _test_key($root, $c, $nw, 1);
+}
+
+sub _test_key {
+ my ($root, $c, $nw, $invert) = @_;
+
+ my @checks = ref $c eq 'ARRAY' ? @$c
+ : map { ( $_ => $c->{$_})} sort keys %$c ;
+
+ while (@checks) {
+ my $path = shift @checks;
+ my $spec = shift @checks;
+ my @key_checks = ref $spec eq 'ARRAY' ? @$spec: ($spec);
+
+ my $obj = $root->grab( step => $path, type => 'hash' );
+ my @keys = $obj->fetch_all_indexes;
+ my $res = 0;
+ foreach my $check (@key_checks) {
+ my @match ;
+ foreach my $k (@keys) {
+ if (ref $check eq 'Regexp') {
+ push @match, $k if $k =~ $check;
+ }
+ else {
+ push @match, $k if $k eq $check;
+ }
+ }
+ if ($invert) {
+ is(scalar @match,0, "check $check matched no key" );
+ }
+ else {
+ ok(scalar @match, "check $check matched with keys @match" );
+ }
+ }
+ }
+}
+
sub write_data_back {
my ($model_test, $inst, $t) = @_;
local $Config::Model::Value::nowarning = $t->{no_warnings} || 0;
@@ -401,6 +447,9 @@ sub run_model_test {
check_data("first", $root, $t->{check}, $t->{no_warnings}) if $t->{check};
+ has_key ( $root, $t->{has_key}, $t->{no_warnings}) if $t->{has_key} ;
+ has_not_key ( $root, $t->{has_not_key}, $t->{no_warnings}) if $t->{has_not_key} ;
+
check_annotation($root,$t) if $t->{verify_annotation};
write_data_back ($model_test, $inst, $t) ;
@@ -490,7 +539,7 @@ Config::Model::Tester - Test framework for Config::Model
=head1 VERSION
-version 2.050
+version 2.051
=head1 SYNOPSIS
@@ -765,6 +814,25 @@ A regexp can also be used to check value:
=item *
+Verify if a hash contains one or more keys (or keys matching a regexp):
+
+ has_key => [
+ 'sections' => 'debian', # sections must point to a hash element
+ 'control' => [qw/source binary/],
+ 'copyright Files' => qr/.c$/,
+ 'copyright Files' => [qr/\.h$/], qr/\.c$/],
+ ],
+
+=item *
+
+Verify that a hash has B<not> a key (or a key matching a regexp):
+
+ has_not_key => [
+ 'copyright Files' => qr/.virus$/ # silly, isn't ?
+ ],
+
+=item *
+
Verify annotation extracted from the configuration file comments:
verify_annotation => {
@@ -938,7 +1006,7 @@ Dominique Dumont
=head1 COPYRIGHT AND LICENSE
-This software is Copyright (c) 2014 by Dominique Dumont.
+This software is Copyright (c) 2015 by Dominique Dumont.
This is free software, licensed under:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libconfig-model-tester-perl.git
More information about the Pkg-perl-cvs-commits
mailing list