add and change NEWS for 2.8.0 release
[parrot.git] / t / codingstd / copyright.t
blob5591356ffee2f22e1b9922f8be505104d4daeb3f
1 #! perl
2 # Copyright (C) 2007-2009, Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
9 use Cwd;
10 use File::Spec ();
11 use Parrot::Distribution;
12 use Test::More tests => 3;
14 =head1 NAME
16 t/codingstd/copyright.t - checks for an appropriate copyright
17 statement in parrot source files
19 =head1 SYNOPSIS
21     # test all files
22     % prove t/codingstd/copyright.t
24     # test specific files
25     % perl t/codingstd/copyright.t src/foo.c include/parrot/bar.h
27 =head1 DESCRIPTION
29 Ensures that the copyright statement exists in each source file and that it
30 is up to date.
32 =head1 SEE ALSO
34 L<docs/pdds/pdd07_codingstd.pod>
36 =cut
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(),
46 my (
47     @no_copyright_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;
68         next;
69     }
71     # is the copyright text correct?
72     # If so, remove it...
73     if ( ! ($buf =~ s/$copyright_parrot//) ) {
74         push @bad_format_copyright_files, $path;
75     }
76     # ... and then see if any other copyright notices exist.
77     elsif ($buf =~ $copyright_simple) {
78         push @duplicate_copyright_files, $path;
79     }
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
88 END_SUGGESTION
90 # run the tests
91 ok( !scalar(@no_copyright_files), 'Copyright statement exists' )
92     or diag(
93     join
94         $/ => "No copyright statement found in " . scalar @no_copyright_files . " files:",
95     @no_copyright_files,
96     "The copyright statement should read something like:",
97     $suggested_version
98     );
100     ok( !scalar(@bad_format_copyright_files), 'Copyright statement in the right format' )
101         or diag(
102         join
103             $/ => "Bad format in copyright statement found in "
104             . scalar @bad_format_copyright_files
105             . " files:",
106         @bad_format_copyright_files,
107         "Please update to read something like:",
108         $suggested_version
109         );
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 = (
117     {
118         file    => 'examples/c/test_main.c',
119         reason  => 'sample code',
120     },
121     {
122         file    => 'Configure.pl',
123         reason  => 'cite automake copyright statement',
124     },
125     {
126         file    => 'config/gen/opengl.pm',
127         reason  => 'heredoc text for generated file',
128     },
129     {
130         file    => 'lib/Parrot/Configure/Messages.pm',
131         reason  => 'heredoc for print_introduction()',
132     },
133     {
134         file    => 't/tools/dev/searchops/samples.pm',
135         reason  => 'sample code used in testing',
136     },
137     {
138         file    => 'tools/build/vtable_extend.pl',
139         reason  => 'heredoc text for generated file',
140     },
141     {
142         file    => 'tools/dev/create_language.pl',
143         reason  => 'generated files in data section',
144     },
145     {
146         file    => 'examples/pir/quine_ord.pir',
147         reason  => 'quine',
148     },
149     {
150         file    => 'tools/dev/nci_thunk_gen.pir',
151         reason  => 'heredoc text for generated file',
152     },
153     {
154         file    => 'src/main.c',
155         reason  => 'Parrot_version() prints copyright notice ',
156     },
157     {
158         file    => 't/examples/streams.t',
159         reason  => 'heredoc-like text in test',
160     },
162 my $cwd = cwd();
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;
171 TODO: {
172     local $TODO = 'duplicate copyrights exist.';
174     ok( !scalar(@non_permitted_duplicate_copyright_files),
175         'Duplicate Copyright statements' )
176         or diag(
177         join
178             $/ => "Duplicate copyright statement found in "
179             . scalar @non_permitted_duplicate_copyright_files
180             . " 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."
185         );
188 # Local Variables:
189 #   mode: cperl
190 #   cperl-indent-level: 4
191 #   fill-column: 100
192 # End:
193 # vim: expandtab shiftwidth=4: