Skip to content

Commit

Permalink
Make Test::JMM, and use it in the tests, for extra funky stuff
Browse files Browse the repository at this point in the history
 - $ENV{TRACK_MODULES}, to show me what my dependencies should be.
 - $ENV{TEST_JMM_HAS_C3} / _MOOSE ==0, to test the case where
   C3 or Moose isn't installed, without actually removing them.
  • Loading branch information
theorbtwo committed Jul 8, 2009
1 parent ee6ca52 commit 414ca0d
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 8 deletions.
2 changes: 2 additions & 0 deletions t/01kwalitee.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/perl
use lib 't/auxlib';
use Test::JMM;
use warnings;
use strict;
use Test::More;
Expand Down
13 changes: 6 additions & 7 deletions t/02base.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/perl
use lib 't/auxlib';
use Test::JMM;
use Test::More tests => 7;
use Test::NoWarnings;
use Test::Exception;
use Test::Differences;
use lib 't/lib';
use lib 't/auxlib';

use_ok('Pod::Inherit');

Expand All @@ -23,10 +24,8 @@ $pi_override->write_pod;
ok(!-e 't/lib/OverrideSubClass.pod', "Doesn't produce unneeded pod for completely overridden base class");


my ($skip_moose, $skip_classc3);
eval "require Moose";

if(!$@) {
SKIP: {
skip "Moose not installed", 1 unless Test::JMM::has_moose;
my $pi_moose = Pod::Inherit->new({ input_files => [ 't/auxlib/MooseSub.pm' ] });
$pi_moose->write_pod;
my $output = do { local (@ARGV, $/) = "t/auxlib/MooseSub.pod"; <> || 'NO OUTPUT' };
Expand All @@ -38,8 +37,8 @@ if(!$@) {
# ok(!-e 't/lib/MooseSub.pod', "Moose extends, existing POD");
}

eval "require Class::C3";
if(!$@) {
SKIP: {
skip "Class::C3 not installed", 1 unless Test::JMM::has_c3;
my $pi_c3 = Pod::Inherit->new({ input_files => [ 't/auxlib/ClassC3Sub.pm' ] });
$pi_c3->write_pod;
eq_or_diff(
Expand Down
2 changes: 2 additions & 0 deletions t/03pod-coverage.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/perl
use lib 't/auxlib';
use Test::JMM;
use warnings;
use strict;
use Test::Pod::Coverage tests=>2;
Expand Down
2 changes: 2 additions & 0 deletions t/03pod.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/perl
use lib 't/auxlib';
use Test::JMM;
use warnings;
use strict;
use Test::More;
Expand Down
3 changes: 2 additions & 1 deletion t/04files.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/perl

use lib 't/auxlib';
use Test::JMM;
use Test::More 'no_plan';
use Test::Differences;
use Test::Pod;
Expand Down
2 changes: 2 additions & 0 deletions t/05not_ours.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/perl
use lib 't/auxlib';
use Test::JMM;
use warnings;
use strict;
use Pod::Inherit;
Expand Down
2 changes: 2 additions & 0 deletions t/06dir.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/perl
use lib 't/auxlib';
use Test::JMM;
use Test::More 'no_plan';
use Test::Differences;
use Test::Pod;
Expand Down
63 changes: 63 additions & 0 deletions t/auxlib/Test/JMM.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package Test::JMM;
use warnings;
use strict;
use Module::CoreList;

sub has_module {
# Modname is the actual name of the module: Class::C3.
# Shortname is what gets stuck in env vars: C3.
my ($modname, $shortname) = @_;
$shortname ||= $modname;
my $envvar = "TEST_JMM_HAS_".uc($shortname);
if (exists $ENV{$envvar}) {
return $ENV{$envvar};
}
if (eval "require $modname; 1") {
return 1;
} else {
return 0;
}
}

sub has_moose {
has_module('Moose');
}

sub has_c3 {
has_module('Class::C3', 'C3');
}

sub import {
if ($ENV{TRACK_MODULES}) {
print STDERR "# Doing Test::JMM::import\n";
unshift @INC, sub {
my ($self, $mod_as_filename) = @_;
my $modname = $mod_as_filename;
$modname =~ s!/!::!g;
$modname =~ s/\.pm$//;
my $filename = (caller)[1];
my $line = (caller)[2];
my $kind;
if ($filename =~ m/\bblib\b/) {
$kind = 'runtime';
#print STDERR "# In blib -- assuming runtime dependency of thing under test\n";
} elsif ($filename =~ m!^t\b!) {
$kind = 'test';
#print STDERR "# In t/ -- assuming testing dependency.\n";
} else {
return;
}
my $first_rel = Module::CoreList->first_release($modname);
if ($first_rel and $first_rel <= 5.006) {
print STDERR "# (Is core as of $first_rel)\n";
return ();
}
# print STDERR "# Attempting to find $mod_as_filename from $filename line $line for $kind\n";
print STDERR "# INC hook: $kind: $mod_as_filename for $kind\n";
return ();
}
}
}

1;

0 comments on commit 414ca0d

Please sign in to comment.