Commit | Line | Data |
---|---|---|
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 | ||
16 | use strict; | |
17 | use warnings; | |
18 | ||
19 | use Test::More tests => 3; | |
20 | ||
21 | use File::Spec; | |
22 | use File::Compare; | |
23 | use File::Temp; | |
24 | ||
25 | use Dpkg::IPC; | |
26 | ||
27 | my $srcdir = $ENV{srcdir} || '.'; | |
28 | my $datadir = "$srcdir/t/merge_changelogs"; | |
29 | ||
30 | my $res; | |
31 | sub 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 | ||
44 | my $has_alg_merge = 1; | |
45 | eval 'use Algorithm::Merge;'; | |
46 | if ($@) { | |
47 | $has_alg_merge = 0; | |
48 | } | |
49 | ||
50 | my @input = ("$datadir/ch-old", "$datadir/ch-a", "$datadir/ch-b"); | |
51 | if ($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 | } | |
58 | test_merge("$datadir/ch-badver-merged", ("$datadir/ch-badver-old", | |
59 | "$datadir/ch-badver-a", "$datadir/ch-badver-b")); |