File: raw.t

package info (click to toggle)
libcpan-changes-perl 0.500005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,964 kB
  • sloc: perl: 988; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 915 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use strict;
use warnings;
use Test::More;
use constant HAVE_DIFF => eval {
  require Test::Differences;
  Test::Differences::unified_diff();
  1;
};

use CPAN::Changes::Parser;

sub _eq {
  if (HAVE_DIFF) {
    Test::Differences::eq_or_diff(@_[0..2], { context => 5 });
  }
  else {
    goto &Test::More::is;
  }
}

my $parser = CPAN::Changes::Parser->new(version_like => qr/\{\{\s*\$NEXT\s*\}\}/);

for my $log (@ARGV ? @ARGV : glob('corpus/dists/*.changes')) {
  my $content = do {
    open my $fh, '<:raw', $log
      or die "can't read $log: $!";
    local $/;
    <$fh>;
  };
  my $parsed = $parser->_parse($content);
  my $raw = $parsed->{raw_preamble};

  my @entries = @{ $parsed->{releases} || [] };

  while (my $entry = shift @entries) {
    $raw .= $entry->{raw};
    unshift @entries, @{ $entry->{entries} || [] };
  }

  _eq $raw, $content, "raw content properly preserved for $log";
}

done_testing;