3 # Test ~ expansion from command line arguments.
6 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
7 use MBTest tests => 17;
9 use_ok 'Module::Build';
10 ensure_blib('Module::Build');
12 my $tmp = MBTest->tmpdir;
15 my $dist = DistGen->new( dir => $tmp );
24 local $Test::Builder::Level = $Test::Builder::Level + 1;
30 $mb = Module::Build->new_from_context( @args );
37 my $p = 'install_base';
40 my $home = $ENV{HOME} ? $ENV{HOME} : undef;
43 # Convert the path to UNIX format, trim off the trailing slash
44 $home = VMS::Filespec::unixify($home);
48 unless (defined $home) {
49 my @info = eval { getpwuid $> };
50 skip "No home directory for tilde-expansion tests", 14 if $@;
54 is( run_sample( $p => '~' )->$p(), $home );
56 is( run_sample( $p => '~/foo' )->$p(), "$home/foo" );
58 is( run_sample( $p => '~~' )->$p(), '~~' );
60 is( run_sample( $p => '~ foo' )->$p(), '~ foo' );
62 is( run_sample( $p => '~/ foo')->$p(), "$home/ foo" );
64 is( run_sample( $p => '~/fo o')->$p(), "$home/fo o" );
66 is( run_sample( $p => 'foo~' )->$p(), 'foo~' );
68 is( run_sample( prefix => '~' )->prefix,
71 my $mb = run_sample( install_path => { html => '~/html',
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" );
79 $mb = run_sample( install_path => { lib => '~/lib' } );
80 is( $mb->install_destination('lib'), "$home/lib" );
82 $mb = run_sample( destdir => '~' );
83 is( $mb->destdir, $home );
86 is( $mb->$p(), '~', 'API does not expand tildes' );
89 # Again, with named users
91 my @info = eval { getpwuid $> };
92 skip "No home directory for tilde-expansion tests", 1 if $@;
93 my ($me, $home) = @info[0,7];
95 my $expected = "$home/foo";
98 # Convert the path to UNIX format and trim off the trailing slash
99 $home = VMS::Filespec::unixify($home);
101 $expected = $home . '/../[^/]+' . '/foo';
104 like( run_sample( $p => "~$me/foo")->$p(), qr($expected)i );