From c3d82aa011d7190edb093127eadfa6e26ddee386 Mon Sep 17 00:00:00 2001 From: Christian Walde Date: Sat, 23 Sep 2023 15:26:59 +0200 Subject: [PATCH] have the dependents test test all dependents --- .github/workflows/test-dependents.yml | 9 +++- .gitignore | 1 + xt/DepReqs.pm | 73 +++++++++++++++++++++++++++ xt/dependent-modules.t | 57 +++++++++++++++++---- 4 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 xt/DepReqs.pm diff --git a/.github/workflows/test-dependents.yml b/.github/workflows/test-dependents.yml index 0a48e482..60929e9b 100644 --- a/.github/workflows/test-dependents.yml +++ b/.github/workflows/test-dependents.yml @@ -12,8 +12,6 @@ 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 @@ -21,7 +19,14 @@ jobs: 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 diff --git a/.gitignore b/.gitignore index 6e198334..7dd668a8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /PPI-*.tar.gz /nytprof* /TODO +/xt/cpanfile diff --git a/xt/DepReqs.pm b/xt/DepReqs.pm new file mode 100644 index 00000000..72a93a3c --- /dev/null +++ b/xt/DepReqs.pm @@ -0,0 +1,73 @@ +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 run { # synch with dependent-modules.t + ## 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; } + + my @deps = Test::DependentModules::_get_deps PPI => { + exclude => 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 + )$/x + }; + + { 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"; +} diff --git a/xt/dependent-modules.t b/xt/dependent-modules.t index 581f7aa8..77249fdc 100644 --- a/xt/dependent-modules.t +++ b/xt/dependent-modules.t @@ -1,16 +1,51 @@ -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'); +# synch with DepReqs.pm -SKIP: { - skip '$ENV{TEST_DEPENDENTS} not set', scalar @modules - unless $ENV{TEST_DEPENDENTS}; - test_modules(@modules); +skip_all "ENV var TEST_DEPENDENTS not set" if not $ENV{TEST_DEPENDENTS}; -} +# 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; } -done_testing(); +# 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; } + +test_all_dependents PPI => { + exclude => 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 + )$/x +}; + +my $error_log = join "\n", @error_log; +my @fails = $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;