mk.t 2.2 KB

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