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