#! perl # Copyright (C) 2007, The Perl Foundation. =head1 NAME adjustcopyright.t - check copyright for all files in the parrot distr. =head1 SYNOPSIS =head1 DESCRIPTION This test checks the "Last Changed Date" according to SVN for the year it was changed. Then it looks in the file being processed for a copyright notice, and extracts the year. Then, if $SVNYear > $fileYear, fail test (and the copyright should be updated). =head1 ISSUES =over 4 =item * C^C won't stop the testing... =item * How to restore stderr after having it redirected to stdout? =cut use strict; use warnings; use lib qw( . lib ../lib ../../lib ); use File::Find; use Parrot::Test; use Parrot::Config; use Test::More; # don't know how many files will be tested: plan tests => 1; sub vdiag(@) { &diag if $ENV{TEST_VERBOSE} } sub checkCopyright { my $file = $_; # only handle files, not directories return unless -f $file; # only handle text files return unless -T $file; # if there's '.svn' in the filename, it's the directory (probably?) return if $File::Find::name =~ m/.*\.svn.*/; my $cmd = "svn info $File::Find::name"; # # FIXME: restore stderr->stdout after we're done. # my $output = `$cmd 2>&1`; my $SVNYear = undef; # to store the year according to SVN if ($output =~ m/.*Last Changed Date:\s+(\d\d\d\d).*/) { $SVNYear = $1; } else { return; } open(FILE, "< $File::Find::name") or die "cannot open file $File::Find::name"; while() { # on failure, it should emit the failing file's name so we can fix it! # check for copyright lines containing only 1 year; note the matching space here. if ($_ =~ m/.*[cC]opyright[^[\d\d\d\d\-]]*(\d\d\d\d).*/ ) { # check for match # ok found it, now compare with $SVNYear # only change when SVN Year > current is($1, $SVNYear); } # check for copyright lines like X-Y elsif ($_ =~ m/.*[cC]opyright[^\d]*\d\d\d\d\-(\d\d\d\d).*/ ) { is($1, $SVNYear); } } close(FILE); } { # set $parrotRootDir to parrot build directory: my $parrotRootDir = $PConfig{'build_dir'}; # find takes an array containing directories to # be processed, we only have 1 directory: parrot my @dirlist = (); push @dirlist, $parrotRootDir; # check copyright for each file. find(\&checkCopyright, @dirlist); }