--- On Mon, 9/11/09, Philippe Bruhat (BooK) <philippe.bru...@free.fr> wrote:
> compile_ok() would certainly be interesting with scripts > shipped with > a module, that usually have very little meat that needs > testing (since > most of the work is done in the modules), but that one > would at least > check that they compile. OK, here's a quick 'n dirty implementation. Takes either a module name or a script name. If we could get this relatively stable, I might slap it in Test::Most if Schwern doesn't want it in Test::More. #!/usr/bin/env perl use strict; use warnings; use Test::Most 'no_plan'; sub compile_ok ($;$) { my ( $module_or_code, $name ) = @_; my $tb = Test::More->builder; my $perl = $^X; my $command = Test::More::_is_module_name($module_or_code) ? "$perl -M$module_or_code -e 1" : "$perl -c $module_or_code"; my $success = system($command) == 0; my $error = $? >> 8; my $ok = $tb->ok( $success, $name || "$module_or_code compiles" ); unless ($ok) { $tb->diag(<<" DIAGNOSTIC"); Tried to compile '$module_or_code'. Exit status: $error DIAGNOSTIC } return $ok; } compile_ok $0; compile_ok $0, 'we compile'; compile_ok 'CGI'; compile_ok 'No::Such::Module'; Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6