Skip to content

Commit

Permalink
have the dependents test test all dependents
Browse files Browse the repository at this point in the history
  • Loading branch information
wchristian committed Feb 24, 2024
1 parent 19e390a commit e527641
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test-dependents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ jobs:
image: perldocker/perl-tester:5.34
steps:
- uses: actions/checkout@v4
- name: install extra modules
run: cpm install -g Test::DependentModules
- name: Run Tests
env:
AUTHOR_TESTING: 0
AUTOMATED_TESTING: 1
EXTENDED_TESTING: 1
RELEASE_TESTING: 1
run: auto-build-and-test-dist
- name: install action prereqs
run: cpm install -g Test::DependentModules IO::All
- name: generate dep prereqs
run: perl -Ixt -MDepReqs -e 'DepReqs->run'
- name: install dep prereqs
run: cpm install -g --cpanfile xt/cpanfile --show-build-log-on-failure
- name: Test Dependents
env:
TEST_DEPENDENTS: 1
PERL_TEST_DM_CPAN_VERBOSE: 1
run: prove -l xt/dependent-modules.t
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/PPI-*.tar.gz
/nytprof*
/TODO
/xt/cpanfile
98 changes: 98 additions & 0 deletions xt/DepReqs.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package #
DepReqs;

use 5.010;
use strictures 2;

use Test::DependentModules;
use IO::All;
use MetaCPAN::Client;
use List::Util 'uniqstr';
use Devel::Confess;

1;

__PACKAGE__->run unless caller;

sub exclusions {
qr/^(
# don't remember why i excluded these
Apache2-SSI|Devel-IPerl|Padre
# fails tests regarding directory write permissions, probably not PPI
|Devel-Examine-Subs
# their dependencies don't even install
|Devel-ebug-HTTP|Padre-Plugin-ParserTool|Devel-PerlySense|PPI-Tester
|Acme-ReturnValue|Bot-BasicBot-Pluggable-Module-Gitbot|Pinwheel
|Dist-Zilla-Plugin-MetaProvides-Package|Dist-Zilla-Plugin-Readme-Brief
|Apache2-PPI-HTML
# author parsing issue
|Spellunker-Perl
# takes too long
|RPerl
# broken on cpan
|Acme-VarMess|Module-Checkstyle|MooseX-Documenter|Perl-Achievements
|Perl-Metrics|Ravenel|Test-LocalFunctions|UML-Class-Simple
# maybe broken on cpan
|App-Grepl|App-Midgen|App-PRT|Pod-Weaver-Section-SQL
# investigate
|Class-Discover|Devel-Decouple|File-PackageIndexer|Perl-Signature
|Perl-Squish|Perl-ToPerl6|Test-Declare
# RT 76417
|Devel-Graph
# meeds Class::Gomor as dep
|Metabrik
# depends on RPerl
|MLPerl
# RT 129344
|Module-AnyEvent-Helper
)$/x
}

sub force_big_metacpan_fetch {
## force metacpan to actually return the whole dependents list
# https://github.com/metacpan/metacpan-client/issues/122
my $old_fetch = \&MetaCPAN::Client::fetch;
my $new_fetch = sub { $old_fetch->( shift, shift . "?size=5000", @_ ) };
{ no warnings 'redefine'; *MetaCPAN::Client::fetch = $new_fetch; }

return $old_fetch;
}

sub run {
my $old_fetch = force_big_metacpan_fetch;

my @deps =
Test::DependentModules::_get_deps PPI => { exclude => exclusions() };

{ no warnings 'redefine'; *MetaCPAN::Client::fetch = $old_fetch; }

my $c = MetaCPAN::Client->new;
my @reqs;
for my $dependent (@deps) {
say $dependent;
my @dep_reqs = map @{ $c->release($_)->dependency }, $dependent;
say " $_->{module}" for @dep_reqs;
push @reqs, @dep_reqs;
}

say "writing file";
io("xt/cpanfile")
->print( join "\n",
uniqstr map qq[requires "$_->{module}" => "$_->{version}";], @reqs );

say "debug printing file";
say io("xt/cpanfile")->all;

# test early that all modules don't have an author that crashes tests later
# !!! careful, this changes CWD !!!
Test::DependentModules::_load_cpan;
for my $name (@deps) {
my $mod = $name;
$mod =~ s/-/::/g;
next unless #
my $dist = Test::DependentModules::_get_distro($mod);
$dist->author->id;
}

say "done";
}
39 changes: 28 additions & 11 deletions xt/dependent-modules.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
use strict;
use warnings;
use Test2::V0;
use strictures 2;

use Test::DependentModules qw( test_modules );
use Test::More;
use Test::DependentModules 'test_all_dependents';
use MetaCPAN::Client;
use Devel::Confess;

my @modules = ('Perl::Critic');
use lib '.';

SKIP: {
skip '$ENV{TEST_DEPENDENTS} not set', scalar @modules
unless $ENV{TEST_DEPENDENTS};
test_modules(@modules);
require( -e "xt" ? "xt/DepReqs.pm" : "DepReqs.pm" );

}
skip_all "ENV var TEST_DEPENDENTS not set" if not $ENV{TEST_DEPENDENTS};

done_testing();
# duplicate error output into an array for later printing
my @error_log;
my $old_log = \&Test::DependentModules::_error_log;
my $new_log = sub { push @error_log, @_; $old_log->(@_); };
{ no warnings 'redefine'; *Test::DependentModules::_error_log = $new_log; }

DepReqs::force_big_metacpan_fetch();

test_all_dependents PPI => { exclude => DepReqs::exclusions() };

my $error_log = join "\n", @error_log;
my $fails = join "\n", $error_log =~ /(FAIL: .*\w+)$/mg;

diag "\n\n---------- ERROR LOG START -----------\n\n",
@error_log,
"\n\n---------- FAILS: -----------\n\n",
$fails,
"\n\n---------- ERROR LOG END -----------\n\n";

done_testing;

0 comments on commit e527641

Please sign in to comment.