dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / merge_changelogs.t
CommitLineData
1479465f
GJ
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
16use strict;
17use warnings;
18
19use Test::More tests => 3;
20
21use File::Spec;
22use File::Compare;
23use File::Temp;
24
25use Dpkg::IPC;
26
27my $srcdir = $ENV{srcdir} || '.';
28my $datadir = "$srcdir/t/merge_changelogs";
29
30my $res;
31sub test_merge {
32 my ($expected_file, @options) = @_;
33 my $fh = File::Temp->new();
34 spawn(exec => [ $ENV{PERL}, "$srcdir/dpkg-mergechangelogs.pl", @options ],
35 to_handle => $fh, error_to_file => '/dev/null',
36 wait_child => 1, nocheck => 1);
37 my $res = compare($expected_file, $fh->filename);
38 if ($res) {
39 system('diff', '-u', $expected_file, $fh->filename);
40 }
41 ok($res == 0, "merged changelog matches expected one ($expected_file)");
42}
43
44my $has_alg_merge = 1;
45eval 'use Algorithm::Merge;';
46if ($@) {
47 $has_alg_merge = 0;
48}
49
50my @input = ("$datadir/ch-old", "$datadir/ch-a", "$datadir/ch-b");
51if ($has_alg_merge) {
52 test_merge("$datadir/ch-merged", @input);
53 test_merge("$datadir/ch-merged-pr", '-m', @input);
54} else {
55 test_merge("$datadir/ch-merged-basic", @input);
56 test_merge("$datadir/ch-merged-pr-basic", '-m', @input);
57}
58test_merge("$datadir/ch-badver-merged", ("$datadir/ch-badver-old",
59 "$datadir/ch-badver-a", "$datadir/ch-badver-b"));