dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / Dpkg_BuildFlags.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 => 15;
20
21BEGIN {
22 use_ok('Dpkg::BuildFlags');
23}
24
25my $bf = Dpkg::BuildFlags->new();
26
27ok($bf->has('CPPFLAGS'), 'CPPFLAGS is present');
28is($bf->get_origin('CPPFLAGS'), 'vendor', 'CPPFLAGS has a vendor origin');
29
30$bf->set('DPKGFLAGS', '-Wflag -On -fsome', 'system');
31is($bf->get('DPKGFLAGS'), '-Wflag -On -fsome', 'get flag');
32is($bf->get_origin('DPKGFLAGS'), 'system', 'flag has a system origin');
33ok(!$bf->is_maintainer_modified('DPKGFLAGS'), 'set marked flag as non-maint modified');
34
35$bf->strip('DPKGFLAGS', '-On', 'user', undef);
36is($bf->get('DPKGFLAGS'), '-Wflag -fsome', 'get stripped flag');
37is($bf->get_origin('DPKGFLAGS'), 'user', 'flag has a user origin');
38ok(!$bf->is_maintainer_modified('DPKGFLAGS'), 'strip marked flag as non-maint modified');
39
40$bf->append('DPKGFLAGS', '-Wl,other', 'vendor', 0);
41is($bf->get('DPKGFLAGS'), '-Wflag -fsome -Wl,other', 'get appended flag');
42is($bf->get_origin('DPKGFLAGS'), 'vendor', 'flag has a vendor origin');
43ok(!$bf->is_maintainer_modified('DPKGFLAGS'), 'append marked flag as non-maint modified');
44
45$bf->prepend('DPKGFLAGS', '-Idir', 'env', 1);
46is($bf->get('DPKGFLAGS'), '-Idir -Wflag -fsome -Wl,other', 'get prepended flag');
47is($bf->get_origin('DPKGFLAGS'), 'env', 'flag has an env origin');
48ok($bf->is_maintainer_modified('DPKGFLAGS'), 'prepend marked flag as maint modified');
49
50# TODO: Add more test cases.
51
521;