[Bps-public-commit] Config-GitLike branch, master, updated. 1.16-5-gae3b8f2

Alex Vandiver alexmv at bestpractical.com
Sun Jul 16 21:19:52 EDT 2017


The branch, master has been updated
       via  ae3b8f2b1ffbd816c5119a85d8a528f37219b03b (commit)
       via  f66d085f18ba5d3a433856f8e4911037d99c2462 (commit)
       via  d9a89c13b78cb38411f0a00877bd73e2f8cce8ac (commit)
      from  9126aa6c2c94808e8f7686064bc84c85edee095a (commit)

Summary of changes:
 lib/Config/GitLike.pm          |  20 ++++-
 t/get_regexp_filter_multiple.t | 187 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 203 insertions(+), 4 deletions(-)
 create mode 100644 t/get_regexp_filter_multiple.t

- Log -----------------------------------------------------------------
commit d9a89c13b78cb38411f0a00877bd73e2f8cce8ac
Author: Edward Baudrez <ebaudrez at cpan.org>
Date:   Thu Oct 15 12:02:21 2015 +0200

    Add tests that expose get_regexp() problem in Version 1.16
    
    get_regexp() doesn't produce sensible results in Version 1.16 when
    filtering is used on keys with multiple values. These tests serve to
    expose the current (broken) behaviour.

diff --git a/t/get_regexp_filter_multiple.t b/t/get_regexp_filter_multiple.t
new file mode 100644
index 0000000..0e56599
--- /dev/null
+++ b/t/get_regexp_filter_multiple.t
@@ -0,0 +1,187 @@
+# tests that serve to expose a problem with the interaction of filtering and
+# multiple values in get_regexp() in Config::GitLike 1.16
+
+use strict;
+use warnings;
+
+use File::Copy;
+use Test::More tests => 30;
+use Test::Exception;
+use File::Spec;
+use File::Temp qw/tempdir/;
+use lib 't/lib';
+use TestConfig;
+
+# create an empty test directory in /tmp
+my $config_dirname = tempdir( CLEANUP => !$ENV{CONFIG_GITLIKE_DEBUG} );
+my $config_filename = File::Spec->catfile( $config_dirname, 'config' );
+
+diag "config file is: $config_filename" if $ENV{TEST_VERBOSE};
+
+my $config
+    = TestConfig->new( confname => 'config', tmpdir => $config_dirname );
+
+$config->burp(
+    '# foo
+[section]
+	b = off
+	b = on
+	exact = 0
+	inexact = 01
+	delicieux = true
+'
+);
+
+$config->load;
+
+# 'delicieux' has only 1 value
+is_deeply(
+    scalar $config->get_all( key => 'section.delicieux' ),
+    ['true'], 'get all values for key delicieux'
+);
+
+is_deeply(
+    scalar $config->get_all( key => 'section.delicieux', filter => 'true' ),
+    ['true'], 'get all values for key delicieux, filter by regexp'
+);
+
+is_deeply(
+    scalar $config->get_all( key => 'section.delicieux', filter => 'false' ),
+    [], 'get all values for key delicieux, filter by regexp "false"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.delicieux' ),
+    { 'section.delicieux' => 'true' }, 'get all values for key delicieux by regexp'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.delicieux', filter => 'true' ),
+    { 'section.delicieux' => 'true' }, 'get all values for key delicieux by regexp, filter by true'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.delicieux', filter => '!true' ),
+    {}, 'get all values for key delicieux by regexp, filter by !true'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.delicieux', filter => 'false' ),
+    {}, 'get all values for key delicieux by regexp, filter by false'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.delicieux', filter => '!false' ),
+    { 'section.delicieux' => 'true' }, 'get all values for key delicieux by regexp, filter by !false'
+);
+
+# 'b' has multiple values (2)
+is_deeply(
+    scalar $config->get_all( key => 'section.b' ),
+    ['off', 'on'], 'get all values for key b'
+);
+
+is_deeply(
+    scalar $config->get_all( key => 'section.b', filter => 'o' ),
+    ['off', 'on'], 'get all values for key b, filter by letter "o"'
+);
+
+is_deeply(
+    scalar $config->get_all( key => 'section.b', filter => 'n' ),
+    ['on'], 'get all values for key b, filter by letter "n"'
+);
+
+is_deeply(
+    scalar $config->get_all( key => 'section.b', filter => 'Q' ),
+    [], 'get all values for key b, filter by letter "Q"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b' ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '' ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by empty regex'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '.*' ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by catch-all regex'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '^.*$' ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by anchored catch-all regex'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => qr/(on|off)/ ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by regex on|off'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => qr/^(on|off)$/ ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by anchored regex on|off'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => 'o' ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by letter "o"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => 'n' ),
+    { 'section.b' => 'on' }, 'get all values for key b by regexp, filter by letter "n"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => 'Q' ),
+    {}, 'get all values for key b by regexp, filter by letter "Q"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => 'ARRAY' ),
+    {}, 'get all values for key b by regexp, filter by word "ARRAY"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!' ),
+    {}, 'get all values for key b by regexp, filter by negated regex'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!.*' ),
+    {}, 'get all values for key b by regexp, filter by negated catch-all regex'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!(on|off)' ),
+    {}, 'get all values for key b by regexp, filter by "!(on|off)"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!on|off' ),
+    {}, 'get all values for key b by regexp, filter by "!on|off"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!good|bad' ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by negated regex good|bad'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!o' ),
+    {}, 'get all values for key b by regexp, filter by "!o"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!n' ),
+    { 'section.b' => 'off' }, 'get all values for key b by regexp, filter by "!n"'
+);
+
+is_deeply(
+    scalar $config->get_regexp( key => 'section\.b', filter => '!ARRAY' ),
+    { 'section.b' => ['off', 'on'] }, 'get all values for key b by regexp, filter by "!ARRAY"'
+);

commit f66d085f18ba5d3a433856f8e4911037d99c2462
Author: Edward Baudrez <ebaudrez at cpan.org>
Date:   Thu Oct 15 12:05:10 2015 +0200

    Patch get_regexp() to filter multiple values correctly

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 81e99de..bededbe 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -675,14 +675,26 @@ sub get_regexp {
         }
         elsif ($args{filter} =~ s/^!//) {
             for (keys %results) {
-                delete $results{$_} if defined $results{$_}
-                    and $results{$_} =~ m/$args{filter}/i;
+                my @values = ref $results{$_} ? @{$results{$_}} : $results{$_};
+                @values = grep { not defined or not m/$args{filter}/i } @values;
+                if (!@values) {
+                    delete $results{$_};
+                }
+                else {
+                    $results{$_} = @values > 1 ? \@values : $values[0];
+                }
             }
         }
         else {
             for (keys %results) {
-                delete $results{$_} if not defined $results{$_}
-                    or $results{$_} !~ m/$args{filter}/i;
+                my @values = ref $results{$_} ? @{$results{$_}} : $results{$_};
+                @values = grep { defined and m/$args{filter}/i } @values;
+                if (!@values) {
+                    delete $results{$_};
+                }
+                else {
+                    $results{$_} = @values > 1 ? \@values : $values[0];
+                }
             }
         }
     }

commit ae3b8f2b1ffbd816c5119a85d8a528f37219b03b
Merge: 9126aa6 f66d085
Author: Alex Vandiver <alex at chmrr.net>
Date:   Sun Jul 16 18:19:43 2017 -0700

    Merge remote-tracking branch 'prs/12'


-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list