910_merge_changelogs.t 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 => 3;
  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, error_to_file => "/dev/null",
  31. wait_child => 1, nocheck => 1);
  32. my $res = compare($expected_file, $filename);
  33. if ($res) {
  34. system("diff -u $expected_file $filename >&2");
  35. }
  36. ok($res == 0, "merged changelog matches expected one ($expected_file)");
  37. unlink($filename);
  38. }
  39. my $has_alg_merge = 1;
  40. eval 'use Algorithm::Merge;';
  41. if ($@) {
  42. $has_alg_merge = 0;
  43. }
  44. my @input = ("$datadir/ch-old", "$datadir/ch-a", "$datadir/ch-b");
  45. if ($has_alg_merge) {
  46. test_merge("$datadir/ch-merged", @input);
  47. test_merge("$datadir/ch-merged-pr", "-m", @input);
  48. } else {
  49. test_merge("$datadir/ch-merged-basic", @input);
  50. test_merge("$datadir/ch-merged-pr-basic", "-m", @input);
  51. }
  52. test_merge("$datadir/ch-badver-merged", ("$datadir/ch-badver-old",
  53. "$datadir/ch-badver-a", "$datadir/ch-badver-b"));