Преглед на файлове

scripts/t: Add test cases for the makefile snippets

Guillem Jover преди 11 години
родител
ревизия
f9d80776cb
променени са 8 файла, в които са добавени 148 реда и са изтрити 1 реда
  1. 1 0
      debian/changelog
  2. 8 1
      scripts/Makefile.am
  3. 76 0
      scripts/t/mk.t
  4. 30 0
      scripts/t/mk/architecture.mk
  5. 14 0
      scripts/t/mk/buildflags.mk
  6. 5 0
      scripts/t/mk/debian/changelog
  7. 9 0
      scripts/t/mk/pkg-info.mk
  8. 5 0
      scripts/t/mk/vendor.mk

+ 1 - 0
debian/changelog

@@ -71,6 +71,7 @@ dpkg (1.18.2) UNRELEASED; urgency=low
   * Test suite:
     - Set SIGINT, SIGTERM and SIGPIPE to their default actions to get
       deterministic behavior.
+    - Add test cases for the makefile snippets.
   * Packaging:
     - Make the libdpkg-dev package Multi-Arch:same.
     - Mark libio-string-perl as <!nocheck>.

+ 8 - 1
scripts/Makefile.am

@@ -231,7 +231,9 @@ test_scripts = \
 	t/Dpkg_Source_Archive.t \
 	t/Dpkg_Source_Package.t \
 	t/Dpkg_Dist_Files.t \
-	t/merge_changelogs.t
+	t/merge_changelogs.t \
+	t/mk.t \
+	$(nil)
 
 test_data = \
 	t/Dpkg_Shlibs/symbols.blacklisted \
@@ -309,6 +311,11 @@ test_data = \
 	t/merge_changelogs/ch-merged-basic \
 	t/merge_changelogs/ch-merged-pr \
 	t/merge_changelogs/ch-merged-pr-basic \
+	t/mk/debian/changelog \
+	t/mk/architecture.mk \
+	t/mk/buildflags.mk \
+	t/mk/pkg-info.mk \
+	t/mk/vendor.mk \
 	t/origins/debian \
 	t/origins/default \
 	t/origins/gnewsense \

+ 76 - 0
scripts/t/mk.t

@@ -0,0 +1,76 @@
+#!/usr/bin/perl
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use File::Spec::Functions qw(rel2abs);
+
+use Dpkg::ErrorHandling;
+use Dpkg::IPC;
+use Dpkg::Vendor;
+
+my $srcdir = $ENV{srcdir} || '.';
+my $datadir = "$srcdir/t/mk";
+
+# Turn these into absolute names so that we can safely switch to the test
+# directory with «make -C».
+$ENV{$_} = rel2abs($ENV{$_}) foreach qw(srcdir DPKG_DATADIR DPKG_ORIGINS_DIR);
+
+# Delete variables that can affect the tests.
+delete $ENV{DEB_VENDOR};
+
+sub test_makefile {
+    my $makefile = shift;
+
+    spawn(exec => [ 'make', '-C', $datadir, '-f', $makefile ],
+          wait_child => 1, nocheck => 1);
+    ok($? == 0, "makefile $makefile computes all values correctly");
+}
+
+sub get_arch_vars {
+    my $prefix = shift // '';
+    my %arch;
+
+    open my $arch_env, '-|', "$srcdir/dpkg-architecture.pl", '-f'
+        or subprocerr('dpkg-architecture');
+    while (<$arch_env>) {
+        chomp;
+        my ($key, $value) = split /=/, $_, 2;
+        $arch{$key} = $value;
+    }
+    close $arch_env or subprocerr('dpkg-architecture');
+
+    return %arch;
+}
+
+# Test makefiles.
+
+my %arch = get_arch_vars();
+
+delete $ENV{$_} foreach keys %arch;
+$ENV{"TEST_$_"} = $arch{$_} foreach keys %arch;
+test_makefile('architecture.mk');
+$ENV{$_} = $arch{$_} foreach keys %arch;
+test_makefile('architecture.mk');
+
+test_makefile('buildflags.mk');
+
+test_makefile('pkg-info.mk');
+
+test_makefile('vendor.mk');
+
+1;

+ 30 - 0
scripts/t/mk/architecture.mk

@@ -0,0 +1,30 @@
+include $(srcdir)/mk/architecture.mk
+
+test:
+	test "$(DEB_BUILD_ARCH)" = "$(TEST_DEB_BUILD_ARCH)"
+	test "$(DEB_BUILD_ARCH_BITS)" = "$(TEST_DEB_BUILD_ARCH_BITS)"
+	test "$(DEB_BUILD_ARCH_CPU)" = "$(TEST_DEB_BUILD_ARCH_CPU)"
+	test "$(DEB_BUILD_ARCH_ENDIAN)" = "$(TEST_DEB_BUILD_ARCH_ENDIAN)"
+	test "$(DEB_BUILD_ARCH_OS)" = "$(TEST_DEB_BUILD_ARCH_OS)"
+	test "$(DEB_BUILD_GNU_CPU)" = "$(TEST_DEB_BUILD_GNU_CPU)"
+	test "$(DEB_BUILD_GNU_SYSTEM)" = "$(TEST_DEB_BUILD_GNU_SYSTEM)"
+	test "$(DEB_BUILD_GNU_TYPE)" = "$(TEST_DEB_BUILD_GNU_TYPE)"
+	test "$(DEB_BUILD_MULTIARCH)" = "$(TEST_DEB_BUILD_MULTIARCH)"
+	test "$(DEB_HOST_ARCH)" = "$(TEST_DEB_HOST_ARCH)"
+	test "$(DEB_HOST_ARCH_BITS)" = "$(TEST_DEB_HOST_ARCH_BITS)"
+	test "$(DEB_HOST_ARCH_CPU)" = "$(TEST_DEB_HOST_ARCH_CPU)"
+	test "$(DEB_HOST_ARCH_ENDIAN)" = "$(TEST_DEB_HOST_ARCH_ENDIAN)"
+	test "$(DEB_HOST_ARCH_OS)" = "$(TEST_DEB_HOST_ARCH_OS)"
+	test "$(DEB_HOST_GNU_CPU)" = "$(TEST_DEB_HOST_GNU_CPU)"
+	test "$(DEB_HOST_GNU_SYSTEM)" = "$(TEST_DEB_HOST_GNU_SYSTEM)"
+	test "$(DEB_HOST_GNU_TYPE)" = "$(TEST_DEB_HOST_GNU_TYPE)"
+	test "$(DEB_HOST_MULTIARCH)" = "$(TEST_DEB_HOST_MULTIARCH)"
+	test "$(DEB_TARGET_ARCH)" = "$(TEST_DEB_TARGET_ARCH)"
+	test "$(DEB_TARGET_ARCH_BITS)" = "$(TEST_DEB_TARGET_ARCH_BITS)"
+	test "$(DEB_TARGET_ARCH_CPU)" = "$(TEST_DEB_TARGET_ARCH_CPU)"
+	test "$(DEB_TARGET_ARCH_ENDIAN)" = "$(TEST_DEB_TARGET_ARCH_ENDIAN)"
+	test "$(DEB_TARGET_ARCH_OS)" = "$(TEST_DEB_TARGET_ARCH_OS)"
+	test "$(DEB_TARGET_GNU_CPU)" = "$(TEST_DEB_TARGET_GNU_CPU)"
+	test "$(DEB_TARGET_GNU_SYSTEM)" = "$(TEST_DEB_TARGET_GNU_SYSTEM)"
+	test "$(DEB_TARGET_GNU_TYPE)" = "$(TEST_DEB_TARGET_GNU_TYPE)"
+	test "$(DEB_TARGET_MULTIARCH)" = "$(TEST_DEB_TARGET_MULTIARCH)"

+ 14 - 0
scripts/t/mk/buildflags.mk

@@ -0,0 +1,14 @@
+DEB_CPPFLAGS_MAINT_APPEND = -DTEST_MK=test
+
+include $(srcdir)/mk/buildflags.mk
+
+test:
+	test "$(CFLAGS)" = "-g -O2 -fstack-protector-strong -Wformat -Werror=format-security"
+	test "$(CPPFLAGS)" = "-D_FORTIFY_SOURCE=2 -DTEST_MK=test"
+	test "$(CXXFLAGS)" = "-g -O2 -fstack-protector-strong -Wformat -Werror=format-security"
+	test "$(FCFLAGS)" = "-g -O2 -fstack-protector-strong"
+	test "$(FFLAGS)" = "-g -O2 -fstack-protector-strong"
+	test "$(GCJFLAGS)" = "-g -O2 -fstack-protector-strong"
+	test "$(LDFLAGS)" = "-Wl,-z,relro"
+	test "$(OBJCFLAGS)" = "-g -O2 -fstack-protector-strong -Wformat -Werror=format-security"
+	test "$(OBJCXXFLAGS)" = "-g -O2 -fstack-protector-strong -Wformat -Werror=format-security"

+ 5 - 0
scripts/t/mk/debian/changelog

@@ -0,0 +1,5 @@
+source (1:2:3.4-5-6) suite; urgency=low
+
+  * Initial release.
+
+ -- Dpkg Developers <debian-dpkg@lists.debian.org>  Tue, 04 Aug 2015 16:13:50 +0200

+ 9 - 0
scripts/t/mk/pkg-info.mk

@@ -0,0 +1,9 @@
+include $(srcdir)/mk/pkg-info.mk
+
+test:
+	test "$(DEB_SOURCE)" = "source"
+	test "$(DEB_VERSION)" = "1:2:3.4-5-6"
+	test "$(DEB_VERSION_EPOCH_UPSTREAM)" = "1:2:3.4-5"
+	test "$(DEB_VERSION_UPSTREAM_REVISION)" = "2:3.4-5-6"
+	test "$(DEB_VERSION_UPSTREAM)" = "2:3.4-5"
+	test "$(DEB_DISTRIBUTION)" = "suite"

+ 5 - 0
scripts/t/mk/vendor.mk

@@ -0,0 +1,5 @@
+include $(srcdir)/mk/vendor.mk
+
+test:
+	test "$(DEB_VENDOR)" = "Debian"
+	test "$(DEB_PARENT_VENDOR)" = ""