| Dist-Zilla-Plugin-CompileTests documentation | Contained in the Dist-Zilla-Plugin-CompileTests distribution. |
Foo::Bar), not the file path
(lib/Foo/Bar.pm).Dist::Zilla::Plugin::CompileTests - common tests to check syntax of your modules
version 1.110930
In your dist.ini:
[CompileTests]
skip = Test$
fake_home = 1
needs_display = 1
This is an extension of Dist::Zilla::Plugin::InlineFiles, providing the following files:
This test will find all modules and scripts in your dist, and try to compile them one by one. This means it's a bit slower than loading them all at once, but it will catch more errors.
This plugin accepts the following options:
Foo::Bar), not the file path
(lib/Foo/Bar.pm).You can also look for information on this module at:
http://cpanratings.perl.org/d/Dist-Zilla-Plugin-CompileTests
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dist-Zilla-Plugin-CompileTests
http://github.com/jquelin/dist-zilla-plugin-compiletests.git.
Jerome Quelin
This software is copyright (c) 2009 by Jerome Quelin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| Dist-Zilla-Plugin-CompileTests documentation | Contained in the Dist-Zilla-Plugin-CompileTests distribution. |
# # This file is part of Dist-Zilla-Plugin-CompileTests # # This software is copyright (c) 2009 by Jerome Quelin. # # This is free software; you can redistribute it and/or modify it under # the same terms as the Perl 5 programming language system itself. # use 5.008; use strict; use warnings; package Dist::Zilla::Plugin::CompileTests; BEGIN { $Dist::Zilla::Plugin::CompileTests::VERSION = '1.110930'; } # ABSTRACT: common tests to check syntax of your modules use Moose; extends 'Dist::Zilla::Plugin::InlineFiles'; with 'Dist::Zilla::Role::FileMunger'; # -- attributes has fake_home => ( is=>'ro', predicate=>'has_fake_home' ); has skip => ( is=>'ro', predicate=>'has_skip' ); # skiplist - a regex has needs_display => ( is=>'ro', predicate=>'has_needs_display' ); # -- public methods # called by the filemunger role sub munge_file { my ($self, $file) = @_; return unless $file->name eq 't/00-compile.t'; my $skip = ( $self->has_skip && $self->skip ) ? sprintf( 'return if $found =~ /%s/;', $self->skip ) : '# nothing to skip'; my $home = ( $self->has_fake_home && $self->fake_home ) ? '' : '# no fake requested ##'; # Skip all tests if you need a display for this test and $ENV{DISPLAY} is not set my $needs_display = ''; if ( $self->has_needs_display && $self->needs_display ) { $needs_display = <<'CODE'; BEGIN { if( not $ENV{DISPLAY} and not $^O eq 'MSWin32' ) { plan skip_all => 'Needs DISPLAY'; exit 0; } } CODE } # replace strings in the file my $content = $file->content; $content =~ s/COMPILETESTS_SKIP/$skip/g; $content =~ s/COMPILETESTS_FAKE_HOME/$home/; $content =~ s/COMPILETESTS_NEEDS_DISPLAY/$needs_display/; $file->content( $content ); } no Moose; __PACKAGE__->meta->make_immutable; 1;
__DATA__ ___[ t/00-compile.t ]___ #!perl use strict; use warnings; use Test::More; COMPILETESTS_NEEDS_DISPLAY use File::Find; use File::Temp qw{ tempdir }; my @modules; find( sub { return if $File::Find::name !~ /\.pm\z/; my $found = $File::Find::name; $found =~ s{^lib/}{}; $found =~ s{[/\\]}{::}g; $found =~ s/\.pm$//; COMPILETESTS_SKIP push @modules, $found; }, 'lib', ); my @scripts; if ( -d 'bin' ) { find( sub { return unless -f; my $found = $File::Find::name; COMPILETESTS_SKIP push @scripts, $found; }, 'bin', ); } my $plan = scalar(@modules) + scalar(@scripts); $plan ? (plan tests => $plan) : (plan skip_all => "no tests to run"); { # fake home for cpan-testers COMPILETESTS_FAKE_HOME local $ENV{HOME} = tempdir( CLEANUP => 1 ); like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" ) for sort @modules; SKIP: { eval "use Test::Script 1.05; 1;"; skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; foreach my $file ( @scripts ) { my $script = $file; $script =~ s!.*/!!; script_compiles( $file, "$script script compiles" ); } } }