Run tests recursively.
[gitmo/moose-dev-utils.git] / cpan-stable-smolder
CommitLineData
07ea463b 1#!/usr/bin/env perl
aa815f88 2
3use strict;
4use warnings;
5use CPAN;
6use Cwd;
7use File::chdir;
f3b33ea9 8use IPC::Run3 qw( run3 );
aa815f88 9
10
11CPAN::HandleConfig->load();
12CPAN::Shell::setup_output();
13CPAN::Index->reload();
14
15local $CPAN::Config->{tar_verbosity} = 'none';
16local $CPAN::Config->{load_module_verbosity} = 'none';
17
18
19my $LOGFILE = ( cwd . "/cpan-stable-smolder.log" );
20
21if ( -f $LOGFILE ) {
22 unlink $LOGFILE;
23}
24
25open my $log, '>', $LOGFILE || die "Could not open $LOGFILE because $!";
26
07827b71 27my $MODULE_LIST_FILE = ( cwd . '/cpan-stable-modules' );
28
29my @modules;
30{
31 open my $fh, $MODULE_LIST_FILE or die "Can't open $MODULE_LIST_FILE: $!";
32 @modules = map { chomp; $_ } <$fh>;
33}
34
ad33ecbf 35test_all_modules(@modules);
aa815f88 36
37close $log;
38
39exit;
40
81b7b406 41sub test_all_modules {
f3b33ea9 42 my @statuses;
43 my @details;
44
2873d006 45 foreach my $project (@_) {
81b7b406 46 my $dist = get_distro_from_cpan($project);
47
48 unless ($dist) {
f3b33ea9 49 print {$log} "UNKNOWN : $project (not on CPAN?)\n";
81b7b406 50 next;
51 }
52
f3b33ea9 53 my ( $passed, $warned, $output ) = test_module( $dist->dir() );
54
55 my $status = $passed && $warned ? 'WARN' : $passed ? 'PASS' : 'FAIL';
56
42e12f75 57 my $summary = "$status: $project - " . $dist->base_id();
58 print {$log} "$summary\n";
f3b33ea9 59
60 push @details, [ $project, $output ]
61 if $warned || ! $passed;
62 }
63
f3b33ea9 64 if (@details) {
65 print {$log} "\n\n";
81b7b406 66
f3b33ea9 67 for my $detail (@details) {
68 print {$log} q{-} x 50;
69 print {$log} "\n";
70 print {$log} "$detail->[0]\n\n";
71 print {$log} "$detail->[1]\n\n";
72 }
81b7b406 73 }
74}
75
aa815f88 76sub get_distro_from_cpan {
77 my $project = shift;
78
79 ( my $module = $project ) =~ s/-/::/g;
80
81 my @mods = CPAN::Shell->expand( 'Module', $module );
82
83 die "Cannot resolve $project to a single module object"
84 if @mods > 1;
85
86 return unless @mods;
87
88 my $dist = $mods[0]->distribution();
89
90 $dist->get();
91
92 return $dist;
93}
94
95sub test_module {
96 my $dir = shift;
97
98 local $CWD = $dir;
99
100 local $ENV{PERL_AUTOINSTALL} = '--defaultdeps';
81b7b406 101 if ( -f "Build.PL" ) {
f3b33ea9 102 return
103 unless _run_commands(
81b7b406 104 [ $^X, 'Build.PL' ],
105 ['./Build'],
f3b33ea9 106 );
aa815f88 107 }
108 else {
f3b33ea9 109 return
110 unless _run_commands(
81b7b406 111 [ $^X, 'Makefile.PL' ],
112 ['make'],
f3b33ea9 113 );
aa815f88 114 }
f3b33ea9 115
116 return _run_tests();
aa815f88 117}
118
81b7b406 119sub _run_commands {
120 for my $cmd (@_) {
f3b33ea9 121 my $output;
122
123 unless ( run3 $cmd, \undef, \$output, \$output ) {
81b7b406 124 warn "Failed to run @{$cmd}\n";
f3b33ea9 125 return ( 0, $output );
aa815f88 126 }
aa815f88 127 }
181b2270 128
129 return 1;
aa815f88 130}
131
f3b33ea9 132sub _run_tests {
133 my $output;
134
ad33ecbf 135 run3 [ qw( prove -br ) ], undef, \$output, \$output;
f3b33ea9 136
137 my $passed = $output =~ /Result: PASS/;
138 my $warned = $output =~ /at .+ line \d+/;
139
140 return ( $passed, $warned, $output );
141}
142