dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / mk.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 => 5;
20 use File::Spec::Functions qw(rel2abs);
21
22 use Dpkg ();
23 use Dpkg::ErrorHandling;
24 use Dpkg::IPC;
25 use Dpkg::Vendor;
26
27 my $srcdir = $ENV{srcdir} || '.';
28 my $datadir = "$srcdir/t/mk";
29
30 # Turn these into absolute names so that we can safely switch to the test
31 # directory with «make -C».
32 $ENV{$_} = rel2abs($ENV{$_}) foreach qw(srcdir DPKG_DATADIR DPKG_ORIGINS_DIR);
33
34 # Any parallelization from the parent should be ignored, we are testing
35 # the makefiles serially anyway.
36 delete $ENV{MAKEFLAGS};
37
38 # Delete other variables that can affect the tests.
39 delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV;
40
41 $ENV{DEB_BUILD_PATH} = rel2abs($datadir);
42
43 sub test_makefile {
44 my $makefile = shift;
45
46 spawn(exec => [ $Dpkg::PROGMAKE, '-C', $datadir, '-f', $makefile ],
47 wait_child => 1, nocheck => 1);
48 ok($? == 0, "makefile $makefile computes all values correctly");
49 }
50
51 sub cmd_get_vars {
52 my (@cmd) = @_;
53 my %var;
54
55 open my $cmd_fh, '-|', @cmd or subprocerr($cmd[0]);
56 while (<$cmd_fh>) {
57 chomp;
58 my ($key, $value) = split /=/, $_, 2;
59 $var{$key} = $value;
60 }
61 close $cmd_fh or subprocerr($cmd[0]);
62
63 return %var;
64 }
65
66 # Test makefiles.
67
68 my %arch = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-architecture.pl", '-f');
69
70 delete $ENV{$_} foreach keys %arch;
71 $ENV{"TEST_$_"} = $arch{$_} foreach keys %arch;
72 test_makefile('architecture.mk');
73 $ENV{$_} = $arch{$_} foreach keys %arch;
74 test_makefile('architecture.mk');
75
76 my %buildflag = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-buildflags.pl");
77
78 delete $ENV{$_} foreach keys %buildflag;
79 $ENV{"TEST_$_"} = $buildflag{$_} foreach keys %buildflag;
80 test_makefile('buildflags.mk');
81
82 test_makefile('pkg-info.mk');
83
84 test_makefile('vendor.mk');
85
86 1;