test: Rename merge_changlogs test to match the command being tested
[dpkg.git] / scripts / t / dpkg_mergechangelogs.t
blob646cd2f6ea8608d446032a75a4b8c3678e963310
1 #!/usr/bin/perl
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.
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.
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/>.
16 use strict;
17 use warnings;
19 use Test::More tests => 4;
21 use File::Spec;
22 use File::Compare;
23 use File::Temp;
25 use Dpkg::IPC;
27 my $srcdir = $ENV{srcdir} || '.';
28 my $datadir = "$srcdir/t/dpkg_mergechangelogs";
30 sub test_merge {
31 my ($expected_file, @options) = @_;
32 my $fh = File::Temp->new();
33 spawn(exec => [ $ENV{PERL}, "$srcdir/dpkg-mergechangelogs.pl", @options ],
34 to_handle => $fh, error_to_file => '/dev/null',
35 wait_child => 1, nocheck => 1);
36 my $res = compare($expected_file, $fh->filename);
37 if ($res) {
38 system('diff', '-u', $expected_file, $fh->filename);
40 ok($res == 0, "merged changelog matches expected one ($expected_file)");
43 my $has_alg_merge = 1;
44 eval 'use Algorithm::Merge;';
45 if ($@) {
46 $has_alg_merge = 0;
49 my @input = ("$datadir/ch-old", "$datadir/ch-a", "$datadir/ch-b");
50 if ($has_alg_merge) {
51 test_merge("$datadir/ch-merged", @input);
52 test_merge("$datadir/ch-merged-pr", '-m', @input);
53 test_merge("$datadir/ch-unreleased-merged", '--merge-unreleased',
54 ("$datadir/ch-unreleased-old",
55 "$datadir/ch-unreleased-a",
56 "$datadir/ch-unreleased-b"));
57 } else {
58 test_merge("$datadir/ch-merged-basic", @input);
59 test_merge("$datadir/ch-merged-pr-basic", '-m', @input);
60 test_merge("$datadir/ch-unreleased-merged-basic", '--merge-unreleased',
61 ("$datadir/ch-unreleased-old",
62 "$datadir/ch-unreleased-a",
63 "$datadir/ch-unreleased-b"));
65 test_merge("$datadir/ch-badver-merged", ("$datadir/ch-badver-old",
66 "$datadir/ch-badver-a", "$datadir/ch-badver-b"));