CPAN-Smoker-Utils

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

bin/mirror_cleanup
bin/send_reports
cpanfile
dist.ini
lib/CPAN/Smoker/Utils.pm
lib/CPAN/Smoker/Utils/PerlConfig.pm
t/00-report-prereqs.dd
t/00-report-prereqs.t
t/basic.t
t/dblock.t
t/distroprefs/ARFREITAS.Foo-Bar.yml
t/scripts.t
xt/001-pod.t
xt/002-pod-coverage.t
xt/author/00-compile.t
xt/author/pod-syntax.t
xt/kwalitee.t

README  view on Meta::CPAN

  is_distro_ok
    Expects as parameter a string in the format "AUTHOR/DISTRIBUTION".

    It executes some very basic testing against the string.

    Returns true or false depending if the string passes the tests. It will
    also "warn" if things are not OK.

  block_distro
    Blocks a distribution to be tested under the smoker by using a
    distroprefs file.

    Expects as parameters:

    1.  a distribution name (for example, "JOHNDOE/Some-Distro-Name").

    2.  The perl interpreter (which is in execution) configuration.

    3.  An comment to include in the distroprefs file.

    It returns a hash reference containing keys/values that could be
    directly serialized to YAML (or other format) but the "full_path" key,
    that contains a suggest complete path to the distroprefs file (based on
    the CPAN "prefs_dir" configuration client.

    If there is an already file created as defined in "full_path" key, it
    will "warn" and return "undef".

SEE ALSO
    For more details about those programs interact with the smoker and
    CPAN::Reporter, be sure to read the documentation about CPAN client,
    specially the part about DistroPrefs.

    You will also want to take a look at the following programs

bin/dblock  view on Meta::CPAN


my $perl_info = CPAN::Smoker::Utils::PerlConfig->new;

unless ( my $data_ref = block_distro( $distro, $perl_info->dump, $comment ) )
{
    exit(1);
}
else {
    my $path = delete( $data_ref->{full_path} );

    # to make sure group can write to distroprefs
    umask 002;
    DumpFile( $path, $data_ref );
}

__END__

=head1 dblock

dblock - program to create a distribution preferences file to prevent the smoker
from testing it

bin/dblock  view on Meta::CPAN


This is a required parameter: not providing it will cause the program to abort
with an error.

=item B<--help>

This help message.

=item B<--comment>

Adds a customized comment to the distroprefs file. It's entirely optional, and
if not given, the default text will be the string C<Tests hang smoker>.

Sometimes you want to add an distroprefs when, for example, the distribution
uses too much disk space, and an different message will help to identify that.

=item B<--version>

Prints the version number and exits.

=back

=head1 DESCRIPTION

This program creates a YAML file that describes a Perl distribution preferences
specifically to disable L<CPAN::Reporter> to skip trying to test the
distribution itself.

Sometimes this is required to be included for CPAN Smokers
(see L<CPAN::Reporter::Smoker>) because some distributions just cannot be
tested automatically and makes a smoker to hang during the tests, one will need
to manually terminate the related processes.

The YAML file will be created on the respective home directory of the user,
followed by C<.cpan> and C<prefs>.

See L<CPAN::Reporter> for details. You can check examples of those files on this
project webpage at Github. Those preferences files were created during several
tests executed.

=head1 AUTHOR

Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENSE

lib/CPAN/Smoker/Utils.pm  view on Meta::CPAN

        warn "invalid string '$distro' in --distro!\n\n";
        return 0;
    }
    else {
        return 1;
    }
}

=head2 block_distro

Blocks a distribution to be tested under the smoker by using a distroprefs file.

Expects as parameters:

=over

=item 1.

a distribution name (for example, "JOHNDOE/Some-Distro-Name").

=item 2.

The perl interpreter (which is in execution) configuration.

=item 3.

An comment to include in the distroprefs file.

=back

It returns a hash reference containing keys/values that could be directly
serialized to YAML (or other format) but the C<full_path> key, that contains
a suggest complete path to the distroprefs file (based on the L<CPAN>
C<prefs_dir> configuration client.

If there is an already file created as defined in C<full_path> key, it will
C<warn> and return C<undef>.

=cut

sub block_distro {
    my ( $distro, $perl_info, $comment ) = @_;
    my $distribution = '^' . $distro;
    my $filename     = "$distro.yml";

lib/CPAN/Smoker/Utils.pm  view on Meta::CPAN

    my %data = (
        comment => $comment || 'Tests hang smoker',
        match   => {
            distribution => $distribution,
            perlconfig   => $perl_info
        },
        disabled => 1
    );

    CPAN::HandleConfig->load;
    my $prefs_dir = $CPAN::Config->{prefs_dir};
    die "$prefs_dir does not exist or it is not readable\n"
        unless ( -d $prefs_dir );
    my $full_path = File::Spec->catfile( $prefs_dir, $filename );

    if ( -f $full_path ) {
        warn "$full_path already exists, will not overwrite it.";
        return;
    }
    else {
        $data{full_path} = $full_path;
        return \%data;
    }
}

lib/CPAN/Smoker/Utils/PerlConfig.pm  view on Meta::CPAN


    use CPAN::Smoker::Utils::PerlConfig;

    my $cfg = CPAN::Smoker::Utils::PerlConfig->new;

=head1 DESCRIPTION

This class represents a C<perl> configuration in a way that can be used by the
C<dblock> CLI.

It was created to handle the details of a distroprefs implementation, specially
regarding dealing with C<undef> values.

=head1 METHODS

=head2 new

Creates a new instance of this class.

Expects nothing, returns a new instance.

t/dblock.t  view on Meta::CPAN

plan tests => $total_tests;

SKIP: {

    skip
"Can only run those tests with cpan client, currently testing with cpanplus, version $ENV{PERL5_CPANPLUS_IS_VERSION}",
        $total_tests
        unless ( not( exists( $ENV{PERL5_CPANPLUS_IS_VERSION} ) ) );

    CPAN::HandleConfig->load;
    my $prefs_dir = $CPAN::Config->{prefs_dir};

    skip "prefs_dir '$prefs_dir' is not available for reading/writing",
        $total_tests
        unless ( -d $prefs_dir && -r $prefs_dir && -w $prefs_dir );

    my $distro_name = 'ARFREITAS/Foo-Bar';
    my %perl_info   = (
        no_useithreads => 'define',
        osname         => 'openbsd',
        archname       => 'Openbsd.amd64-openbsd'
    );
    my $data_ref
        = block_distro( $distro_name, \%perl_info, 'Tests hang smoker' );

    # required to avoid issue with different paths
    delete( $data_ref->{full_path} );
    my $expected = LoadFile(
        File::Spec->catfile( 't', 'distroprefs', 'ARFREITAS.Foo-Bar.yml' ) );
    like( $data_ref->{match}->{distribution},
        qr/^\^ARFREITAS/,
        'the created distroprefs has the expected distro name' );

    # to match the current running OS
    update_per_env($expected);
    my $perl_info = CPAN::Smoker::Utils::PerlConfig->new;
    $data_ref
        = block_distro( $distro_name, $perl_info->dump, 'Tests hang smoker' );
    delete( $data_ref->{full_path} );
    note('Testing with CPAN::Reporter::Smoker::OpenBSD::PerlConfig');
    is_deeply( $data_ref, $expected, 'block_distro works as expected' )
        or diag( explain($data_ref) );



( run in 1.639 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )