3 # Test ~ expansion from command line arguments.
7 use MBTest tests => 16;
9 blib_load('Module::Build');
11 my $tmp = MBTest->tmpdir;
14 my $dist = DistGen->new( dir => $tmp );
23 local $Test::Builder::Level = $Test::Builder::Level + 1;
29 $mb = Module::Build->new_from_context( @args );
36 my $p = 'install_base';
39 my $home = $ENV{HOME} ? $ENV{HOME} : undef;
42 # Convert the path to UNIX format, trim off the trailing slash
43 $home = VMS::Filespec::unixify($home);
47 unless (defined $home) {
48 my @info = eval { getpwuid $> };
49 skip "No home directory for tilde-expansion tests", 15 if $@;
53 is( run_sample( $p => '~' )->$p(), $home );
55 is( run_sample( $p => '~/foo' )->$p(), "$home/foo" );
57 is( run_sample( $p => '~/ foo')->$p(), "$home/ foo" );
59 is( run_sample( $p => '~/fo o')->$p(), "$home/fo o" );
61 is( run_sample( $p => 'foo~' )->$p(), 'foo~' );
63 is( run_sample( prefix => '~' )->prefix,
66 # Test when HOME is different from getpwuid(), as in sudo.
68 local $ENV{HOME} = '/wibble/whomp';
70 is( run_sample( $p => '~' )->$p(), "/wibble/whomp" );
73 my $mb = run_sample( install_path => { html => '~/html',
76 is( $mb->install_destination('lib'), "$home/lib" );
77 # 'html' is translated to 'binhtml' & 'libhtml'
78 is( $mb->install_destination('binhtml'), "$home/html" );
79 is( $mb->install_destination('libhtml'), "$home/html" );
81 $mb = run_sample( install_path => { lib => '~/lib' } );
82 is( $mb->install_destination('lib'), "$home/lib" );
84 $mb = run_sample( destdir => '~' );
85 is( $mb->destdir, $home );
88 is( $mb->$p(), '~', 'API does not expand tildes' );
90 skip "On OS/2 EMX all users are equal", 2 if $^O eq 'os2';
91 is( run_sample( $p => '~~' )->$p(), '~~' );
92 is( run_sample( $p => '~ foo' )->$p(), '~ foo' );
95 # Again, with named users
97 my @info = eval { getpwuid $> };
98 skip "No home directory for tilde-expansion tests", 1 if $@;
99 my ($me, $home) = @info[0,7];
101 my $expected = "$home/foo";
104 # Convert the path to UNIX format and trim off the trailing slash
105 $home = VMS::Filespec::unixify($home);
107 $expected = $home . '/../[^/]+' . '/foo';
110 like( run_sample( $p => "~$me/foo")->$p(), qr($expected)i );