Explorar el Código

scripts/t: Add dpkg-source functional tests

Guillem Jover hace 12 años
padre
commit
1d8f6e1fa3

+ 1 - 0
debian/changelog

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

+ 5 - 0
scripts/Makefile.am

@@ -231,6 +231,7 @@ test_scripts = \
 	t/Dpkg_Source_Archive.t \
 	t/Dpkg_Source_Package.t \
 	t/Dpkg_Dist_Files.t \
+	t/dpkg_source.t \
 	t/merge_changelogs.t \
 	t/mk.t \
 	$(nil)
@@ -303,6 +304,10 @@ test_data = \
 	t/Dpkg_Substvars/substvars1 \
 	t/Dpkg_Substvars/substvars2 \
 	t/Dpkg_Dist_Files/files-byhand \
+	t/dpkg_source/testsuite_0.dsc \
+	t/dpkg_source/testsuite_1.dsc \
+	t/dpkg_source/testsuite_2.dsc \
+	t/dpkg_source/testsuite_3.dsc \
 	t/merge_changelogs/ch-old \
 	t/merge_changelogs/ch-a \
 	t/merge_changelogs/ch-b \

+ 18 - 0
scripts/Test/Dpkg.pm

@@ -26,6 +26,7 @@ our @EXPORT_OK = qw(
     test_needs_module
     test_needs_command
     test_needs_srcdir_switch
+    test_neutralize_checksums
 );
 our %EXPORT_TAGS = (
     needs => [ qw(
@@ -101,4 +102,21 @@ sub test_needs_srcdir_switch
     }
 }
 
+sub test_neutralize_checksums
+{
+    my $filename = shift;
+    my $filenamenew = "$filename.new";
+
+    open my $fhnew, '>', $filenamenew or die;
+    open my $fh, '<', $filename or die;
+    while (<$fh>) {
+        s/^ ([0-9a-f]{32,}) [1-9][0-9]* /q{ } . $1 =~ tr{0-9a-f}{0}r . q{ 0 }/e;
+        print { $fhnew } $_;
+    }
+    close $fh or die;
+    close $fhnew or die;
+
+    rename $filenamenew, $filename or die;
+}
+
 1;

+ 167 - 0
scripts/t/dpkg_source.t

@@ -0,0 +1,167 @@
+#!/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 => 4;
+use Test::Dpkg qw(test_neutralize_checksums);
+
+use File::Spec::Functions qw(rel2abs);
+use File::Compare;
+use File::Path qw(make_path);
+
+use Dpkg::IPC;
+use Dpkg::Substvars;
+
+my $srcdir = rel2abs($ENV{srcdir} || '.');
+my $datadir = "$srcdir/t/dpkg_source";
+my $tmpdir = 't.tmp/dpkg_source';
+
+$ENV{$_} = rel2abs($ENV{$_}) foreach qw(DPKG_DATADIR DPKG_ORIGINS_DIR);
+
+# Delete variables that can affect the tests.
+delete $ENV{SOURCE_DATE_EPOCH};
+
+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}
+
+  * Test package.
+
+ -- ${maintainer}  Sat, 05 Jul 2014 21:11:22 +0200
+TMPL_CHANGELOG
+
+my $tmpl_control = <<'TMPL_CONTROL';
+Source: ${source-name}
+Section: ${source-section}
+Priority: ${source-priority}
+Maintainer: ${maintainer}
+Standards-Version: 1.0
+Testsuite: ${source-testsuite}
+
+Package: test-binary
+Architecture: all
+Description: test package
+TMPL_CONTROL
+
+my %default_substvars = (
+    'source-name' => 'test-source',
+    'source-version' => 0,
+    'source-section' => 'test',
+    'source-priority' => 'optional',
+    'source-testsuite' => 'autopkgtest',
+    '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 $dirname = "$source-$version";
+
+    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);
+
+    if (defined $options{'control-test'}) {
+        make_path("$dirname/debian/tests");
+        gen_from_tmpl("$dirname/debian/tests/control", $options{'control-test'}, $substvars);
+    }
+
+    return $dirname;
+}
+
+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_source
+{
+    my ($name) = shift;
+
+    spawn(exec => [ "$srcdir/dpkg-source.pl", '-b', $name ],
+          error_to_file => '/dev/null',
+          wait_child => 1, nocheck => 1);
+
+    my $basename = $name =~ tr/-/_/r;
+
+    test_diff("$basename.dsc");
+}
+
+my $dirname;
+
+$dirname = gen_source('source-name' => 'testsuite',
+                      'source-version' => 0,
+                      'control-test' => '');
+test_build_source($dirname);
+
+$dirname = gen_source('source-name' => 'testsuite',
+                      'source-version' => 1,
+                      'control-test' => '');
+test_build_source($dirname);
+
+$dirname = gen_source('source-name' => 'testsuite',
+                      'source-version' => 2,
+                      'source-testsuite' => 'smokepkgtest, unitpkgtest, funcpkgtest',
+                      'control-test' => '');
+test_build_source($dirname);
+
+$dirname = gen_source('source-name' => 'testsuite',
+                      'source-version' => 3);
+test_build_source($dirname);
+
+1;

+ 16 - 0
scripts/t/dpkg_source/testsuite_0.dsc

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

+ 16 - 0
scripts/t/dpkg_source/testsuite_1.dsc

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

+ 16 - 0
scripts/t/dpkg_source/testsuite_2.dsc

@@ -0,0 +1,16 @@
+Format: 3.0 (native)
+Source: testsuite
+Binary: test-binary
+Architecture: all
+Version: 2
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Standards-Version: 1.0
+Testsuite: autopkgtest, funcpkgtest, smokepkgtest, unitpkgtest
+Package-List:
+ test-binary deb test optional arch=all
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 testsuite_2.tar.xz
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 testsuite_2.tar.xz
+Files:
+ 00000000000000000000000000000000 0 testsuite_2.tar.xz

+ 15 - 0
scripts/t/dpkg_source/testsuite_3.dsc

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