Permalink
Browse files

Initial implementation

  • Loading branch information...
1 parent bd0c532 commit 3171778e8a60ab426eaf84f0b4c9126f1b2193eb @Leont committed Oct 16, 2011
Showing with 77 additions and 9 deletions.
  1. +1 −1 .gitignore
  2. +2 −2 Changes
  3. +1 −1 dist.ini
  4. +0 −5 lib/Test/AssureDeps.pm
  5. +61 −0 lib/Test/CheckDeps.pm
  6. +12 −0 t/00-basics.t
View
@@ -4,4 +4,4 @@
*.swo
*.tdy
*.tar.gz
-Test-AssureDeps-*
+Test-CheckDeps-*
View
@@ -1,4 +1,4 @@
-Revision history for Test-AssureDeps
+Revision history for Test-CheckDeps
{{$NEXT}}
- -
+ Initial release
View
@@ -1,4 +1,4 @@
-name = Test-AssureDeps
+name = Test-CheckDeps
author = Leon Timmermans <leont@cpan.org>
license = Perl_5
copyright_holder = Leon Timmermans
@@ -1,5 +0,0 @@
-package Test::AssureDeps;
-use strict;
-use warnings;
-
-1;
View
@@ -0,0 +1,61 @@
+package Test::CheckDeps;
+use strict;
+use warnings FATAL => 'all';
+
+use Exporter 5.57 'import';
+our @EXPORT = qw/check_dependencies/;
+our @EXPORT_OK = qw/check_dependencies_opts/;
+our %EXPORT_TAGS = (all => [ @EXPORT, @EXPORT_OK ] );
+
+use CPAN::Meta;
+use List::Util qw/first/;
+use Module::Metadata;
+use Test::More;
+
+sub check_dependencies {
+ my $metafile = first { -e $_ } qw/MYMETA.json MYMETA.yml META.json META.yml/ or return fail("No META information provided\n");
+ my $meta = CPAN::Meta->load_file($metafile);
+ check_dependencies_opts($meta, $_, 'requires') for qw/configure build test runtime/;
+ return;
+}
+
+sub check_dependencies_opts {
+ my ($meta, $phase, $type) = @_;
+
+ my $reqs = $meta->effective_prereqs->requirements_for($phase, $type);
+ for my $module ($reqs->required_modules) {
+ my $version;
+ if ($module eq 'perl') {
+ $version = $];
+ }
+ else {
+ my $metadata = Module::Metadata->new_from_module($module);
+ fail("Module '$module' is not installed"), next if not defined $metadata;
+ $version = eval { $metadata->version };
+ }
+ fail("Missing version info for module '$module'"), next if not $version;
+ fail(sprintf 'Version %s of module %s is not in range \'%s\'', $version, $module, $reqs->as_string_hash->{$module}), next if not $reqs->accepts_module($module, $version);
+ pass("$module $version is present");
+ }
+ return;
+}
+
+1;
+
+__END__
+
+#ABSTRACT: Check for presence of dependencies
+
+=head1 DESCRIPTION
+
+This module adds a test that assures all dependencies have been installed properly. If requested, it can bail out all testing on error.
+
+=func check_dependencies()
+
+Check all 'requires' dependencies based on a local MYMETA or META file.
+
+=func check_dependencies_opts($meta, $phase, $type)
+
+Check dependencies in L<CPAN::Meta> object $meta for phase C<$phase> (configure, build, test, runtime, develop) and type C<$type>(requires, recommends, suggests, conflicts). You probably just want to use C<check_dependencies> though.
+
+=cut
View
@@ -0,0 +1,12 @@
+#! perl
+
+use strict;
+use warnings;
+
+use Test::More 0.88;
+
+use Test::CheckDeps;
+
+check_dependencies();
+
+done_testing;

0 comments on commit 3171778

Please sign in to comment.