Add ExtUtils::Miniperl to the list of core modules for all versions >= 5.00504
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / tilde.t
CommitLineData
bb4e9162 1#!/usr/bin/perl -w
2
3# Test ~ expansion from command line arguments.
4
5use strict;
6use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
15cb7b9d 7use MBTest tests => 18;
738349a8 8
9use_ok 'Module::Build';
10ensure_blib('Module::Build');
bb4e9162 11
7a827510 12my $tmp = MBTest->tmpdir;
bb4e9162 13
14use DistGen;
15my $dist = DistGen->new( dir => $tmp );
16$dist->regen;
17
738349a8 18$dist->chdir_in;
bb4e9162 19
bb4e9162 20
21sub run_sample {
22 my @args = @_;
23
24 local $Test::Builder::Level = $Test::Builder::Level + 1;
25
26 $dist->clean;
27
28 my $mb;
29 stdout_of( sub {
30 $mb = Module::Build->new_from_context( @args );
31 } );
32
33 return $mb;
34}
35
36
7a827510 37my $p = 'install_base';
bb4e9162 38
7a827510 39SKIP: {
40 my $home = $ENV{HOME} ? $ENV{HOME} : undef;
738349a8 41
42 if ($^O eq 'VMS') {
43 # Convert the path to UNIX format, trim off the trailing slash
44 $home = VMS::Filespec::unixify($home);
45 $home =~ s#/$##;
46 }
47
7a827510 48 unless (defined $home) {
49 my @info = eval { getpwuid $> };
15cb7b9d 50 skip "No home directory for tilde-expansion tests", 15 if $@;
7a827510 51 $home = $info[7];
52 }
bb4e9162 53
7a827510 54 is( run_sample( $p => '~' )->$p(), $home );
c1d8f74e 55
7a827510 56 is( run_sample( $p => '~/foo' )->$p(), "$home/foo" );
c1d8f74e 57
7a827510 58 is( run_sample( $p => '~~' )->$p(), '~~' );
c1d8f74e 59
7a827510 60 is( run_sample( $p => '~ foo' )->$p(), '~ foo' );
c1d8f74e 61
7a827510 62 is( run_sample( $p => '~/ foo')->$p(), "$home/ foo" );
63
64 is( run_sample( $p => '~/fo o')->$p(), "$home/fo o" );
c1d8f74e 65
7a827510 66 is( run_sample( $p => 'foo~' )->$p(), 'foo~' );
bb4e9162 67
7a827510 68 is( run_sample( prefix => '~' )->prefix,
69 $home );
bb4e9162 70
15cb7b9d 71 # Test when HOME is different from getpwuid(), as in sudo.
72 {
73 local $ENV{HOME} = '/wibble/whomp';
74
75 is( run_sample( $p => '~' )->$p(), "/wibble/whomp" );
76 }
77
7a827510 78 my $mb = run_sample( install_path => { html => '~/html',
79 lib => '~/lib' }
80 );
81 is( $mb->install_destination('lib'), "$home/lib" );
bb4e9162 82 # 'html' is translated to 'binhtml' & 'libhtml'
7a827510 83 is( $mb->install_destination('binhtml'), "$home/html" );
84 is( $mb->install_destination('libhtml'), "$home/html" );
bb4e9162 85
86 $mb = run_sample( install_path => { lib => '~/lib' } );
7a827510 87 is( $mb->install_destination('lib'), "$home/lib" );
bb4e9162 88
89 $mb = run_sample( destdir => '~' );
7a827510 90 is( $mb->destdir, $home );
91
92 $mb->$p('~');
93 is( $mb->$p(), '~', 'API does not expand tildes' );
94}
bb4e9162 95
7a827510 96# Again, with named users
97SKIP: {
98 my @info = eval { getpwuid $> };
99 skip "No home directory for tilde-expansion tests", 1 if $@;
100 my ($me, $home) = @info[0,7];
101
738349a8 102 my $expected = "$home/foo";
103
104 if ($^O eq 'VMS') {
105 # Convert the path to UNIX format and trim off the trailing slash
106 $home = VMS::Filespec::unixify($home);
107 $home =~ s#/$##;
108 $expected = $home . '/../[^/]+' . '/foo';
109 }
110
111 like( run_sample( $p => "~$me/foo")->$p(), qr($expected)i );
bb4e9162 112}
113
114
115# cleanup
bb4e9162 116$dist->remove;