|
@@ -16,7 +16,7 @@
|
|
|
use strict;
|
|
|
use warnings;
|
|
|
|
|
|
-use Test::More tests => 14;
|
|
|
+use Test::More tests => 9;
|
|
|
|
|
|
BEGIN {
|
|
|
use_ok('Dpkg::Conf');
|
|
@@ -28,17 +28,21 @@ my $datadir = $srcdir . '/t/Dpkg_Conf';
|
|
|
my ($conf, $count, @opts);
|
|
|
|
|
|
my @expected_long_opts = (
|
|
|
-'--l=v',
|
|
|
-'--option-dash=value-dash',
|
|
|
'--option-double-quotes=value double quotes',
|
|
|
-'--option-equal=value-equal=subvalue-equal',
|
|
|
-'--option-indent=value-indent',
|
|
|
-'--option-name=value-name',
|
|
|
-'--option-noequal=value-noequal',
|
|
|
-'--option-simple',
|
|
|
'--option-single-quotes=value single quotes',
|
|
|
'--option-space=value words space',
|
|
|
-);
|
|
|
+qw(
|
|
|
+--option-dupe=value1
|
|
|
+--option-name=value-name
|
|
|
+--option-indent=value-indent
|
|
|
+--option-equal=value-equal=subvalue-equal
|
|
|
+--option-noequal=value-noequal
|
|
|
+--option-dupe=value2
|
|
|
+--option-simple
|
|
|
+--option-dash=value-dash
|
|
|
+--option-dupe=value3
|
|
|
+--l=v
|
|
|
+));
|
|
|
my @expected_short_opts = qw(
|
|
|
-o=vd
|
|
|
-s
|
|
@@ -48,55 +52,50 @@ $conf = Dpkg::Conf->new();
|
|
|
local $SIG{__WARN__} = sub { };
|
|
|
$count = $conf->load("$datadir/config-mixed");
|
|
|
delete $SIG{__WARN__};
|
|
|
-is($count, 10, 'Load a config file, only long options');
|
|
|
+is($count, 13, 'Load a config file, only long options');
|
|
|
|
|
|
@opts = $conf->get_options();
|
|
|
is_deeply(\@opts, \@expected_long_opts, 'Parse long options');
|
|
|
|
|
|
$conf = Dpkg::Conf->new(allow_short => 1);
|
|
|
$count = $conf->load("$datadir/config-mixed");
|
|
|
-is($count, 12, 'Load a config file, mixed options');
|
|
|
+is($count, 15, 'Load a config file, mixed options');
|
|
|
|
|
|
@opts = $conf->get_options();
|
|
|
-my @expected_mixed_opts = ( @expected_short_opts, @expected_long_opts );
|
|
|
+my @expected_mixed_opts = ( @expected_long_opts, @expected_short_opts );
|
|
|
is_deeply(\@opts, \@expected_mixed_opts, 'Parse mixed options');
|
|
|
|
|
|
my $expected_mixed_output = <<'MIXED';
|
|
|
--o = "vd"
|
|
|
--s
|
|
|
-l = "v"
|
|
|
-option-dash = "value-dash"
|
|
|
option-double-quotes = "value double quotes"
|
|
|
-option-equal = "value-equal=subvalue-equal"
|
|
|
-option-indent = "value-indent"
|
|
|
+option-single-quotes = "value single quotes"
|
|
|
+option-space = "value words space"
|
|
|
+option-dupe = "value1"
|
|
|
option-name = "value-name"
|
|
|
+option-indent = "value-indent"
|
|
|
+option-equal = "value-equal=subvalue-equal"
|
|
|
option-noequal = "value-noequal"
|
|
|
+option-dupe = "value2"
|
|
|
option-simple
|
|
|
-option-single-quotes = "value single quotes"
|
|
|
-option-space = "value words space"
|
|
|
+option-dash = "value-dash"
|
|
|
+option-dupe = "value3"
|
|
|
+l = "v"
|
|
|
+-o = "vd"
|
|
|
+-s
|
|
|
MIXED
|
|
|
|
|
|
is($conf->output, $expected_mixed_output, 'Output mixed options');
|
|
|
|
|
|
-is($conf->get('-o'), 'vd', 'Get option -o');
|
|
|
-is($conf->get('option-dash'), 'value-dash', 'Get option-dash');
|
|
|
-is($conf->get('option-space'), 'value words space', 'Get option-space');
|
|
|
-
|
|
|
-is($conf->get('manual-option'), undef, 'Get non-existent option');
|
|
|
-$conf->set('manual-option', 'manual value');
|
|
|
-is($conf->get('manual-option'), 'manual value', 'Get manual option');
|
|
|
-
|
|
|
my $expected_filter;
|
|
|
|
|
|
$expected_filter = <<'FILTER';
|
|
|
+l = "v"
|
|
|
-o = "vd"
|
|
|
-s
|
|
|
-l = "v"
|
|
|
FILTER
|
|
|
|
|
|
$conf = Dpkg::Conf->new(allow_short => 1);
|
|
|
$conf->load("$datadir/config-mixed");
|
|
|
-$conf->filter(format_argv => 1, remove => sub { $_[0] =~ m/^--option/ });
|
|
|
+$conf->filter(remove => sub { $_[0] =~ m/^--option/ });
|
|
|
is($conf->output, $expected_filter, 'Filter remove');
|
|
|
|
|
|
$expected_filter = <<'FILTER';
|
|
@@ -106,7 +105,7 @@ FILTER
|
|
|
|
|
|
$conf = Dpkg::Conf->new(allow_short => 1);
|
|
|
$conf->load("$datadir/config-mixed");
|
|
|
-$conf->filter(keep => sub { $_[0] =~ m/^option-[a-z]+-quotes/ });
|
|
|
+$conf->filter(keep => sub { $_[0] =~ m/^--option-[a-z]+-quotes/ });
|
|
|
is($conf->output, $expected_filter, 'Filter keep');
|
|
|
|
|
|
$expected_filter = <<'FILTER';
|
|
@@ -115,8 +114,7 @@ FILTER
|
|
|
|
|
|
$conf = Dpkg::Conf->new(allow_short => 1);
|
|
|
$conf->load("$datadir/config-mixed");
|
|
|
-$conf->filter(format_argv => 1,
|
|
|
- remove => sub { $_[0] =~ m/^--option/ },
|
|
|
+$conf->filter(remove => sub { $_[0] =~ m/^--option/ },
|
|
|
keep => sub { $_[0] =~ m/^--/ });
|
|
|
is($conf->output, $expected_filter, 'Filter keep and remove');
|
|
|
|