Commit | Line | Data |
---|---|---|
1479465f GJ |
1 | #!/usr/bin/perl |
2 | # | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | ||
16 | use strict; | |
17 | use warnings; | |
18 | ||
19 | use Test::More tests => 9; | |
20 | use Test::Dpkg qw(:paths); | |
21 | ||
22 | BEGIN { | |
23 | use_ok('Dpkg::Conf'); | |
24 | } | |
25 | ||
26 | my $datadir = test_get_data_path('t/Dpkg_Conf'); | |
27 | ||
28 | my ($conf, $count, @opts); | |
29 | ||
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 | |
48 | -s | |
49 | ); | |
50 | ||
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'); | |
56 | ||
57 | @opts = $conf->get_options(); | |
58 | is_deeply(\@opts, \@expected_long_opts, 'Parse long options'); | |
59 | ||
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'); | |
63 | ||
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'); | |
67 | ||
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" | |
83 | -s | |
84 | MIXED | |
85 | ||
86 | is($conf->output, $expected_mixed_output, 'Output mixed options'); | |
87 | ||
88 | my $expected_filter; | |
89 | ||
90 | $expected_filter = <<'FILTER'; | |
91 | l = "v" | |
92 | -o = "vd" | |
93 | -s | |
94 | FILTER | |
95 | ||
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'); | |
100 | ||
101 | $expected_filter = <<'FILTER'; | |
102 | option-double-quotes = "value double quotes" | |
103 | option-single-quotes = "value single quotes" | |
104 | FILTER | |
105 | ||
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'); | |
110 | ||
111 | $expected_filter = <<'FILTER'; | |
112 | l = "v" | |
113 | FILTER | |
114 | ||
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'); | |
120 | ||
121 | 1; |