1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#!/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 v5.36;
use Test::More;
use Test::Dpkg qw(:needs :paths test_neutralize_checksums);
use File::Spec::Functions qw(rel2abs);
use File::Compare;
use File::Path qw(make_path);
use Dpkg::File;
use Dpkg::IPC;
use Dpkg::Substvars;
test_needs_command('xz');
plan tests => 8;
my $srcdir = rel2abs($ENV{srcdir} || '.');
my $datadir = "$srcdir/t/dpkg_source";
my $tmpdir = test_get_temp_path();
$ENV{$_} = rel2abs($ENV{$_}) foreach qw(DPKG_DATADIR DPKG_ORIGINS_DIR);
# Delete variables that can affect the tests.
delete $ENV{SOURCE_DATE_EPOCH};
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 $tmpl_control_tests = <<'TMPL_CONTROL_TESTS';
Test-Command: test-unique
Depends: @, aa
Tests: test-dupe
Depends: @builddeps@
Test-Command: test-dupe
Depends: bb, test-binary
Test-Command: test-dupe
Depends: cc
TMPL_CONTROL_TESTS
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) = @_;
file_dump($pathname, $substvars->substvars($tmpl));
}
sub gen_source
{
my (%opts) = @_;
my $substvars = Dpkg::Substvars->new();
foreach my $var ((keys %default_substvars, keys %opts)) {
my $value = $opts{$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 $opts{'control-test'}) {
make_path("$dirname/debian/tests");
gen_from_tmpl("$dirname/debian/tests/control", $opts{'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;
my $stderr;
spawn(
exec => [ $ENV{PERL}, "$srcdir/dpkg-source.pl", '--build', $name ],
error_to_string => \$stderr,
wait_child => 1,
no_check => 1,
);
ok($? == 0, 'dpkg-source --build succeeded');
diag($stderr) unless $? == 0;
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' => $tmpl_control_tests,
);
test_build_source($dirname);
$dirname = gen_source(
'source-name' => 'testsuite',
'source-version' => 3,
);
test_build_source($dirname);
|