dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / Dpkg_BuildOptions.t
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 => 28;
20
21 use Dpkg::ErrorHandling;
22
23 use_ok('Dpkg::BuildOptions');
24
25 {
26 no warnings; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
27 # Disable warnings related to invalid values fed during
28 # the tests
29 report_options(quiet_warnings => 1);
30 }
31
32 $ENV{DEB_BUILD_OPTIONS} = 'noopt foonostripbar parallel=3 bazNOCHECK';
33
34 my $dbo = Dpkg::BuildOptions->new();
35 ok($dbo->has('noopt'), 'has noopt');
36 is($dbo->get('noopt'), undef, 'noopt value');
37 ok($dbo->has('foonostripbar'), 'has foonostripbar');
38 is($dbo->get('foonostripbar'), undef, 'foonostripbar value');
39 ok($dbo->has('parallel'), 'has parallel');
40 is($dbo->get('parallel'), 3, 'parallel value');
41 ok(!$dbo->has('bazNOCHECK'), 'not has bazNOCHECK');
42
43 $dbo->reset();
44 $dbo->merge('no opt no-strip parallel = 5 nocheck', 'test');
45 ok($dbo->has('no'), 'has no');
46 is($dbo->get('no'), undef, 'no value');
47 ok($dbo->has('opt'), 'has opt');
48 is($dbo->get('opt'), undef, 'opt value');
49 ok($dbo->has('no-strip'), 'has no-strip');
50 is($dbo->get('no-strip'), undef, 'no-strip value');
51 ok($dbo->has('parallel'), 'has parallel');
52 is($dbo->get('parallel'), '', 'parallel value');
53 ok($dbo->has('nocheck'), 'has nocheck');
54 is($dbo->get('nocheck'), undef, 'nocheck value');
55
56 $dbo->reset();
57 $dbo->set('parallel', 5);
58 $dbo->set('noopt', undef);
59
60 my $env = $dbo->export();
61 is($env, 'noopt parallel=5', 'value of export');
62 is($ENV{DEB_BUILD_OPTIONS}, $env, 'env match return value of export');
63 $env = $dbo->export('OTHER_VARIABLE');
64 is($ENV{OTHER_VARIABLE}, $env, 'export to other variable');
65
66 $ENV{DEB_BUILD_OPTIONS} = 'foobar';
67 $dbo = Dpkg::BuildOptions->new();
68 $dbo->set('noopt', 1);
69 is($dbo->output(), 'foobar noopt', 'output');
70
71 $dbo = Dpkg::BuildOptions->new(envvar => 'OTHER_VARIABLE');
72 is($dbo->get('parallel'), 5, 'import from other variable, check parallel');
73 ok($dbo->has('noopt'), 'import from other variable, check noopt');
74
75 my %theme = (
76 metal => undef,
77 pink => undef,
78 rusty => undef,
79 sky => undef,
80 );
81 my %theme_ref;
82
83 $dbo = Dpkg::BuildOptions->new();
84
85 $theme_ref{$_} = 1 foreach keys %theme;
86 $dbo->set('theme', '+all');
87 $dbo->parse_features('theme', \%theme);
88 is_deeply(\%theme, \%theme_ref, 'features set with +all');
89
90 $theme{$_} = undef foreach keys %theme;
91 $theme_ref{$_} = 1 foreach keys %theme;
92 $theme_ref{rusty} = 0;
93 $dbo->set('theme', '+all,-rusty');
94 $dbo->parse_features('theme', \%theme);
95 is_deeply(\%theme, \%theme_ref, 'features set with +all,-rusty');
96
97 $theme{$_} = undef foreach keys %theme;
98 $theme_ref{$_} = 0 foreach keys %theme;
99 $theme_ref{metal} = 1;
100 $dbo->set('theme', '-all,+metal');
101 $dbo->parse_features('theme', \%theme);
102 is_deeply(\%theme, \%theme_ref, 'features set with +all,-rusty');
103
104 $theme{$_} = $theme_ref{$_} = undef foreach keys %theme;
105 $theme_ref{pink} = 1;
106 $theme_ref{sky} = 0;
107 $dbo->set('theme', '+pink,-sky');
108 $dbo->parse_features('theme', \%theme);
109 is_deeply(\%theme, \%theme_ref, 'features set with +pink,-sky');