3 # cpantest - sends test results to cpan-testers@perl.org
4 # Copyright (c) 2007 Adam J. Foxson. All rights reserved.
5 # Copyright (c) 2002 Autrijus Tang. All rights reserved.
6 # Copyright (c) 1999 Kurt Starsinic. All rights reserved.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the same terms as Perl itself.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 $VERSION $Grade $Package $No_comment $Automatic $Comment_text $Comment_file
22 %Grades $CC $Report $Tempfile $Subject $Reporter $From $Dump $Perl_version
27 ($Tempfile, $Report) = File::Temp::tempfile(UNLINK => 1);
28 $Reporter = Test::Reporter->new();
30 'pass' => "all tests pass",
31 'fail' => "some tests fail",
32 'na' => "package will not work on this platform",
33 'unknown' => "package did not include tests",
38 &set_transport() if $Transport;
39 &get_comment_file() if $Comment_file;
40 &set_comment() if not $No_comment;
41 &start_editor() unless ($No_comment || ($Comment_text and !$Comment_file));
42 &get_comment() unless $No_comment;
43 &get_package() if not $Package;
46 &get_tested_perl() if $Perl_version;
49 my $fh; open($fh, '>-') or die "Can't open STDOUT: $!";
50 $Reporter->write($fh);
53 &confirm_send() if not $Automatic;
60 print "Error: $message\n" if defined $message;
62 print " cpantest -g grade [ -nc ] [ -auto ] [ -p package ]\n";
63 print " [ -t text | -f file ] [ -from user\@example.com ]\n";
64 print " [ -perl-version path_to_perl ]\n";
65 print " [ -dump | email-addresses ]\n";
66 print " [ -x transport ]\n";
67 print " -g grade Indicates the status of the tested package.\n";
68 print " Possible values for grade are:\n";
71 printf " %-10s %s\n", $_, $Grades{$_};
74 print " -from Specify the From: address.\n";
75 print " -t Specify a short comment.\n";
76 print " -f Specify a file containing comments.\n";
77 print " -p Specify the name of the distribution tested\n";
78 print " (e.g.: Test-Reporter-1.27).\n";
79 print " -nc No comment; you will not be prompted to comment on\n";
80 print " the package.\n";
81 print " -auto Autosubmission (non-interactive); implies -nc.\n";
82 print " -dump Print the report instead of emailing it.\n";
83 print " -perl-version Specify an alternate perl under which the distribution was tested.\n";
84 print " -x Specify a transport: Net::SMTP or Mail::Send.\n";
95 't=s', \$Comment_text,
96 'f=s', \$Comment_file,
99 'perl-version=s', \$Perl_version,
103 $CC = join ' ', @ARGV;
104 $No_comment = 1 if ($Automatic && !$Comment_text && !$Comment_file);
105 $Reporter->from($From) if $From;
109 $Reporter->transport($Transport);
113 usage("-g <grade> is required") unless defined $Grade;
114 usage("grade `$Grade' is invalid") unless defined $Grades{$Grade};
115 usage("-p is required with -auto") if $Automatic and !$Package;
116 usage("can't have both -f and -t") if $Comment_text and $Comment_file;
119 sub get_comment_file {
121 open FH, $Comment_file or die "Can't open comment file: $!";
122 $Comment_text = <FH>;
123 close FH or die "Can't close comment file: $!";
127 chomp $Comment_text if $Comment_text;
129 my $comment = $Comment_text ? $Comment_text : '[ insert comments here ]';
131 $Reporter->comments($comment);
132 print $Tempfile $Reporter->report();
136 # Given an author identifier (either a CPAN authorname or a proper
137 # email address), return a proper email address.
141 if ($author =~ /^[-A-Z]+$/) { # Smells like a CPAN authorname
142 eval { require CPAN } or return undef;
144 my $cpan_author = CPAN::Shell->expand("Author", $author);
146 return eval { $cpan_author->email };
148 elsif ($author =~ /^\S+@[a-zA-Z0-9\.-]+$/) {
155 # Prompt for a new value for $label, given $default; return the user's
158 my ($label, $default) = @_;
160 printf "$label%s", (" [$default]: ");
161 my $input = scalar <STDIN>;
164 return (length $input) ? $input : $default;
168 my $cc = prompt('CC', 'none');
170 return ($cc eq 'none') ? undef : expand_author($cc);
174 my $editor = $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
175 || ($^O eq 'VMS' and "edit/tpu")
176 || ($^O eq 'MSWin32' and "notepad")
179 $editor = prompt('Editor', $editor) unless $Automatic;
181 die "The editor `$editor' could not be run" if system "$editor $Report";
182 die "Empty report; terminated" unless -s $Report > 2;
183 $CC ||= ask_cc() unless $Automatic;
187 $Reporter->comments('');
189 if ($Comment_text and not $Comment_file) {
190 $Reporter->comments($Comment_text);
197 open REPORT, $Report or die $!;
206 close REPORT or die $!;
208 chomp $comment if $comment;
210 if ($comment and $comment ne '[ insert comments here ]')
212 $Reporter->comments($comment);
219 $Package = prompt('Package', $Package);
223 $Reporter->grade($Grade);
224 $Reporter->distribution($Package);
225 $Subject = $Reporter->subject();
229 $Reporter->via("cpantest $VERSION");
232 sub get_tested_perl {
233 $Reporter->perl_version($Perl_version);
237 $Subject = prompt('Subject', $Subject);
240 print "Subject: $Subject\n";
241 print "To: " . $Reporter->address() . "\n";
242 print "Cc: $CC\n" if defined $CC;
244 if (prompt('S)end/I)gnore', 'Ignore') !~ /^[Ss]/) {
245 print "Ignoring message.\n";
252 my @recipients = split /\s+/, $CC;
253 $Reporter->send(@recipients) || die $Reporter->errstr();
256 $Reporter->send() || die $Reporter->errstr();
259 &log() if $ENV{CPANTEST_LOG};
263 open(LOG,">>$ENV{CPANTEST_LOG}") or
264 die "Unable to open $ENV{CPANTEST_LOG}";
265 my $time = localtime;
266 print LOG "$Subject $time\n";
274 B<cpantest> - Report test results of a package retrieved from CPAN
278 B<cpantest> uniformly posts package test results in support of the
279 cpan-testers project. See B<http://testers.cpan.org/> for details.
283 cpantest -g grade [ -nc ] [ -auto ] [ -p package ]
284 [ -t text | -f file ] [ email-addresses ]
293 I<grade> indicates the success or failure of the package's builtin
294 tests, and is one of:
298 pass all tests included with the package passed
299 fail some tests failed
300 na the package does not work on this platform
301 unknown the package did not include tests
305 I<package> is the name of the package you are testing. If you don't
306 supply a value on the command line, you will be prompted for one.
308 For example: Test-Reporter-1.27
312 No comment; you will not be prompted to supply a comment about the
317 A short comment text line.
321 A file containing comments; '-' will make it read from STDIN. Note
322 that an editor will still appear after reading this file.
326 Autosubmission (non-interactive); you won't be prompted to supply any
327 information that you didn't provide on the command line. Implies I<-nc>.
329 =item email-addresses
331 A list of additional email addresses that should be cc:'d in this
332 report (typically, the package's author).
334 =item perl-version perl
336 An alternate version of perl on which the distribution was tested.
337 This option allows reporting on versions of perl for which Test::Reporter
342 Specify a transport: Net::SMTP or Mail::Send. This is optional. One will be
343 chosen for you automatically if not specified. See Test::Reporter docs for
350 This version of the 'cpantest' script was adapted by Adam J. Foxson
351 E<lt>F<afoxson@pobox.com>E<gt> for Test::Reporter, and is based on
352 Autrijus Tang's E<lt>autrijus@autrijus.orgE<gt> adaptations for
353 CPANPLUS, which is in turn based upon the original script by Kurt
354 Starsinic E<lt>F<Kurt.Starsinic@isinet.com>E<gt> with various patches
355 from the CPAN Testers E<lt>F<cpan-testers@perl.org>E<gt>.
359 Copyright (c) 2007 Adam J. Foxson. All rights reserved.
360 Copyright (c) 2002 Autrijus Tang. All rights reserved.
361 Copyright (c) 1999 Kurt Starsinic. All rights reserved.
363 This program is free software; you may redistribute it
364 and/or modify it under the same terms as Perl itself.