2 # Copyright (C) 2007-2009, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
11 use Parrot::Distribution;
12 use Test::More tests => 3;
16 t/codingstd/copyright.t - checks for an appropriate copyright
17 statement in parrot source files
22 % prove t/codingstd/copyright.t
25 % perl t/codingstd/copyright.t src/foo.c include/parrot/bar.h
29 Ensures that the copyright statement exists in each source file and that it
34 L<docs/pdds/pdd07_codingstd.pod>
38 my $DIST = Parrot::Distribution->new;
40 my @files = @ARGV ? <@ARGV> : (
41 $DIST->get_c_language_files(),
42 $DIST->get_perl_language_files(),
43 $DIST->get_make_language_files(),
44 $DIST->get_pir_language_files(),
48 @bad_format_copyright_files,
49 @duplicate_copyright_files,
52 my $copyright_simple =
53 qr/Copyright \(C\) \d{4}/i;
54 my $copyright_parrot =
55 qr/Copyright \(C\) (?:\d{4}\-)?\d{4}, Parrot Foundation\.\n/;
57 foreach my $file (@files) {
59 # if we have command line arguments, the file is the full path
60 # otherwise, use the relevant Parrot:: path method
61 my $path = @ARGV ? $file : $file->path;
63 my $buf = $DIST->slurp($path);
65 # does there exist a copyright statement at all?
66 if ( $buf !~ $copyright_simple ) {
67 push @no_copyright_files, $path;
71 # is the copyright text correct?
73 if ( ! ($buf =~ s/$copyright_parrot//) ) {
74 push @bad_format_copyright_files, $path;
76 # ... and then see if any other copyright notices exist.
77 elsif ($buf =~ $copyright_simple) {
78 push @duplicate_copyright_files, $path;
82 my $suggested_version=<<END_SUGGESTION;
83 Copyright (C) C<start-year>-C<last-year-modified>, Parrot Foundation.
84 To find the C<start-year>, use a command such as:
85 svn log C<filename> | grep 'lines' | tail -n 1
86 To find the C<last-year-modified>, use a command such as:
87 svn log C<filename> | grep 'lines' | head -n 1
91 ok( !scalar(@no_copyright_files), 'Copyright statement exists' )
94 $/ => "No copyright statement found in " . scalar @no_copyright_files . " files:",
96 "The copyright statement should read something like:",
100 ok( !scalar(@bad_format_copyright_files), 'Copyright statement in the right format' )
103 $/ => "Bad format in copyright statement found in "
104 . scalar @bad_format_copyright_files
106 @bad_format_copyright_files,
107 "Please update to read something like:",
111 # Certain files contain the string 'Copyright (c)' more than once
112 # because they contain heredocs for generated files, correctly cite the
113 # copyright information for non-Parrot code, etc. We shall exclude them
114 # from our test for duplicate copyright statements.
116 my @permitted_duplicate_copyright_files = (
118 file => 'examples/c/test_main.c',
119 reason => 'sample code',
122 file => 'Configure.pl',
123 reason => 'cite automake copyright statement',
126 file => 'config/gen/opengl.pm',
127 reason => 'heredoc text for generated file',
130 file => 'lib/Parrot/Configure/Messages.pm',
131 reason => 'heredoc for print_introduction()',
134 file => 't/tools/dev/searchops/samples.pm',
135 reason => 'sample code used in testing',
138 file => 'tools/build/vtable_extend.pl',
139 reason => 'heredoc text for generated file',
142 file => 'tools/dev/create_language.pl',
143 reason => 'generated files in data section',
146 file => 'examples/pir/quine_ord.pir',
150 file => 'tools/dev/nci_thunk_gen.pir',
151 reason => 'heredoc text for generated file',
154 file => 'src/main.c',
155 reason => 'Parrot_version() prints copyright notice ',
158 file => 't/examples/streams.t',
159 reason => 'heredoc-like text in test',
163 my %permitted_duplicate_copyright_files =
164 map { ( File::Spec->catfile( $cwd, $_->{file} ) ) => 1 }
165 @permitted_duplicate_copyright_files;
167 my @non_permitted_duplicate_copyright_files =
168 grep { ! $permitted_duplicate_copyright_files{ $_ } }
169 @duplicate_copyright_files;
172 local $TODO = 'duplicate copyrights exist.';
174 ok( !scalar(@non_permitted_duplicate_copyright_files),
175 'Duplicate Copyright statements' )
178 $/ => "Duplicate copyright statement found in "
179 . scalar @non_permitted_duplicate_copyright_files
181 @non_permitted_duplicate_copyright_files,
182 "Please get copyright assigned to Parrot Foundation",
183 "and remove alternate notice; or remove duplicated",
184 "notice for Parrot Foundation."
190 # cperl-indent-level: 4
193 # vim: expandtab shiftwidth=4: