Skip to content

Commit

Permalink
Fix the test suite up.
Browse files Browse the repository at this point in the history
- Update several tests in t/ to use proper temporary files.
  This allows multiple tests to run at once and not collide with
  already created temp files. Many failures were caused by this.
- Added the 00-report-prereqs.t test to show the prereqs
- Added several xt/author tests to help find errors in the build.
- Updated the manifest accordingly.
- Updated the Makefile.PL to contain all of the prereqs.
  • Loading branch information
genio committed Sep 28, 2018
1 parent 4d04e8d commit 33b69d3
Show file tree
Hide file tree
Showing 18 changed files with 628 additions and 256 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Revision history File::Slurp
- Update t/data_list.t
- Update t/data_scalar.t
- Update t/error_mode.t
- Update t/large.t
- Update t/original.t
- Update t/stringify.t
- Added t/00-report-prereqs.t
- Added more xt/author tests
- Fix all trailing whitespace in accordance with xt/author/eol.t
- Updated the Makefile.PL to get all of the prereqs in there.

9999.19 Tue Jun 7 04:06:06 EDT 2011
- Fixed use line in t/edit_file.t to import :edit first
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Makefile.PL
MANIFEST
MANIFEST.SKIP
META.yml Module meta-data (added by MakeMaker)
MYMETA.json
MYMETA.yml
README
t/00-report-prereqs.t
t/append_null.t
t/binmode.t
t/data_list.t
Expand All @@ -31,4 +34,9 @@ t/stringify.t
t/tainted.t
t/TestDriver.pm
t/write_file_win32.t
xt/author/00-compile.t
xt/author/eol.t
xt/author/pod-spell.t
xt/author/pod-syntax.t
xt/author/pod_coverage.t
xt/author/test-version.t
86 changes: 68 additions & 18 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,22 +1,72 @@
use strict ;
use strict;
use warnings;
use ExtUtils::MakeMaker;
use 5.006;

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'File::Slurp',
'LICENSE' => 'perl',
'AUTHOR' => 'Uri Guttman <[email protected]>',
'VERSION_FROM' => 'lib/File/Slurp.pm',
'ABSTRACT_FROM' => 'lib/File/Slurp.pm',
'META_MERGE' => {
requires => {
perl => 5.004,
},
},
'PREREQ_PM' => {
'Carp' => 0,
'Exporter' => 0,
'Fcntl' => 0,
'POSIX' => 0,
},

my %BuildReqs = (
"ExtUtils::MakeMaker" => 0,
);
my %ConfigReqs = (
"ExtUtils::MakeMaker" => 0,
);
my %DevReqs = (
"Test::Pod" => 0,
"Test::Pod::Coverage" => 0,
);
my %TestReqs = (
"overload" => 0,
"strict" => 0,
"warnings" => 0,
"B" => 0,
"Carp" => 0,
'Exporter' => 0,
"File::Spec" => 0,
"File::Temp" => 0,
"IO::Handle" => 0,
"POSIX" => 0,
"Scalar::Util" => 0,
"Socket" => 0,
"Symbol" => 0,
"Test::More" => 0,
);
my %prereqs = (
'B' => 0,
'Carp' => 0,
'Exporter' => 0,
'Errno' => 0,
'Fcntl' => 0,
'POSIX' => 0,
"strict" => 0,
"warnings" => 0,
);

my %WriteMakefileArgs = (
'NAME' => 'File::Slurp',
"DISTNAME" => "File-Slurp",
'LICENSE' => 'perl',
'AUTHOR' => 'Uri Guttman <[email protected]>',
'VERSION_FROM' => 'lib/File/Slurp.pm',
'ABSTRACT_FROM' => 'lib/File/Slurp.pm',
"BUILD_REQUIRES" => \%BuildReqs,
"CONFIGURE_REQUIRES" => \%ConfigReqs,
"TEST_REQUIRES" => \%TestReqs,
"PREREQ_PM" => \%prereqs,
"test" => {
"TESTS" => "t/*.t",
},
);

unless ( eval { ExtUtils::MakeMaker->VERSION('6.63_03') } ) {
my %fallback = (%prereqs, %TestReqs, %ConfigReqs, %BuildReqs);
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%fallback;
}

delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION('6.52') };

WriteMakefile(%WriteMakefileArgs);
2 changes: 0 additions & 2 deletions lib/File/Slurp.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package File::Slurp;

use 5.006002 ;

use strict;
use warnings ;

Expand Down
193 changes: 193 additions & 0 deletions t/00-report-prereqs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#!perl

use strict;
use warnings;

# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027

use Test::More tests => 1;

use ExtUtils::MakeMaker;
use File::Spec;

# from $version::LAX
my $lax_version_re =
qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )?
|
(?:\.[0-9]+) (?:_[0-9]+)?
) | (?:
v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?
|
(?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?
)
)/x;

# hide optional CPAN::Meta modules from prereq scanner
# and check if they are available
my $cpan_meta = "CPAN::Meta";
my $cpan_meta_pre = "CPAN::Meta::Prereqs";
my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic

# Verify requirements?
my $DO_VERIFY_PREREQS = 1;

sub _max {
my $max = shift;
$max = ( $_ > $max ) ? $_ : $max for @_;
return $max;
}

sub _merge_prereqs {
my ($collector, $prereqs) = @_;

# CPAN::Meta::Prereqs object
if (ref $collector eq $cpan_meta_pre) {
return $collector->with_merged_prereqs(
CPAN::Meta::Prereqs->new( $prereqs )
);
}

# Raw hashrefs
for my $phase ( keys %$prereqs ) {
for my $type ( keys %{ $prereqs->{$phase} } ) {
for my $module ( keys %{ $prereqs->{$phase}{$type} } ) {
$collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module};
}
}
}

return $collector;
}

my @include = qw(
);

my @exclude = qw(
);

# Add static prereqs to the included modules list
my $static_prereqs = do './t/00-report-prereqs.dd';

# Merge all prereqs (either with ::Prereqs or a hashref)
my $full_prereqs = _merge_prereqs(
( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ),
$static_prereqs
);

# Add dynamic prereqs to the included modules list (if we can)
my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
my $cpan_meta_error;
if ( $source && $HAS_CPAN_META
&& (my $meta = eval { CPAN::Meta->load_file($source) } )
) {
$full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
}
else {
$cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source)
$source = 'static metadata';
}

my @full_reports;
my @dep_errors;
my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;

# Add static includes into a fake section
for my $mod (@include) {
$req_hash->{other}{modules}{$mod} = 0;
}

for my $phase ( qw(configure build test runtime develop other) ) {
next unless $req_hash->{$phase};
next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});

for my $type ( qw(requires recommends suggests conflicts modules) ) {
next unless $req_hash->{$phase}{$type};

my $title = ucfirst($phase).' '.ucfirst($type);
my @reports = [qw/Module Want Have/];

for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) {
next if $mod eq 'perl';
next if grep { $_ eq $mod } @exclude;

my $file = $mod;
$file =~ s{::}{/}g;
$file .= ".pm";
my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;

my $want = $req_hash->{$phase}{$type}{$mod};
$want = "undef" unless defined $want;
$want = "any" if !$want && $want == 0;

my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";

if ($prefix) {
my $have = MM->parse_version( File::Spec->catfile($prefix, $file) );
$have = "undef" unless defined $have;
push @reports, [$mod, $want, $have];

if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
if ( $have !~ /\A$lax_version_re\z/ ) {
push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
}
elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) {
push @dep_errors, "$mod version '$have' is not in required range '$want'";
}
}
}
else {
push @reports, [$mod, $want, "missing"];

if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
push @dep_errors, "$mod is not installed ($req_string)";
}
}
}

if ( @reports ) {
push @full_reports, "=== $title ===\n\n";

my $ml = _max( map { length $_->[0] } @reports );
my $wl = _max( map { length $_->[1] } @reports );
my $hl = _max( map { length $_->[2] } @reports );

if ($type eq 'modules') {
splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
}
else {
splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports;
}

push @full_reports, "\n";
}
}
}

if ( @full_reports ) {
diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
}

if ( $cpan_meta_error || @dep_errors ) {
diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n";
}

if ( $cpan_meta_error ) {
my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n";
}

if ( @dep_errors ) {
diag join("\n",
"\nThe following REQUIRED prerequisites were not satisfied:\n",
@dep_errors,
"\n"
);
}

pass;

# vim: ts=4 sts=4 sw=4 et:
3 changes: 1 addition & 2 deletions t/file_object.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SKIP: {
unlink $path;


# the following mimics the parts from Path::Class causing
# the following mimics the parts from Path::Class causing
# problems with File::Slurp
package FileObject;
use overload
Expand All @@ -72,4 +72,3 @@ sub new {
sub stringify {
return $_[0]->{path}
}

2 changes: 1 addition & 1 deletion t/handle.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sub test_data_slurp {

my $data_seek = tell( \*DATA );

# first slurp in the lines
# first slurp in the lines
my @slurp_lines = read_file( \*DATA ) ;

# now seek back and read all the lines with the <> op and we make
Expand Down
2 changes: 1 addition & 1 deletion t/inode.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Socket ;
use Symbol ;
use Test::More ;

BEGIN {
BEGIN {
if( $^O =~ '32' ) {
plan skip_all => 'skip inode test on windows';
exit ;
Expand Down
Loading

0 comments on commit 33b69d3

Please sign in to comment.