diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2014-03-07 12:27:19 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2014-03-07 12:27:19 +0000 |
commit | 13016fa7011fc3084536c7b3181d75acb43d3aae (patch) | |
tree | 243c375747ca181bea20c8e05e01e00e449d128c /t/tilde.t | |
download | ExtUtils-Helpers-tarball-master.tar.gz |
ExtUtils-Helpers-0.022HEADExtUtils-Helpers-0.022master
Diffstat (limited to 't/tilde.t')
-rw-r--r-- | t/tilde.t | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/t/tilde.t b/t/tilde.t new file mode 100644 index 0000000..784ca4a --- /dev/null +++ b/t/tilde.t @@ -0,0 +1,66 @@ +#!/usr/bin/perl -w + +# Test ~ expansion from command line arguments. + +use strict; +use lib 't/lib'; +use Test::More tests => 9; + +use ExtUtils::Helpers 'detildefy'; + +SKIP: { + my $env_name = $^O eq 'MSWin32' ? 'USERPROFILE' : 'HOME'; + my $home = $ENV{$env_name}; + + if ($^O eq 'VMS') { + # Convert the path to UNIX format, trim off the trailing slash + $home = VMS::Filespec::unixify($home); + $home =~ s#/$##; + } + + unless (defined $home) { + my @info = eval { getpwuid $> }; + skip "No home directory for tilde-expansion tests", 8 if $@ or !defined $info[7]; + $home = $info[7]; + } + + is( detildefy('~'), $home); + + is( detildefy('~/fooxzy'), "$home/fooxzy"); + + is( detildefy('~/ fooxzy'), "$home/ fooxzy"); + + is( detildefy('~/fo o'), "$home/fo o"); + + is( detildefy('fooxzy~'), 'fooxzy~'); + + # Test when HOME is different from getpwuid(), as in sudo. + { + local $ENV{HOME} = '/wibble/whomp'; + local $ENV{USERPROFILE} = $ENV{HOME}; + + is( detildefy('~'), "/wibble/whomp"); + } + + skip "On OS/2 EMX all users are equal", 2 if $^O eq 'os2'; + is( detildefy('~~'), '~~' ); + is( detildefy('~ fooxzy'), '~ fooxzy' ); +} + +# Again, with named users +SKIP: { + my @info = eval { getpwuid $> }; + skip "No home directory for tilde-expansion tests", 1 if $@ or !defined $info[7] or !defined $info[0]; + my ($me, $home) = @info[0,7]; + + my $expected = "$home/fooxzy"; + + if ($^O eq 'VMS') { + # Convert the path to UNIX format and trim off the trailing slash + $home = VMS::Filespec::unixify($home); + $home =~ s#/$##; + $expected = $home . '/../[^/]+' . '/fooxzy'; + } + like( detildefy("~$me/fooxzy"), qr(\Q$expected\E)i ); +} + |