test to check dependents
[gitmo/Moo.git] / xt / test-my-dependents.t
CommitLineData
dcc862ca 1use Test::More;
2BEGIN {
3 plan skip_all => <<'END_HELP' unless $ENV{MOO_TEST_MD};
4This test will not run unless you set MOO_TEST_MD to a true value.
5
6 Valid values are:
7
8 all Test every dist which depends on Moose except those
9 that we know cannot be tested. This is a lot of
10 distros (hundreds).
11
12 Dist::1,Dist::2,... Test the individual dists listed.
13
14 MooX Test all Moo extension distros.
15
16 1 Run the default tests. We pick 200 random dists and
17 test them.
18END_HELP
19}
20
21use Test::DependentModules qw( test_modules );
22use MetaCPAN::API;
23use List::Util ();
24
25my $mcpan = MetaCPAN::API->new;
26my $res = $mcpan->post(
27 '/search/reverse_dependencies/Moo' => {
28 query => {
29 filtered => {
30 query => { "match_all" => {} },
31 filter => {
32 and => [
33 { term => { 'release.status' => 'latest' } },
34 { term => { 'release.authorized' => \1 } },
35 ],
36 },
37 },
38 },
39 size => 5000,
40 fields => ['distribution', 'provides'],
41 },
42);
43
44my %bad_module;
45foreach my $line (<DATA>) {
46 chomp $line;
47 if ($line =~ /^\s*(\S+)\s*(#|$)/) {
48 $bad_module{$1}++;
49 }
50 else {
51 die "Invalid entry in DATA section: $line";
52 }
53}
54
55my @modules = sort grep !/^(?:Task|Bundle|Acme)::/, grep !$bad_module{$_}, map {
56 if (my $provides = $_->{fields}{provides}) {
57 ref $provides ? (sort @$provides)[0] : $provides;
58 }
59 else {
60 my $dist = $_->{fields}{distribution};
61 $dist =~ s/-/::/g;
62 $dist;
63 }
64} @{ $res->{hits}{hits} };
65
66if ( $ENV{MOO_TEST_MD} eq 'MooX' ) {
67 @modules = grep /^MooX(?:$|::)/, @modules;
68}
69elsif ( $ENV{MOO_TEST_MD} eq '1' ) {
70 diag(<<'EOF');
71 Picking 200 random dependents to test. Set MOO_TEST_MD=all to test all
72 dependents or MOO_TEST_MD=MooX to test extension modules only.
73EOF
74 @modules = (List::Util::shuffle(@modules))[0..199];
75}
76elsif ( $ENV{MOO_TEST_MD} ne 'all' ) {
77 my @chosen = split /,/, $ENV{MOO_TEST_MD};
78 my %modules = map { $_ => 1 } @modules;
79 if (my @unknown = grep { !$modules{$_} } @chosen) {
80 die "Unknown modules: @unknown";
81 }
82 @modules = @chosen;
83}
84
85plan tests => scalar @modules;
86test_modules(@modules);
87
88__DATA__
89# broken
90