dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / Dpkg_BuildOptions.t
CommitLineData
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
16use strict;
17use warnings;
18
19use Test::More tests => 28;
20
21use Dpkg::ErrorHandling;
22
23use_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
34my $dbo = Dpkg::BuildOptions->new();
35ok($dbo->has('noopt'), 'has noopt');
36is($dbo->get('noopt'), undef, 'noopt value');
37ok($dbo->has('foonostripbar'), 'has foonostripbar');
38is($dbo->get('foonostripbar'), undef, 'foonostripbar value');
39ok($dbo->has('parallel'), 'has parallel');
40is($dbo->get('parallel'), 3, 'parallel value');
41ok(!$dbo->has('bazNOCHECK'), 'not has bazNOCHECK');
42
43$dbo->reset();
44$dbo->merge('no opt no-strip parallel = 5 nocheck', 'test');
45ok($dbo->has('no'), 'has no');
46is($dbo->get('no'), undef, 'no value');
47ok($dbo->has('opt'), 'has opt');
48is($dbo->get('opt'), undef, 'opt value');
49ok($dbo->has('no-strip'), 'has no-strip');
50is($dbo->get('no-strip'), undef, 'no-strip value');
51ok($dbo->has('parallel'), 'has parallel');
52is($dbo->get('parallel'), '', 'parallel value');
53ok($dbo->has('nocheck'), 'has nocheck');
54is($dbo->get('nocheck'), undef, 'nocheck value');
55
56$dbo->reset();
57$dbo->set('parallel', 5);
58$dbo->set('noopt', undef);
59
60my $env = $dbo->export();
61is($env, 'noopt parallel=5', 'value of export');
62is($ENV{DEB_BUILD_OPTIONS}, $env, 'env match return value of export');
63$env = $dbo->export('OTHER_VARIABLE');
64is($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);
69is($dbo->output(), 'foobar noopt', 'output');
70
71$dbo = Dpkg::BuildOptions->new(envvar => 'OTHER_VARIABLE');
72is($dbo->get('parallel'), 5, 'import from other variable, check parallel');
73ok($dbo->has('noopt'), 'import from other variable, check noopt');
74
75my %theme = (
76 metal => undef,
77 pink => undef,
78 rusty => undef,
79 sky => undef,
80);
81my %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);
88is_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);
95is_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);
102is_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);
109is_deeply(\%theme, \%theme_ref, 'features set with +pink,-sky');