mk.t 2.4 KB

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