The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
#!perl

BEGIN {
    unless ( $ENV{RELEASE_TESTING} ) {
        require Test::More;
        Test::More::plan(
            skip_all => 'these tests are for release candidate testing' );
    }
}

use Test::More tests => 2;

note 'Checking Changes';
my $changes_file = 'Changes';
my $newver       = '0.27';
my $trial_token  = '-TRIAL';

SKIP: {
    ok( -e $changes_file, "$changes_file file exists" )
        or skip 'Changes is missing', 1;

    ok( _get_changes($newver), "$changes_file has content for $newver" );
}

done_testing;

# _get_changes copied and adapted from Dist::Zilla::Plugin::Git::Commit
# by Jerome Quelin
sub _get_changes {
    my $newver = shift;

    # parse changelog to find commit message
    open( my $fh, '<', $changes_file ) or die "cannot open $changes_file: $!";
    my $changelog = join( '', <$fh> );
    close $fh;

    my @content
        = grep { /^$newver(?:$trial_token)?(?:\s+|$)/ ... /^\S/ } # from newver to un-indented
        split /\n/, $changelog;
    shift @content;    # drop the version line

    # drop unindented last line and trailing blank lines
    pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ );

    # return number of non-blank lines
    return scalar @content;
}