910_merge_changelogs.t 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- mode: cperl;-*-
  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 <http://www.gnu.org/licenses/>.
  15. use Dpkg::IPC;
  16. use File::Spec;
  17. use Test::More;
  18. use File::Compare;
  19. use File::Temp qw(tempfile);
  20. use strict;
  21. use warnings;
  22. plan tests => 2;
  23. my $srcdir = $ENV{srcdir} || '.';
  24. my $datadir = "$srcdir/t/910_merge_changelogs";
  25. my $res;
  26. sub test_merge {
  27. my ($expected_file, @options) = @_;
  28. my ($fh, $filename) = tempfile();
  29. spawn(exec => ["$srcdir/dpkg-mergechangelogs.pl", @options],
  30. to_handle => $fh, wait_child => 1, nocheck => 1);
  31. my $res = compare($expected_file, $filename);
  32. if ($res) {
  33. system("diff -u $expected_file $filename >&2");
  34. }
  35. ok($res == 0, "merged changelog matches expected one ($expected_file)");
  36. unlink($filename);
  37. }
  38. my $has_alg_merge = 1;
  39. eval 'use Algorithm::Merge;';
  40. if ($@) {
  41. $has_alg_merge = 0;
  42. }
  43. my @input = ("$datadir/ch-old", "$datadir/ch-a", "$datadir/ch-b");
  44. if ($has_alg_merge) {
  45. test_merge("$datadir/ch-merged", @input);
  46. test_merge("$datadir/ch-merged-pr", "-m", @input);
  47. } else {
  48. test_merge("$datadir/ch-merged-basic", @input);
  49. test_merge("$datadir/ch-merged-pr-basic", "-m", @input);
  50. }