Upgrade to Module-Build-0.30
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / tilde.t
1 #!/usr/bin/perl -w
2
3 # Test ~ expansion from command line arguments.
4
5 use strict;
6 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
7 use MBTest tests => 17;
8
9 use_ok 'Module::Build';
10 ensure_blib('Module::Build');
11
12 my $tmp = MBTest->tmpdir;
13
14 use DistGen;
15 my $dist = DistGen->new( dir => $tmp );
16 $dist->regen;
17
18 $dist->chdir_in;
19
20
21 sub 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
37 my $p = 'install_base';
38
39 SKIP: {
40     my $home = $ENV{HOME} ? $ENV{HOME} : undef;
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
48     unless (defined $home) {
49       my @info = eval { getpwuid $> };
50       skip "No home directory for tilde-expansion tests", 14 if $@;
51       $home = $info[7];
52     }
53
54     is( run_sample( $p => '~'     )->$p(),  $home );
55
56     is( run_sample( $p => '~/foo' )->$p(),  "$home/foo" );
57
58     is( run_sample( $p => '~~'    )->$p(),  '~~' );
59
60     is( run_sample( $p => '~ foo' )->$p(),  '~ foo' );
61
62     is( run_sample( $p => '~/ foo')->$p(),  "$home/ foo" );
63       
64     is( run_sample( $p => '~/fo o')->$p(),  "$home/fo o" );
65
66     is( run_sample( $p => 'foo~'  )->$p(),  'foo~' );
67
68     is( run_sample( prefix => '~' )->prefix,
69         $home );
70
71     my $mb = run_sample( install_path => { html => '~/html',
72                                            lib  => '~/lib'   }
73                        );
74     is( $mb->install_destination('lib'),  "$home/lib" );
75     # 'html' is translated to 'binhtml' & 'libhtml'
76     is( $mb->install_destination('binhtml'), "$home/html" );
77     is( $mb->install_destination('libhtml'), "$home/html" );
78
79     $mb = run_sample( install_path => { lib => '~/lib' } );
80     is( $mb->install_destination('lib'),  "$home/lib" );
81
82     $mb = run_sample( destdir => '~' );
83     is( $mb->destdir,           $home );
84
85     $mb->$p('~');
86     is( $mb->$p(),      '~', 'API does not expand tildes' );
87 }
88
89 # Again, with named users
90 SKIP: {
91     my @info = eval { getpwuid $> };
92     skip "No home directory for tilde-expansion tests", 1 if $@;
93     my ($me, $home) = @info[0,7];
94     
95     my $expected = "$home/foo";
96
97     if ($^O eq 'VMS') {
98         # Convert the path to UNIX format and trim off the trailing slash
99         $home = VMS::Filespec::unixify($home);
100         $home =~ s#/$##;
101         $expected = $home . '/../[^/]+' . '/foo';
102     }
103
104     like( run_sample( $p => "~$me/foo")->$p(),  qr($expected)i );
105 }
106
107
108 # cleanup
109 $dist->remove;