po: Update German man pages translation
[dpkg.git] / scripts / t / Dpkg_Conf.t
blob432c508a12b08bb3eaebad660dbb4c904ad125a0
1 #!/usr/bin/perl
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/>.
16 use strict;
17 use warnings;
19 use Test::More tests => 9;
20 use Test::Dpkg qw(:paths);
22 BEGIN {
23 use_ok('Dpkg::Conf');
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',
34 qw(
35 --option-dupe=value1
36 --option-name=value-name
37 --option-indent=value-indent
38 --option-equal=value-equal=subvalue-equal
39 --option-noequal=value-noequal
40 --option-dupe=value2
41 --option-simple
42 --option-dash=value-dash
43 --option-dupe=value3
44 --l=v
45 ));
46 my @expected_short_opts = qw(
47 -o=vd
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"
78 option-simple
79 option-dash = "value-dash"
80 option-dupe = "value3"
81 l = "v"
82 -o = "vd"
84 MIXED
86 is($conf->output, $expected_mixed_output, 'Output mixed options');
88 my $expected_filter;
90 $expected_filter = <<'FILTER';
91 l = "v"
92 -o = "vd"
94 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"
104 FILTER
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';
112 l = "v"
113 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');