1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
9 use CPANPLUS::Internals::Constants::Report;
13 my $total_tests = $send_tests + $query_tests;
15 use Test::More 'no_plan';
16 use Module::Load::Conditional qw[can_load];
21 use constant NOBODY => 'nobody@xs4all.nl';
23 my $conf = gimme_conf();
24 my $CB = CPANPLUS::Backend->new( $conf );
25 my $ModName = TEST_CONF_MODULE;
26 my $ModPrereq = TEST_CONF_PREREQ;
28 ### divide by many -- possibly ~0 is unsigned, and we cause an overflow,
29 ### as happens to version.pm 0.7203 among others.
30 my $HighVersion = ~0/1000;
31 my $Mod = $CB->module_tree($ModName);
32 my $int_ver = $CPANPLUS::Internals::VERSION;
34 ### explicitly enable testing if possible ###
35 $CB->configure_object->set_conf(cpantest =>1) if $ARGV[0];
39 buffer => '', # output from build process
40 failed => 0, # indicate failure
41 match => [qw|/PASS/|], # list of regexes for the output
42 check => 0, # check if callbacks got called?
48 '/tests for this module were skipped during this build/',
52 => 1, # did we skip the tests?
55 buffer => missing_prereq_buffer(),
57 match => ['/The comments above are created mechanically/',
58 '/computer-generated error report/',
59 '/Below is the error stack from stage/',
60 '/test suite seem to fail without these modules/',
68 buffer => missing_tests_buffer(),
70 match => ['/The comments above are created mechanically/',
71 '/computer-generated error report/',
72 '/Below is the error stack from stage/',
79 perl_version_too_low_mm => {
80 buffer => perl_version_too_low_buffer_mm(),
82 match => ['/This distribution has been tested/',
83 '/http://testers.cpan.org/',
88 perl_version_too_low_build1 => {
89 buffer => perl_version_too_low_buffer_build(1),
91 match => ['/This distribution has been tested/',
92 '/http://testers.cpan.org/',
97 perl_version_too_low_build2 => {
98 buffer => perl_version_too_low_buffer_build(2),
100 match => ['/This distribution has been tested/',
101 '/http://testers.cpan.org/',
106 prereq_versions_too_low => {
107 ### set the prereq version incredibly high
110 my $clone = $mod->clone;
111 $clone->status->prereqs({ $ModPrereq => $HighVersion });
115 match => ['/This distribution has been tested/',
116 '/http://testers.cpan.org/',
121 prereq_not_on_cpan => {
124 my $clone = $mod->clone;
125 $clone->status->prereqs(
126 { TEST_CONF_INVALID_MODULE, 0 }
131 match => ['/This distribution has been tested/',
132 '/http://testers.cpan.org/',
137 prereq_not_on_cpan_but_core => {
140 my $clone = $mod->clone;
141 $clone->status->prereqs(
142 { TEST_CONF_PREREQ, 0 }
147 match => ['/This distribution has been tested/',
148 '/http://testers.cpan.org/',
155 ### test config settings
156 { for my $opt ( qw[cpantest cpantest_mx] ) {
158 local $SIG{__WARN__} = sub { $warnings .= "@_" };
160 my $org = $conf->get_conf( $opt );
161 ok( $conf->set_conf( $opt => $$ ),
162 "Setting option $opt to $$" );
163 is( $conf->get_conf( $opt ), $$,
164 " Retrieved properly" );
165 ok( $conf->set_conf( $opt => $org ),
166 " Option $opt set back to original" );
167 ok( !$warnings, " No warnings" );
171 ### test constants ###
172 { { my $to = CPAN_MAIL_ACCOUNT->('foo');
173 is( $to, 'foo@cpan.org', "Got proper mail account" );
176 { ok(RELEVANT_TEST_RESULT->($Mod),"Test is relevant" );
178 ### test non-relevant tests ###
179 my $cp = $Mod->clone;
180 $cp->module( $Mod->module . '::' . ($^O eq 'beos' ? 'MSDOS' : 'Be') );
181 ok(!RELEVANT_TEST_RESULT->($cp),"Test is irrelevant");
184 { my $support = "it works!";
185 my @support = ( "No support for OS",
189 ok(!UNSUPPORTED_OS->($support), "OS supported");
190 ok( UNSUPPORTED_OS->($_), "OS not supported") for(@support);
193 { ok(PERL_VERSION_TOO_LOW->( perl_version_too_low_buffer_mm() ),
194 "Perl version too low" );
195 ok(PERL_VERSION_TOO_LOW->( perl_version_too_low_buffer_build(1) ),
196 "Perl version too low" );
197 ok(PERL_VERSION_TOO_LOW->( perl_version_too_low_buffer_build(2) ),
198 "Perl version too low" );
199 ok(!PERL_VERSION_TOO_LOW->('foo'),
200 " Perl version adequate" );
203 { my $tests = "test.pl";
204 my @none = ( "No tests defined for Foo extension.",
205 "'No tests defined for Foo::Bar extension.'",
206 "'No tests defined.'",
208 ok(!NO_TESTS_DEFINED->($tests), "Tests defined");
209 ok( NO_TESTS_DEFINED->($_), "No tests defined") for(@none);
212 { my $fail = 'MAKE TEST'; my $unknown = 'foo';
213 is( TEST_FAIL_STAGE->($fail), lc $fail,
214 "Proper test fail stage found" );
215 is( TEST_FAIL_STAGE->($unknown), 'fetch',
216 "Proper test fail stage found" );
219 ### test missing prereqs
220 { my $str = q[Can't locate Foo/Bar.pm in @INC];
223 { my @list = MISSING_PREREQS_LIST->( $str );
224 is( scalar(@list), 1, " List of missing prereqs found" );
225 is( $list[0], 'Foo::Bar', " Proper prereq found" );
228 ### multiple mentions of same prereq
229 { my @list = MISSING_PREREQS_LIST->( $str . $str );
231 is( scalar(@list), 1, " 1 result for multiple mentions" );
232 is( $list[0], 'Foo::Bar', " Proper prereq found" );
236 { # cp version, author
237 my $header = REPORT_MESSAGE_HEADER->($int_ver,'foo');
238 ok( $header, "Test header generated" );
239 like( $header, qr/Dear foo,/, " Proper content found" );
240 like( $header, qr/puter-gen/, " Proper content found" );
241 like( $header, qr/CPANPLUS,/, " Proper content found" );
242 like( $header, qr/ments may/, " Proper content found" );
246 my $header = REPORT_MESSAGE_FAIL_HEADER->('test','buffer');
247 ok( $header, "Test header generated" );
248 like( $header, qr/uploading/, " Proper content found" );
249 like( $header, qr/RESULTS:/, " Proper content found" );
250 like( $header, qr/stack/, " Proper content found" );
251 like( $header, qr/buffer/, " Proper content found" );
254 { my $prereqs = REPORT_MISSING_PREREQS->('foo','bar@example.com','Foo::Bar');
255 ok( $prereqs, "Test output generated" );
256 like( $prereqs, qr/'foo \(bar\@example\.com\)'/,
257 " Proper content found" );
258 like( $prereqs, qr/Foo::Bar/, " Proper content found" );
259 like( $prereqs, qr/prerequisi/, " Proper content found" );
260 like( $prereqs, qr/PREREQ_PM/, " Proper content found" );
263 { my $prereqs = REPORT_MISSING_PREREQS->(undef,undef,'Foo::Bar');
264 ok( $prereqs, "Test output generated" );
265 like( $prereqs, qr/Your Name/, " Proper content found" );
266 like( $prereqs, qr/Foo::Bar/, " Proper content found" );
267 like( $prereqs, qr/prerequisi/, " Proper content found" );
268 like( $prereqs, qr/PREREQ_PM/, " Proper content found" );
271 { my $missing = REPORT_MISSING_TESTS->();
272 ok( $missing, "Missing test string generated" );
273 like( $missing, qr/tests/, " Proper content found" );
274 like( $missing, qr/Test::More/, " Proper content found" );
277 { my $missing = REPORT_MESSAGE_FOOTER->();
278 ok( $missing, "Message footer string generated" );
279 like( $missing, qr/NOTE/, " Proper content found" );
280 like( $missing, qr/identical/, " Proper content found" );
281 like( $missing, qr/mistaken/, " Proper content found" );
282 like( $missing, qr/appreciate/, " Proper content found" );
283 like( $missing, qr/Additional/, " Proper content found" );
286 { my @libs = MISSING_EXTLIBS_LIST->("No library found for -lfoo\nNo library found for -lbar");
287 ok( @libs, "Missing external libraries found" );
288 my @list = qw(foo bar);
289 is_deeply( \@libs, \@list, " Proper content found" );
292 { my $clone = $Mod->clone;
294 my $prereqs = { $ModPrereq => $HighVersion };
296 $clone->status->prereqs( $prereqs );
298 my $str = REPORT_LOADED_PREREQS->( $clone );
300 like($str, qr/PREREQUISITES:/, "Listed loaded prerequisites" );
301 like($str, qr/\! $ModPrereq\s+\S+\s+\S+/,
302 " Proper content found" );
307 { ### as reported in bug 13086, this callback returned the wrong item
309 ### $self->_callbacks->munge_test_report->($Mod, $message, $grade);
310 my $rv = $CB->_callbacks->munge_test_report->( 1..4 );
311 is( $rv, 2, "Default 'munge_test_report' callback OK" );
315 ### test creating test reports ###
317 skip "You have chosen not to enable test reporting", $total_tests,
318 unless $CB->configure_object->get_conf('cpantest');
320 skip "No report send & query modules installed", $total_tests
321 unless $CB->_have_query_report_modules(verbose => 0);
325 my $mod = $CB->module_tree( TEST_CONF_PREREQ ); # is released to CPAN
326 ok( $mod, "Module retrieved" );
328 ### so we're not pinned down to this specific version of perl
329 my @list = $mod->fetch_report( all_versions => 1 );
330 skip "Possibly no net connection, or server down", 7 unless @list;
333 ok( scalar(@list), "Fetched test report" );
334 is( ref $href, ref {}, " Return value has hashrefs" );
336 ok( $href->{grade}, " Has a grade" );
338 ### XXX use constants for grades?
339 like( $href->{grade}, qr/pass|fail|unknown|na/i,
340 " Grade as expected" );
342 my $pkg_name = $mod->package_name;
343 ok( $href->{dist}, " Has a dist" );
344 like( $href->{dist}, qr/$pkg_name/, " Dist as expected" );
346 ok( $href->{platform}, " Has a platform" );
349 skip "No report sending modules installed", $send_tests
350 unless $CB->_have_send_report_modules(verbose => 0);
352 for my $type ( keys %$map ) {
355 ### never enter the editor for test reports
356 ### but check if the callback actually gets called;
357 my $called_edit; my $called_send;
358 $CB->_register_callback(
359 name => 'edit_test_report',
360 code => sub { $called_edit++; 0 }
363 $CB->_register_callback(
364 name => 'send_test_report',
365 code => sub { $called_send++; 1 }
368 ### reset from earlier tests
369 $CB->_register_callback(
370 name => 'munge_test_report',
371 code => sub { return $_[1] }
374 my $mod = $map->{$type}->{'pre_hook'}
375 ? $map->{$type}->{'pre_hook'}->( $Mod )
379 ### so T::R does not try to resolve our maildomain, which can
380 ### lead to large timeouts for *every* invocation in T::R < 1.51_01
381 ### see: http://code.google.com/p/test-reporter/issues/detail?id=15
382 local $ENV{MAILDOMAIN} ||= 'example.com';
385 buffer => $map->{$type}{'buffer'},
386 failed => $map->{$type}{'failed'},
387 tests_skipped => ($map->{$type}{'skiptests'} ? 1 : 0),
392 ok( $file, "Type '$type' written to file" );
393 ok( -e $file, " File exists" );
395 my $fh = FileHandle->new($file);
396 ok( $fh, " Opened file for reading" );
398 my $in = do { local $/; <$fh> };
399 ok( $in, " File has contents" );
401 for my $regex ( @{$map->{$type}->{match}} ) {
402 like( $in, $regex, " File contains expected contents" );
405 ### check if our registered callback got called ###
406 if( $map->{$type}->{check} ) {
407 ok( $called_edit, " Callback to edit was called" );
408 ok( $called_send, " Callback to send was called" );
414 ### T::R tests don't even try to mail, let's not try and be smarter
416 # { ### use a dummy 'editor' and see if the editor
417 # ### invocation doesn't break things
418 # $conf->set_program( editor => "$^X -le1" );
419 # $CB->_callbacks->edit_test_report( sub { 1 } );
421 # ### XXX whitebox test!!! Might change =/
422 # ### this makes test::reporter not ask for what editor to use
423 # ### XXX stupid lousy perl warnings;
424 # local $Test::Reporter::MacApp = 1;
425 # local $Test::Reporter::MacApp = 1;
427 # ### now try and mail the report to a /dev/null'd mailbox
428 # my $ok = $CB->_send_report(
430 # buffer => $map->{$type}->{'buffer'},
431 # failed => $map->{$type}->{'failed'},
434 # ok( $ok, " Mailed report to NOBODY" );
440 sub missing_prereq_buffer {
443 Can't locate floo.pm in @INC (@INC contains: /Users/kane/sources/p4/other/archive-extract/lib /Users/kane/sources/p4/other/file-fetch/lib /Users/kane/sources/p4/other/archive-tar-new/lib /Users/kane/sources/p4/other/carp-trace/lib /Users/kane/sources/p4/other/log-message/lib /Users/kane/sources/p4/other/module-load/lib /Users/kane/sources/p4/other/params-check/lib /Users/kane/sources/p4/other/qmail-checkpassword/lib /Users/kane/sources/p4/other/module-load-conditional/lib /Users/kane/sources/p4/other/term-ui/lib /Users/kane/sources/p4/other/ipc-cmd/lib /Users/kane/sources/p4/other/config-auto/lib /Users/kane/sources/NSA /Users/kane/sources/NSA/misc /Users/kane/sources/NSA/test /Users/kane/sources/beheer/perl /opt/lib/perl5/5.8.3/darwin-2level /opt/lib/perl5/5.8.3 /opt/lib/perl5/site_perl/5.8.3/darwin-2level /opt/lib/perl5/site_perl/5.8.3 /opt/lib/perl5/site_perl .).
444 BEGIN failed--compilation aborted.
448 sub missing_tests_buffer {
450 cp lib/Acme/POE/Knee.pm blib/lib/Acme/POE/Knee.pm
451 cp demo_race.pl blib/lib/Acme/POE/demo_race.pl
452 cp demo_simple.pl blib/lib/Acme/POE/demo_simple.pl
454 No tests defined for Acme::POE::Knee extension.
458 sub perl_version_too_low_buffer_mm {
460 Running [/usr/bin/perl5.8.1 Makefile.PL ]...
461 Perl v5.8.3 required--this is only v5.8.1, stopped at Makefile.PL line 1.
462 BEGIN failed--compilation aborted at Makefile.PL line 1.
463 [ERROR] Could not run '/usr/bin/perl5.8.1 Makefile.PL': Perl v5.8.3 required--this is only v5.8.1, stopped at Makefile.PL line 1.
464 BEGIN failed--compilation aborted at Makefile.PL line 1.
469 sub perl_version_too_low_buffer_build {
472 ERROR: perl: Version 5.006001 is installed, but we need version >= 5.008001
473 ERROR: version: Prerequisite version isn't installed
474 ERRORS/WARNINGS FOUND IN PREREQUISITES. You may wish to install the versions
475 of the modules indicated above before proceeding with this installation.
478 ERROR: Version 5.006001 of perl is installed, but we need version >= 5.008001
479 ERROR: version: Prerequisite version isn't installed
480 ERRORS/WARNINGS FOUND IN PREREQUISITES. You may wish to install the versions
481 of the modules indicated above before proceeding with this installation.
486 # c-indentation-style: bsd
488 # indent-tabs-mode: nil
490 # vim: expandtab shiftwidth=4: