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