Mercurial > hg > chronicle
diff tests/perl-syntax.t @ 1:bc8961a81af6 release
2007-08-13 22:53:14 by steve
Initial revision
author | steve |
---|---|
date | Mon, 13 Aug 2007 22:53:14 +0000 |
parents | |
children | 8503c495b169 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/perl-syntax.t Mon Aug 13 22:53:14 2007 +0000 @@ -0,0 +1,70 @@ +#!/usr/bin/perl -w +# +# Test that every perl file we have passes the syntax check. +# +# Steve +# -- +# $Id: perl-syntax.t,v 1.1.1.1 2007-08-13 22:53:14 steve Exp $ + + +use strict; +use File::Find; +use Test::More qw( no_plan ); + + +# +# Find all the files beneath the current directory, +# and call 'checkFile' with the name. +# +find( { wanted => \&checkFile, no_chdir => 1 }, '.' ); + + + +# +# Check a file. +# +# If this is a perl file then call "perl -c $name", otherwise +# return +# +sub checkFile +{ + # The file. + my $file = $File::Find::name; + + # We don't care about directories + return if ( ! -f $file ); + + # `modules.sh` is a false positive. + return if ( $file =~ /modules.sh$/ ); + + # See if it is a perl file. + my $isPerl = 0; + + # Read the file. + open( INPUT, "<", $file ); + foreach my $line ( <INPUT> ) + { + if ( $line =~ /\/usr\/bin\/perl/ ) + { + $isPerl = 1; + } + } + close( INPUT ); + + # + # Return if it wasn't a perl file. + # + return if ( ! $isPerl ); + + # + # Now run 'perl -c $file' to see if we pass the syntax + # check. We add a couple of parameters to make sure we're + # really OK. + # + # use strict "vars"; + # use strict "subs"; + # + my $retval = system( "perl -Mstrict=subs -Mstrict=vars -c $file 2>/dev/null >/dev/null" ); + + is( $retval, 0, "Perl file passes our syntax check: $file" ); +}