2 # Copyright (C) 2007-2009, Parrot Foundation.
9 use lib qw( . lib ../lib ../../lib );
10 use Parrot::Distribution;
11 use Test::More tests => 3;
15 t/codingstd/copyright.t - checks for an appropriate copyright
16 statement in parrot source files
21 % prove t/codingstd/copyright.t
24 % perl t/codingstd/copyright.t src/foo.c include/parrot/bar.h
28 Ensures that the copyright statement exists in each source file and that it
33 L<docs/pdds/pdd07_codingstd.pod>
37 my $DIST = Parrot::Distribution->new;
39 my @files = @ARGV ? <@ARGV> : (
40 $DIST->get_c_language_files(),
41 $DIST->get_perl_language_files(),
42 $DIST->get_make_language_files(),
43 $DIST->get_pir_language_files(),
47 @bad_format_copyright_files,
48 @duplicate_copyright_files,
51 my $copyright_simple =
52 qr/Copyright \(C\) \d{4}/i;
53 my $copyright_parrot =
54 qr/Copyright \(C\) (?:\d{4}\-)?\d{4}, Parrot Foundation\.\n/;
56 foreach my $file (@files) {
58 # if we have command line arguments, the file is the full path
59 # otherwise, use the relevant Parrot:: path method
60 my $path = @ARGV ? $file : $file->path;
62 my $buf = $DIST->slurp($path);
64 # does there exist a copyright statement at all?
65 if ( $buf !~ $copyright_simple ) {
66 push @no_copyright_files, $path;
70 # is the copyright text correct?
72 if ( ! ($buf =~ s/$copyright_parrot//) ) {
73 push @bad_format_copyright_files, $path;
75 # ... and then see if any other copyright notices exist.
76 elsif ($buf =~ $copyright_simple) {
77 push @duplicate_copyright_files, $path;
81 my $suggested_version=<<END_SUGGESTION;
82 Copyright (C) C<start-year>-C<last-year-modified>, Parrot Foundation.
83 To find the C<start-year>, use a command such as:
84 svn log C<filename> | grep 'lines' | tail -n 1
85 To find the C<last-year-modified>, use a command such as:
86 svn log C<filename> | grep 'lines' | head -n 1
90 ok( !scalar(@no_copyright_files), 'Copyright statement exists' )
93 $/ => "No copyright statement found in " . scalar @no_copyright_files . " files:",
95 "The copyright statement should read something like:",
99 ok( !scalar(@bad_format_copyright_files), 'Copyright statement in the right format' )
102 $/ => "Bad format in copyright statement found in "
103 . scalar @bad_format_copyright_files
105 @bad_format_copyright_files,
106 "Please update to read something like:",
110 # Certain files contain the string 'Copyright (c)' more than once
111 # because they contain heredocs for generated files, correctly cite the
112 # copyright information for non-Parrot code, etc. We shall exclude them
113 # from our test for duplicate copyright statements.
115 my @permitted_duplicate_copyright_files = (
117 file => 'examples/c/test_main.c',
118 reason => 'sample code',
121 file => 'Configure.pl',
122 reason => 'cite automake copyright statement',
125 file => 'config/gen/opengl.pm',
126 reason => 'heredoc text for generated file',
129 file => 'lib/Parrot/Configure/Messages.pm',
130 reason => 'heredoc for print_introduction()',
133 file => 't/tools/dev/searchops/samples.pm',
134 reason => 'sample code used in testing',
137 file => 'tools/build/nativecall.pl',
138 reason => 'heredoc text for generated file',
141 file => 'tools/build/vtable_extend.pl',
142 reason => 'heredoc text for generated file',
145 file => 'examples/pir/quine_ord.pir',
150 my %permitted_duplicate_copyright_files =
151 map { ( File::Spec->catfile( $cwd, $_->{file} ) ) => 1 }
152 @permitted_duplicate_copyright_files;
154 my @non_permitted_duplicate_copyright_files =
155 grep { ! $permitted_duplicate_copyright_files{ $_ } }
156 @duplicate_copyright_files;
159 local $TODO = 'duplicate copyrights exist.';
161 ok( !scalar(@non_permitted_duplicate_copyright_files),
162 'Duplicate Copyright statements' )
165 $/ => "Duplicate copyright statement found in "
166 . scalar @non_permitted_duplicate_copyright_files
168 @non_permitted_duplicate_copyright_files,
169 "Please get copyright assigned to Parrot Foundation",
170 "and remove alternate notice; or remove duplicated",
171 "notice for Parrot Foundation."
177 # cperl-indent-level: 4
180 # vim: expandtab shiftwidth=4: