summaryrefslogtreecommitdiff
path: root/dist/lib/t
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-09-28 15:11:36 +0100
committerNicholas Clark <nick@ccl4.org>2009-09-29 11:12:38 +0100
commit88697c04890059636ae16bf315df6e3817777136 (patch)
tree934b1dd33646044c93489c83bdb7828ce9b56a56 /dist/lib/t
parent725607636edc598ad6823e49789420d734f8aa28 (diff)
downloadperl-88697c04890059636ae16bf315df6e3817777136.tar.gz
Move lib from ext/ to dist/
Diffstat (limited to 'dist/lib/t')
-rw-r--r--dist/lib/t/01lib.t81
1 files changed, 81 insertions, 0 deletions
diff --git a/dist/lib/t/01lib.t b/dist/lib/t/01lib.t
new file mode 100644
index 0000000000..d39a656bf8
--- /dev/null
+++ b/dist/lib/t/01lib.t
@@ -0,0 +1,81 @@
+#!./perl -w
+
+BEGIN {
+ chdir 't';
+ unshift @INC, '..';
+ unshift @INC, '../lib';
+ @OrigINC = @INC;
+}
+
+use Test::More tests => 13;
+use Config;
+use File::Spec;
+use File::Path;
+
+#set up files and directories
+my @lib_dir;
+my $Lib_Dir;
+my $Arch_Dir;
+my $Auto_Dir;
+my $Module;
+BEGIN {
+ # lib.pm is documented to only work with Unix filepaths.
+ @lib_dir = qw(stuff moo);
+ $Lib_Dir = join "/", @lib_dir;
+ $Arch_Dir = join "/", @lib_dir, $Config{archname};
+
+ # create the auto/ directory and a module
+ $Auto_Dir = File::Spec->catdir(@lib_dir, $Config{archname},'auto');
+ $Module = File::Spec->catfile(@lib_dir, 'Yup.pm');
+
+ mkpath [$Auto_Dir];
+
+ open(MOD, ">$Module") || DIE $!;
+ print MOD <<'MODULE';
+package Yup;
+$Plan = 9;
+return '42';
+MODULE
+
+ close MOD;
+}
+
+END {
+ # cleanup the auto/ directory we created.
+ rmtree([$lib_dir[0]]);
+}
+
+
+use lib $Lib_Dir;
+use lib $Lib_Dir;
+
+BEGIN { use_ok('Yup') }
+
+BEGIN {
+ is( $INC[1], $Lib_Dir, 'lib adding at end of @INC' );
+ print "# \@INC == @INC\n";
+ is( $INC[0], $Arch_Dir, ' auto/ dir in front of that' );
+ is( grep(/^\Q$Lib_Dir\E$/, @INC), 1, ' no duplicates' );
+
+ # Yes, %INC uses Unixy filepaths.
+ # Not on Mac OS, it doesn't ... it never has, at least.
+ my $path = join("/",$Lib_Dir, 'Yup.pm');
+ is( $INC{'Yup.pm'}, $path, '%INC set properly' );
+
+ is( eval { do 'Yup.pm' }, 42, 'do() works' );
+ ok( eval { require Yup; }, ' require()' );
+ ok( eval "use Yup; 1;", ' use()' );
+ is( $@, '' );
+
+ is_deeply(\@OrigINC, \@lib::ORIG_INC, '@lib::ORIG_INC' );
+}
+
+no lib $Lib_Dir;
+
+unlike( do { eval 'use lib $Config{installsitelib};'; $@ || '' },
+ qr/::Config is read-only/, 'lib handles readonly stuff' );
+
+BEGIN {
+ is( grep(/stuff/, @INC), 0, 'no lib' );
+ ok( !do 'Yup.pm', ' do() effected' );
+}