3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 use Test
::More tests
=> 9;
20 use Test
::Dpkg
qw(:paths);
26 my $datadir = test_get_data_path
();
28 my ($conf, $count, @opts);
30 my @expected_long_opts = (
31 '--option-double-quotes=value double quotes',
32 '--option-single-quotes=value single quotes',
33 '--option-space=value words space',
36 --option-name=value-name
37 --option-indent=value-indent
38 --option-equal=value-equal=subvalue-equal
39 --option-noequal=value-noequal
42 --option-dash=value-dash
46 my @expected_short_opts = qw(
51 $conf = Dpkg
::Conf
->new();
52 local $SIG{__WARN__
} = sub { };
53 $count = $conf->load("$datadir/config-mixed");
54 delete $SIG{__WARN__
};
55 is
($count, 13, 'Load a config file, only long options');
57 @opts = $conf->get_options();
58 is_deeply
(\
@opts, \
@expected_long_opts, 'Parse long options');
60 $conf = Dpkg
::Conf
->new(allow_short
=> 1);
61 $count = $conf->load("$datadir/config-mixed");
62 is
($count, 15, 'Load a config file, mixed options');
64 @opts = $conf->get_options();
65 my @expected_mixed_opts = ( @expected_long_opts, @expected_short_opts );
66 is_deeply
(\
@opts, \
@expected_mixed_opts, 'Parse mixed options');
68 my $expected_mixed_output = <<'MIXED';
69 option-double-quotes = "value double quotes"
70 option-single-quotes = "value single quotes"
71 option-space = "value words space"
72 option-dupe = "value1"
73 option-name = "value-name"
74 option-indent = "value-indent"
75 option-equal = "value-equal=subvalue-equal"
76 option-noequal = "value-noequal"
77 option-dupe = "value2"
79 option-dash = "value-dash"
80 option-dupe = "value3"
86 is
($conf->output, $expected_mixed_output, 'Output mixed options');
90 $expected_filter = <<'FILTER';
96 $conf = Dpkg
::Conf
->new(allow_short
=> 1);
97 $conf->load("$datadir/config-mixed");
98 $conf->filter(remove
=> sub { $_[0] =~ m/^--option/ });
99 is
($conf->output, $expected_filter, 'Filter remove');
101 $expected_filter = <<'FILTER';
102 option-double-quotes = "value double quotes"
103 option-single-quotes = "value single quotes"
106 $conf = Dpkg
::Conf
->new(allow_short
=> 1);
107 $conf->load("$datadir/config-mixed");
108 $conf->filter(keep
=> sub { $_[0] =~ m/^--option-[a-z]+-quotes/ });
109 is
($conf->output, $expected_filter, 'Filter keep');
111 $expected_filter = <<'FILTER';
115 $conf = Dpkg
::Conf
->new(allow_short
=> 1);
116 $conf->load("$datadir/config-mixed");
117 $conf->filter(remove
=> sub { $_[0] =~ m/^--option/ },
118 keep
=> sub { $_[0] =~ m/^--/ });
119 is
($conf->output, $expected_filter, 'Filter keep and remove');