}
},
+ # must list any dep used by adhoc testing
+ # this prevents the "skips due to forgotten deps" issue
+ test_adhoc => {
+ req => {
+ 'Date::Simple' => '3.03',
+ 'YAML' => '0',
+ 'Class::Unload' => '0.07',
+ },
+ },
+
replicated => {
req => $moose_basic,
pod => {
},
},
- test_component_accessor => {
- req => {
- 'Class::Unload' => '0.07',
- },
- },
-
test_pod => {
req => {
'Test::Pod' => '1.42',
req => {
'Class::DBI::Plugin::DeepAbstractSearch' => '0',
'Time::Piece::MySQL' => '0',
- 'Date::Simple' => '3.03',
},
},
;
}
+my $tb;
+sub skip_without {
+ my ($self, $groups) = @_;
+
+ $tb ||= do { local $@; eval { Test::Builder->new } }
+ or croak "Calling skip_without() before loading Test::Builder makes no sense";
+
+ if ( my $err = $self->req_missing_for($groups) ) {
+ my ($fn, $ln) = (caller(0))[1,2];
+ $tb->skip("block in $fn around line $ln requires $err");
+ local $^W = 0;
+ last SKIP;
+ }
+
+ 1;
+}
+
sub die_unless_req_ok_for {
if (my $err = shift->req_missing_for(shift) ) {
die "Unable to continue due to missing requirements: $err\n";
join '/', @res;
}
+my $groupname_re = qr/ [A-Z_a-z][0-9A-Z_a-z]* /x;
+my $modname_re = qr/ [A-Z_a-z] [0-9A-Z_a-z]* (?:::[0-9A-Z_a-z]+)* /x;
+my $modver_re = qr/ [0-9]+ (?: \. [0-9]+ )? /x;
+
# Expand includes from a random group in a specific order:
# nonvariable groups first, then their includes, then the variable groups,
# then their includes.
for my $g (@$groups) {
croak "Invalid requirement group name '$g': only ascii alphanumerics and _ are allowed"
- if $g !~ /\A [A-Z_a-z][0-9A-Z_a-z]* \z/x;
+ if $g !~ qr/ \A $groupname_re \z/x;
my $r = $dbic_reqs->{$g}
or croak "Requirement group '$g' is not defined";
# this method is just a lister and envvar/metadata checker - it does not try to load anything
sub _groups_to_reqs {
- my ($self, $groups) = @_;
+ my ($self, $want) = @_;
- $groups = [ $groups || () ]
- unless ref $groups eq 'ARRAY';
+ $want = [ $want || () ]
+ unless ref $want eq 'ARRAY';
croak "@{[ (caller(1))[3] ]}() expects a requirement group name or arrayref of group names"
- unless @$groups;
+ unless @$want;
my $ret = {
modreqs => {},
modreqs_fully_documented => 1,
};
+ my $groups;
+ for my $piece (@$want) {
+ if ($piece =~ qr/ \A $groupname_re \z /x) {
+ push @$groups, $piece;
+ }
+ elsif ( my ($mod, $ver) = $piece =~ qr/ \A ($modname_re) \>\= ($modver_re) \z /x ) {
+ croak "Ad hoc module specification lists '$mod' twice"
+ if exists $ret->{modreqs}{$mod};
+
+ croak "Ad hoc module specification '${mod} >= $ver' (or greater) not listed in the test_adhoc optdep group" if (
+ ! defined $dbic_reqs->{test_adhoc}{req}{$mod}
+ or
+ $dbic_reqs->{test_adhoc}{req}{$mod} < $ver
+ );
+
+ $ret->{modreqs}{$mod} = $ver;
+ $ret->{modreqs_fully_documented} = 0;
+ }
+ else {
+ croak "Unsupported argument '$piece' supplied to @{[ (caller(1))[3] ]}()"
+ }
+ }
+
my $all_groups = __expand_includes($groups);
# pre-assemble list of augmentations, perform basic sanity checks
for my $req_bag ($group_reqs, @{ $augmentations->{$group} || [] } ) {
for (keys %$req_bag) {
- $_ =~ /\A [A-Z_a-z][0-9A-Z_a-z]* (?:::[0-9A-Z_a-z]+)* \z /x
+ $_ =~ / \A $modname_re \z /x
or croak "Requirement '$_' in group '$group' is not a valid module name";
# !!!DO NOT CHANGE!!!
# remember - version.pm may not be available on the system
croak "Requirement '$_' in group '$group' specifies an invalid version '$req_bag->{$_}' (only plain non-underscored floating point decimals are supported)"
- if ( ($req_bag->{$_}||0) !~ / \A [0-9]+ (?: \. [0-9]+ )? \z /x );
+ if ( ($req_bag->{$_}||0) !~ qr/ \A $modver_re \z /x );
}
}
See also L</-list_missing>.
+=head2 skip_without
+
+=over
+
+=item Arguments: $group_name | \@group_names
+
+=back
+
+A convenience wrapper around L<skip|Test::More/SKIP>. It does not take neither
+a reason (it is generated by L</req_missing_for>) nor an amount of skipped tests
+(it is always C<1>, thus mandating unconditional use of
+L<done_testing|Test::More/done_testing>). Most useful in combination with ad hoc
+requirement specifications:
+EOC
+
+ push @chunks, <<EOC;
+ SKIP: {
+ $class->skip_without([ deploy YAML>=0.90 ]);
+
+ ...
+ }
+EOC
+
+ push @chunks, <<'EOC';
+
=head2 die_unless_req_ok_for
=over