Alien-Build
view release on metacpan or search on metacpan
t/alien_build_plugin_probe_commandline.t view on Meta::CPAN
$ret;
}
sub build
{
my $build = alienfile_ok q{ use alienfile };
my $meta = $build->meta;
if(ref $_[-1] eq 'CODE')
{
my $code = pop;
$code->($build, $meta);
}
my $plugin = Alien::Build::Plugin::Probe::CommandLine->new(@_);
$plugin->init($meta);
($build, $plugin, $meta);
}
subtest 'basic existence' => sub {
my $guard = system_fake
'foo' => sub { return 0 },
;
subtest 'it is there' => sub {
my($build) = build('foo');
is cap { $build->probe }, 'system', 'is system';
};
subtest 'it is not there' => sub {
my($build) = build('bar');
is cap { $build->probe }, 'share', 'is share';
};
};
subtest 'args' => sub {
my $called = 0;
my @args;
my $guard = system_fake
'foo' => sub { $called = 1; @args = @_; return 0 },
;
my($build) = build(command => 'foo', args => [1,2,3], match => qr// );
is cap { $build->probe }, 'system', 'is system';
is $called, 1, 'was called';
is \@args, [1,2,3], 'args are passed in';
};
subtest 'secondary' => sub {
my $lib = 0;
my $run = 0;
my $guard = system_fake
'foo' => sub { $run = 1; return 0 },
;
subtest 'libs + command okay' => sub {
$lib = 0;
$run = 0;
my($build) = build(command => 'foo', secondary => 1, match => qr//, sub {
my($build, $meta) = @_;
$meta->register_hook(probe => sub {
$lib = 1;
'system';
});
});
is(cap { $build->probe }, 'system');
is $run, 1, 'run';
is $lib, 1, 'lib';
};
subtest 'libs ok + command bad' => sub {
$lib = 0;
$run = 0;
my($build) = build(command => 'bar', secondary => 1, match => qr//, sub {
my($build, $meta) = @_;
$meta->register_hook(probe => sub {
$lib = 1;
'system';
});
});
is(cap { $build->probe }, 'share');
is $lib, 1, 'lib';
};
subtest 'libs bad + command okay' => sub {
$lib = 0;
$run = 0;
my($build) = build(command => 'foo', secondary => 1, match => qr//, sub {
my($build, $meta) = @_;
$meta->register_hook(probe => sub {
$lib = 1;
'share';
});
});
is(cap { $build->probe }, 'share');
is $run, 0, 'run';
is $lib, 1, 'lib';
};
subtest 'libs bad + command bad' => sub {
$lib = 0;
$run = 0;
my($build) = build(command => 'bar', secondary => 1, match => qr//, sub {
my($build, $meta) = @_;
$meta->register_hook(probe => sub {
$lib = 1;
'share';
});
});
is(cap { $build->probe }, 'share');
is $run, 0, 'run';
is $lib, 1, 'lib';
};
};
subtest 'match + version' => sub {
my $guard = system_fake
'foo' => sub { print "Froodle Foomaker version 1.00\n"; return 0 },
;
subtest 'match good' => sub {
my($build) = build(command => 'foo', match => qr/Froodle/);
is cap { $build->probe }, 'system';
};
subtest 'match bad' => sub {
my($build) = build(command => 'foo', match => qr/Droodle/);
is cap { $build->probe }, 'share';
};
subtest 'version found' => sub {
my($build) = build(command => 'foo', version => qr/version ([0-9\.]+)/);
is cap { $build->probe }, 'system';
is $build->runtime_prop->{version}, '1.00';
};
subtest 'version unfound' => sub {
my($build) = build(command => 'foo', version => qr/version = ([0-9\.]+)/);
is cap { $build->probe }, 'system';
is $build->runtime_prop->{version}, undef;
};
subtest 'atleast_version satisfied' => sub {
my($build) = build(
command => 'foo',
version => qr/version ([0-9\.]+)/,
atleast_version => '0.5.0'
);
is cap { $build->probe }, 'system';
is $build->runtime_prop->{version}, '1.00';
};
subtest 'atleast_version not satisfied' => sub {
my($build) = build(
command => 'foo',
version => qr/version ([0-9\.]+)/,
atleast_version => '1.5.0'
);
is cap { $build->probe }, 'share';
( run in 0.880 second using v1.01-cache-2.11-cpan-39bf76dae61 )