Преглед изворни кода

scripts/t: Add dpkg-buildpackage functional tests

Taken from dpkg-tests functional test suite.
Guillem Jover пре 9 година
родитељ
комит
a54a3c7e86

+ 1 - 0
debian/changelog

@@ -92,6 +92,7 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
       is the test itself.
     - Rename test suite commands to be prefixed with «c-» instead of «t-».
     - Add new dpkg-source functional tests.
+    - Add new dpkg-buildpackage functional tests.
   * Build system:
     - Add support for profiling perl modules.
     - Clean up compiler and linker automatic flag usage in configure.

+ 7 - 0
scripts/Makefile.am

@@ -232,6 +232,7 @@ test_scripts = \
 	t/Dpkg_Source_Package.t \
 	t/Dpkg_Dist_Files.t \
 	t/dpkg_source.t \
+	t/dpkg_buildpackage.t \
 	t/merge_changelogs.t \
 	t/mk.t \
 	$(nil)
@@ -304,6 +305,12 @@ test_data = \
 	t/Dpkg_Substvars/substvars1 \
 	t/Dpkg_Substvars/substvars2 \
 	t/Dpkg_Dist_Files/files-byhand \
+	t/dpkg_buildpackage/test-source_0.dsc \
+	t/dpkg_buildpackage/test-source_0_all.changes \
+	t/dpkg_buildpackage/test-source_0_any.changes \
+	t/dpkg_buildpackage/test-source_0_binary.changes \
+	t/dpkg_buildpackage/test-source_0_full.changes \
+	t/dpkg_buildpackage/test-source_0_source.changes \
 	t/dpkg_source/testsuite_0.dsc \
 	t/dpkg_source/testsuite_1.dsc \
 	t/dpkg_source/testsuite_2.dsc \

+ 209 - 0
scripts/t/dpkg_buildpackage.t

@@ -0,0 +1,209 @@
+#!/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 => 7;
+use Test::Dpkg qw(test_neutralize_checksums);
+
+use File::Spec::Functions qw(rel2abs);
+use File::Compare;
+use File::Path qw(make_path);
+use File::Copy;
+
+use Dpkg::IPC;
+use Dpkg::Build::Types;
+use Dpkg::Substvars;
+
+my $srcdir = rel2abs($ENV{srcdir} || '.');
+my $datadir = "$srcdir/t/dpkg_buildpackage";
+my $tmpdir = 't.tmp/dpkg_buildpackage';
+
+$ENV{$_} = rel2abs($ENV{$_}) foreach qw(DPKG_DATADIR DPKG_ORIGINS_DIR);
+
+# Any paralellization from the parent should be ignored, we are testing
+# the makefiles serially anyway.
+delete $ENV{MAKEFLAGS};
+
+# Delete variables that can affect the tests.
+delete $ENV{SOURCE_DATE_EPOCH};
+
+# Delete other variables that can affect the tests.
+delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV;
+
+make_path($tmpdir);
+
+chdir $tmpdir;
+
+my $tmpl_format = <<'TMPL_FORMAT';
+3.0 (native)
+TMPL_FORMAT
+
+my $tmpl_changelog = <<'TMPL_CHANGELOG';
+${source-name} (${source-version}) ${suite}; urgency=${urgency}
+
+  * Entry. Closes: #12345
+
+ -- ${maintainer}  Thu, 30 Jun 2016 20:15:12 +0200
+TMPL_CHANGELOG
+
+my $tmpl_control = <<'TMPL_CONTROL';
+Source: ${source-name}
+Section: ${source-section}
+Priority: ${source-priority}
+Maintainer: ${maintainer}
+
+Package: test-binary-all
+Architecture: all
+Description: architecture independent binary package
+
+Package: test-binary-any
+Architecture: any
+Description: architecture dependent binary package
+TMPL_CONTROL
+
+my $tmpl_rules = <<'TMPL_RULES';
+#!/usr/bin/make -f
+
+DI := debian/${binary-name-all}
+DA := debian/${binary-name-any}
+
+clean:
+	rm -f debian/files
+	rm -rf $(DI) $(DA)
+
+build-indep:
+build-arch:
+build: build-indep build-arch
+
+binary-indep: build-indep
+	rm -rf $(DI)
+	mkdir -p $(DI)/DEBIAN
+	dpkg-gencontrol -P$(DI) -p${binary-name-all}
+	dpkg-deb --build $(DI) ..
+
+binary-arch: build-arch
+	rm -rf $(DA)
+	mkdir -p $(DA)/DEBIAN
+	dpkg-gencontrol -P$(DA) -p${binary-name-any}
+	dpkg-deb --build $(DA) ..
+
+binary: binary-indep binary-arch
+
+.PHONY: clean build-indep build-arch build binary-indexp binary-arch binary
+TMPL_RULES
+
+my %default_substvars = (
+    'source-name' => 'test-source',
+    'source-version' => 0,
+    'source-section' => 'test',
+    'source-priority' => 'optional',
+    'binary-name-all' => 'test-binary-all',
+    'binary-name-any' => 'test-binary-any',
+    'suite' => 'unstable',
+    'urgency' => 'low',
+    'maintainer' => 'Dpkg Developers <debian-dpkg@lists.debian.org>',
+);
+
+sub gen_from_tmpl
+{
+    my ($pathname, $tmpl, $substvars) = @_;
+
+    open my $fh, '>', $pathname or die;
+    print { $fh } $substvars->substvars($tmpl);
+    close $fh or die;
+}
+
+sub gen_source
+{
+    my (%options) = @_;
+
+    my $substvars = Dpkg::Substvars->new();
+    foreach my $var (%default_substvars) {
+        my $value = $options{$var} // $default_substvars{$var};
+
+        $substvars->set_as_auto($var, $value);
+    }
+
+    my $source = $substvars->get('source-name');
+    my $version = $substvars->get('source-version');
+    my $basename = "$source\_$version";
+    my $dirname = $basename =~ tr/_/-/r;
+
+    make_path("$dirname/debian/source");
+
+    gen_from_tmpl("$dirname/debian/source/format", $tmpl_format, $substvars);
+    gen_from_tmpl("$dirname/debian/changelog", $tmpl_changelog, $substvars);
+    gen_from_tmpl("$dirname/debian/control", $tmpl_control, $substvars);
+    gen_from_tmpl("$dirname/debian/rules", $tmpl_rules, $substvars);
+
+    return $basename;
+}
+
+sub test_diff
+{
+    my $filename = shift;
+
+    my $expected_file = "$datadir/$filename";
+    my $generated_file =  $filename;
+
+    test_neutralize_checksums($generated_file);
+
+    my $res = compare($expected_file, $generated_file);
+    if ($res) {
+        system "diff -u $expected_file $generated_file >&2";
+    }
+    ok($res == 0, "generated file matches expected one ($expected_file)");
+}
+
+sub test_build
+{
+    my ($basename, $type) = @_;
+    my $dirname = $basename =~ tr/_/-/r;
+
+    set_build_type($type, 'buildtype', nocheck => 1);
+    my $typename = get_build_options_from_type();
+    $typename = 'full' if $typename eq 'source,any,all';
+    $typename = 'binary' if $typename eq 'any,all';
+
+    chdir $dirname;
+    spawn(exec => [ "$srcdir/dpkg-buildpackage.pl", '--host-arch=amd64',
+                    "--build=$typename", '--check-command=' ],
+          error_to_file => '/dev/null',
+          wait_child => 1);
+    chdir '..';
+
+    if (build_has_all(BUILD_ARCH_DEP)) {
+        # Rename the file to preserve on consecutive invokations.
+        move("$basename\_amd64.changes", "$basename\_$typename.changes");
+    }
+
+    if (build_has_all(BUILD_SOURCE)) {
+        test_diff("$basename.dsc");
+    }
+
+    test_diff("$basename\_$typename.changes");
+}
+
+my $basename = gen_source();
+
+test_build($basename, BUILD_SOURCE);
+test_build($basename, BUILD_ARCH_INDEP);
+test_build($basename, BUILD_ARCH_DEP);
+test_build($basename, BUILD_BINARY);
+test_build($basename, BUILD_FULL);
+
+1;

+ 15 - 0
scripts/t/dpkg_buildpackage/test-source_0.dsc

@@ -0,0 +1,15 @@
+Format: 3.0 (native)
+Source: test-source
+Binary: test-binary-all, test-binary-any
+Architecture: any all
+Version: 0
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Package-List:
+ test-binary-all deb test optional arch=all
+ test-binary-any deb test optional arch=any
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 test-source_0.tar.xz
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-source_0.tar.xz
+Files:
+ 00000000000000000000000000000000 0 test-source_0.tar.xz

+ 24 - 0
scripts/t/dpkg_buildpackage/test-source_0_all.changes

@@ -0,0 +1,24 @@
+Format: 1.8
+Date: Thu, 30 Jun 2016 20:15:12 +0200
+Source: test-source
+Binary: test-binary-all test-binary-any
+Architecture: all
+Version: 0
+Distribution: unstable
+Urgency: low
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Changed-By: Dpkg Developers <debian-dpkg@lists.debian.org>
+Description:
+ test-binary-all - architecture independent binary package
+ test-binary-any - architecture dependent binary package
+Closes: 12345
+Changes:
+ test-source (0) unstable; urgency=low
+ .
+   * Entry. Closes: #12345
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 test-binary-all_0_all.deb
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-binary-all_0_all.deb
+Files:
+ 00000000000000000000000000000000 0 test optional test-binary-all_0_all.deb

+ 24 - 0
scripts/t/dpkg_buildpackage/test-source_0_any.changes

@@ -0,0 +1,24 @@
+Format: 1.8
+Date: Thu, 30 Jun 2016 20:15:12 +0200
+Source: test-source
+Binary: test-binary-all test-binary-any
+Architecture: amd64
+Version: 0
+Distribution: unstable
+Urgency: low
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Changed-By: Dpkg Developers <debian-dpkg@lists.debian.org>
+Description:
+ test-binary-all - architecture independent binary package
+ test-binary-any - architecture dependent binary package
+Closes: 12345
+Changes:
+ test-source (0) unstable; urgency=low
+ .
+   * Entry. Closes: #12345
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 test-binary-any_0_amd64.deb
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-binary-any_0_amd64.deb
+Files:
+ 00000000000000000000000000000000 0 test optional test-binary-any_0_amd64.deb

+ 27 - 0
scripts/t/dpkg_buildpackage/test-source_0_binary.changes

@@ -0,0 +1,27 @@
+Format: 1.8
+Date: Thu, 30 Jun 2016 20:15:12 +0200
+Source: test-source
+Binary: test-binary-all test-binary-any
+Architecture: all amd64
+Version: 0
+Distribution: unstable
+Urgency: low
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Changed-By: Dpkg Developers <debian-dpkg@lists.debian.org>
+Description:
+ test-binary-all - architecture independent binary package
+ test-binary-any - architecture dependent binary package
+Closes: 12345
+Changes:
+ test-source (0) unstable; urgency=low
+ .
+   * Entry. Closes: #12345
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 test-binary-all_0_all.deb
+ 0000000000000000000000000000000000000000 0 test-binary-any_0_amd64.deb
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-binary-all_0_all.deb
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-binary-any_0_amd64.deb
+Files:
+ 00000000000000000000000000000000 0 test optional test-binary-all_0_all.deb
+ 00000000000000000000000000000000 0 test optional test-binary-any_0_amd64.deb

+ 33 - 0
scripts/t/dpkg_buildpackage/test-source_0_full.changes

@@ -0,0 +1,33 @@
+Format: 1.8
+Date: Thu, 30 Jun 2016 20:15:12 +0200
+Source: test-source
+Binary: test-binary-all test-binary-any
+Architecture: source all amd64
+Version: 0
+Distribution: unstable
+Urgency: low
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Changed-By: Dpkg Developers <debian-dpkg@lists.debian.org>
+Description:
+ test-binary-all - architecture independent binary package
+ test-binary-any - architecture dependent binary package
+Closes: 12345
+Changes:
+ test-source (0) unstable; urgency=low
+ .
+   * Entry. Closes: #12345
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 test-source_0.dsc
+ 0000000000000000000000000000000000000000 0 test-source_0.tar.xz
+ 0000000000000000000000000000000000000000 0 test-binary-all_0_all.deb
+ 0000000000000000000000000000000000000000 0 test-binary-any_0_amd64.deb
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-source_0.dsc
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-source_0.tar.xz
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-binary-all_0_all.deb
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-binary-any_0_amd64.deb
+Files:
+ 00000000000000000000000000000000 0 test optional test-source_0.dsc
+ 00000000000000000000000000000000 0 test optional test-source_0.tar.xz
+ 00000000000000000000000000000000 0 test optional test-binary-all_0_all.deb
+ 00000000000000000000000000000000 0 test optional test-binary-any_0_amd64.deb

+ 27 - 0
scripts/t/dpkg_buildpackage/test-source_0_source.changes

@@ -0,0 +1,27 @@
+Format: 1.8
+Date: Thu, 30 Jun 2016 20:15:12 +0200
+Source: test-source
+Binary: test-binary-all test-binary-any
+Architecture: source
+Version: 0
+Distribution: unstable
+Urgency: low
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Changed-By: Dpkg Developers <debian-dpkg@lists.debian.org>
+Description:
+ test-binary-all - architecture independent binary package
+ test-binary-any - architecture dependent binary package
+Closes: 12345
+Changes:
+ test-source (0) unstable; urgency=low
+ .
+   * Entry. Closes: #12345
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 test-source_0.dsc
+ 0000000000000000000000000000000000000000 0 test-source_0.tar.xz
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-source_0.dsc
+ 0000000000000000000000000000000000000000000000000000000000000000 0 test-source_0.tar.xz
+Files:
+ 00000000000000000000000000000000 0 test optional test-source_0.dsc
+ 00000000000000000000000000000000 0 test optional test-source_0.tar.xz