merge_changelogs.t 1.8 KB

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