summaryrefslogtreecommitdiff
path: root/scripts/t/Dpkg_Substvars.t
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2015-03-18 22:42:23 +0100
committerGuillem Jover <guillem@debian.org>2015-05-18 02:02:56 +0200
commit9aa0a60a2491caeed59af5fd760c064b3be3cc00 (patch)
tree5568d7b2d045ebd84b1c81cf6330ba067300e8f3 /scripts/t/Dpkg_Substvars.t
parenta58dd78cb1667a26961f07ba80f0f2d676e41959 (diff)
downloaddpkg-9aa0a60a2491caeed59af5fd760c064b3be3cc00.tar.gz
Dpkg::Substvars: Add new filter() method
Diffstat (limited to 'scripts/t/Dpkg_Substvars.t')
-rw-r--r--scripts/t/Dpkg_Substvars.t36
1 files changed, 35 insertions, 1 deletions
diff --git a/scripts/t/Dpkg_Substvars.t b/scripts/t/Dpkg_Substvars.t
index c46c391ff..b8516943e 100644
--- a/scripts/t/Dpkg_Substvars.t
+++ b/scripts/t/Dpkg_Substvars.t
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 32;
+use Test::More tests => 35;
use Dpkg ();
use Dpkg::Arch qw(get_host_arch);
@@ -26,6 +26,8 @@ use_ok('Dpkg::Substvars');
my $srcdir = $ENV{srcdir} || '.';
my $datadir = $srcdir . '/t/Dpkg_Substvars';
+my $expected;
+
my $s = Dpkg::Substvars->new();
$s->load("$datadir/substvars1");
@@ -109,3 +111,35 @@ $SIG{__WARN__} = sub { $output .= $_[0] };
$s->warn_about_unused();
delete $SIG{__WARN__};
is($output, '', 'disabled unused variables warnings');
+
+# Variable filters
+my $sf;
+
+$expected = <<'VARS';
+name3=Yet another value
+name4=Name value
+otherprefix:var7=Quux
+var1=Some value
+var2=Some other value
+VARS
+$sf = Dpkg::Substvars->new("$datadir/substvars2");
+$sf->filter(remove => sub { $_[0] =~ m/^prefix:/ });
+is($sf->output(), $expected, 'Filter remove variables');
+
+$expected = <<'VARS';
+otherprefix:var7=Quux
+prefix:var5=Foo
+var1=Some value
+var2=Some other value
+VARS
+$sf = Dpkg::Substvars->new("$datadir/substvars2");
+$sf->filter(keep => sub { $_[0] =~ m/var/ });
+is($sf->output(), $expected, 'Filter keep variables');
+
+$expected = <<'VARS';
+prefix:name6=Bar
+VARS
+$sf = Dpkg::Substvars->new("$datadir/substvars2");
+$sf->filter(remove => sub { $_[0] =~ m/var/ },
+ keep => sub { $_[0] =~ m/^prefix:/ });
+is($sf->output(), $expected, 'Filter keep and remove variables');