Script to check a "Changes" file

This script checks that a Changes file matches CPAN::Changes::Spec and also that it has been included in the ".tar.gz" file. It's meant to be used after make dist. It gets information from either "MYMETA.json" or "META.json".

#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use Test::CPAN::Changes;
use JSON::Parse 'parse_json';
use Path::Tiny;
use Test::More;
my $m = 'MYMETA.json';
if (! -f $m) {
    $m = 'META.json';
    if (! -f $m) {
        die "No $m";
    }
}
my $j = path ($m)->slurp ();
my $p = parse_json ($j);
my $private;
if (-f 'PRIVATE') {
    $private = 1;
}
ok (@{$p->{author}}, "author in meta");
if ($private) {
    like ($p->{author}[0], qr/benkasminbullock\@gmail\.com/, "correct email in author string");
}
else {
    like ($p->{author}[0], qr/bkb\@cpan\.org/, "correct email in author string");
}
ok ($p->{abstract}, "abstract in meta");
my $version = $p->{version};
# Don't bother checking for "Changes" if it's a private module; the
# git log is enough.
if (! $private) {
    changes_file_ok ("Changes", {version => $version});
}
my $subdir = "$p->{name}-$version";

my $tarfile = "$subdir.tar.gz";
my @lines = `tar tfz $tarfile`;
my @bads = (qw/core object backup makefile buildpl pm_to_blib/);
my %has;
for (@lines) {
    s/^\s+|\s+$//g;
    if (/\.core$/) {
        $has{core} = 1;
    }
    if (/\.o$/) {
        $has{object} = 1;
    }
    if (/^#/ || /~$/) {
        $has{backup} = 1;
    }
    if (m!\bMakefile$!) {
        $has{makefile} = 1;
    }
    if (m!\bbuild\.pl$!) {
        $has{buildpl} = 1;
    }
}
for (@bads) {
    ok (! $has{$_}, "no $_ file in tarfile");
}
my %lines;
@lines{@lines} = @lines;
if (! $private) {
    ok ($lines{"$subdir/Changes"}, "Changes in tarfile");
    ok ($lines{"$subdir/README"}, "README in tarfile");
}
ok (! $lines{"$subdir/a.out"}, "no a.out in tarfile");
ok (! $lines{"$subdir/pm_to_blib"}, "no pm_to_blib in tarfile");
ok (! $lines{"$subdir/build.pl"}, "no 'build.pl' in tarfile");
ok (! $lines{"$subdir/Makefile"}, "no Makefile in tarfile");

done_testing ();

# Local Variables:
# mode: perl
# End:

(download)

If the Changes file is broken or not present in the tar file, it returns a failing error status. I use it like this:

    if (system ("check-changes") != 0) {
	clean (%inputs);
	die "Bad Changes file.\n";
    }

A ".pl" has been added to the file name for the sake of this website.


Copyright © Ben Bullock 2009-2019. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer