Add ARM files
[dh-make-perl] / dev / arm / libmodule-build-perl / libmodule-build-perl-0.2808.01 / 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 => 15;
8
9 use Cwd ();
10 my $cwd = Cwd::cwd;
11 my $tmp = MBTest->tmpdir;
12
13 use DistGen;
14 my $dist = DistGen->new( dir => $tmp );
15 $dist->regen;
16
17 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
18
19
20 use Module::Build;
21
22 sub run_sample {
23     my @args = @_;
24
25     local $Test::Builder::Level = $Test::Builder::Level + 1;
26
27     $dist->clean;
28
29     my $mb;
30     stdout_of( sub {
31       $mb = Module::Build->new_from_context( @args );
32     } );
33
34     return $mb;
35 }
36
37
38 my $p = 'install_base';
39
40 SKIP: {
41     my $home = $ENV{HOME} ? $ENV{HOME} : undef;
42     unless (defined $home) {
43       my @info = eval { getpwuid $> };
44       skip "No home directory for tilde-expansion tests", 14 if $@;
45       $home = $info[7];
46     }
47
48     is( run_sample( $p => '~'     )->$p(),  $home );
49
50     is( run_sample( $p => '~/foo' )->$p(),  "$home/foo" );
51
52     is( run_sample( $p => '~~'    )->$p(),  '~~' );
53
54     is( run_sample( $p => '~ foo' )->$p(),  '~ foo' );
55
56     is( run_sample( $p => '~/ foo')->$p(),  "$home/ foo" );
57       
58     is( run_sample( $p => '~/fo o')->$p(),  "$home/fo o" );
59
60     is( run_sample( $p => 'foo~'  )->$p(),  'foo~' );
61
62     is( run_sample( prefix => '~' )->prefix,
63         $home );
64
65     my $mb = run_sample( install_path => { html => '~/html',
66                                            lib  => '~/lib'   }
67                        );
68     is( $mb->install_destination('lib'),  "$home/lib" );
69     # 'html' is translated to 'binhtml' & 'libhtml'
70     is( $mb->install_destination('binhtml'), "$home/html" );
71     is( $mb->install_destination('libhtml'), "$home/html" );
72
73     $mb = run_sample( install_path => { lib => '~/lib' } );
74     is( $mb->install_destination('lib'),  "$home/lib" );
75
76     $mb = run_sample( destdir => '~' );
77     is( $mb->destdir,           $home );
78
79     $mb->$p('~');
80     is( $mb->$p(),      '~', 'API does not expand tildes' );
81 }
82
83 # Again, with named users
84 SKIP: {
85     my @info = eval { getpwuid $> };
86     skip "No home directory for tilde-expansion tests", 1 if $@;
87     my ($me, $home) = @info[0,7];
88     
89     is( run_sample( $p => "~$me/foo")->$p(),  "$home/foo" );
90 }
91
92
93 # cleanup
94 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
95 $dist->remove;
96
97 use File::Path;
98 rmtree( $tmp );