~ubuntu-branches/ubuntu/trusty/libtest-roo-perl/trusty-proposed

« back to all changes in this revision

Viewing changes to t/00-report-prereqs.t

  • Committer: Package Import Robot
  • Author(s): gregor herrmann
  • Date: 2014-01-14 19:25:11 UTC
  • Revision ID: package-import@ubuntu.com-20140114192511-9ycl4dc1zgamfnek
Tags: upstream-1.002
ImportĀ upstreamĀ versionĀ 1.002

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
use Test::More tests => 1;
 
7
 
 
8
use ExtUtils::MakeMaker;
 
9
use File::Spec::Functions;
 
10
use List::Util qw/max/;
 
11
 
 
12
my @modules = qw(
 
13
  Capture::Tiny
 
14
  ExtUtils::MakeMaker
 
15
  File::Spec
 
16
  File::Spec::Functions
 
17
  File::Temp
 
18
  IO::Handle
 
19
  IPC::Open3
 
20
  List::Util
 
21
  Moo
 
22
  MooX::Types::MooseLike::Base
 
23
  Sub::Install
 
24
  Test::More
 
25
  bareword::filehandles
 
26
  indirect
 
27
  lib
 
28
  multidimensional
 
29
  perl
 
30
  strict
 
31
  strictures
 
32
  warnings
 
33
);
 
34
 
 
35
# replace modules with dynamic results from MYMETA.json if we can
 
36
# (hide CPAN::Meta from prereq scanner)
 
37
my $cpan_meta = "CPAN::Meta";
 
38
if ( -f "MYMETA.json" && eval "require $cpan_meta" ) { ## no critic
 
39
  if ( my $meta = eval { CPAN::Meta->load_file("MYMETA.json") } ) {
 
40
    my $prereqs = $meta->prereqs;
 
41
    delete $prereqs->{develop};
 
42
    my %uniq = map {$_ => 1} map { keys %$_ } map { values %$_ } values %$prereqs;
 
43
    $uniq{$_} = 1 for @modules; # don't lose any static ones
 
44
    @modules = sort keys %uniq;
 
45
  }
 
46
}
 
47
 
 
48
my @reports = [qw/Version Module/];
 
49
 
 
50
for my $mod ( @modules ) {
 
51
  next if $mod eq 'perl';
 
52
  my $file = $mod;
 
53
  $file =~ s{::}{/}g;
 
54
  $file .= ".pm";
 
55
  my ($prefix) = grep { -e catfile($_, $file) } @INC;
 
56
  if ( $prefix ) {
 
57
    my $ver = MM->parse_version( catfile($prefix, $file) );
 
58
    $ver = "undef" unless defined $ver; # Newer MM should do this anyway
 
59
    push @reports, [$ver, $mod];
 
60
  }
 
61
  else {
 
62
    push @reports, ["missing", $mod];
 
63
  }
 
64
}
 
65
 
 
66
if ( @reports ) {
 
67
  my $vl = max map { length $_->[0] } @reports;
 
68
  my $ml = max map { length $_->[1] } @reports;
 
69
  splice @reports, 1, 0, ["-" x $vl, "-" x $ml];
 
70
  diag "Prerequisite Report:\n", map {sprintf("  %*s %*s\n",$vl,$_->[0],-$ml,$_->[1])} @reports;
 
71
}
 
72
 
 
73
pass;
 
74
 
 
75
# vim: ts=2 sts=2 sw=2 et: