This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactoring the /Can't return (?:array|hash) to scalar context/ croak
[perl5.git] / lib / blib.t
CommitLineData
a635c943
MS
1#!./perl -Tw
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8use strict;
91fded41 9use File::Spec;
e69a2255 10my($blib, $blib_arch, $blib_lib, @blib_dirs);
a635c943
MS
11
12sub _cleanup {
e69a2255
JH
13 rmdir foreach reverse (@_);
14 unlink "stderr" unless $^O eq 'MacOS';
a635c943
MS
15}
16
17sub _mkdirs {
18 for my $dir (@_) {
19 next if -d $dir;
20 mkdir $dir or die "Can't mkdir $dir: $!" if ! -d $dir;
21 }
22}
23
24
e69a2255
JH
25BEGIN {
26 if ($^O eq 'MacOS')
27 {
16398b42 28 $MacPerl::Architecture = $MacPerl::Architecture; # shhhhh
e69a2255
JH
29 $blib = ":blib:";
30 $blib_lib = ":blib:lib:";
31 $blib_arch = ":blib:lib:$MacPerl::Architecture:";
32 @blib_dirs = ($blib, $blib_lib, $blib_arch); # order
33 }
34 else
35 {
36 $blib = "blib";
37 $blib_arch = "blib/arch";
38 $blib_lib = "blib/lib";
39 @blib_dirs = ($blib, $blib_arch, $blib_lib);
40 }
41 _cleanup( @blib_dirs );
42}
a635c943
MS
43
44use Test::More tests => 7;
45
46eval 'use blib;';
47ok( $@ =~ /Cannot find blib/, 'Fails if blib directory not found' );
48
e69a2255 49_mkdirs( @blib_dirs );
a635c943
MS
50
51{
4940c443 52 my $warnings = '';
a635c943
MS
53 local $SIG{__WARN__} = sub { $warnings = join '', @_ };
54 use_ok('blib');
91fded41 55 is( $warnings, '', 'use blib is nice and quiet' );
a635c943
MS
56}
57
58is( @INC, 3, '@INC now has 3 elements' );
59is( $INC[2], '../lib', 'blib added to the front of @INC' );
60
bea1ee5e
CB
61if ($^O eq 'VMS') {
62 # Unix syntax is accepted going in but it's not what comes out
91fded41 63 # So we don't use catdir above
bea1ee5e
CB
64 $blib_arch = 'blib.arch]';
65 $blib_lib = 'blib.lib]';
66}
91fded41
NIS
67elsif ($^O ne 'MacOS')
68{
69 $blib_arch = File::Spec->catdir("blib","arch");
70 $blib_lib = File::Spec->catdir("blib","lib");
71}
72
73
74ok( grep(m|\Q$blib_lib\E$|, @INC[0,1]) == 1, " $blib_lib in \@INC");
75ok( grep(m|\Q$blib_arch\E$|, @INC[0,1]) == 1, " $blib_arch in \@INC");
a635c943 76
e69a2255 77END { _cleanup( @blib_dirs ); }