/*
* handle a plain ~ or ~/ by expanding $HOME
* first and then trying the password file
+ * or $USERPROFILE on DOSISH systems
*/
if ((h = getenv("HOME")) == NULL) {
#ifdef HAS_PASSWD
return pattern;
else
h = pwd->pw_dir;
+#elif DOSISH
+ /*
+ * When no passwd file, fallback to the USERPROFILE
+ * environment variable on DOSish systems.
+ */
+ if ((h = getenv("USERPROFILE")) == NULL) {
+ return pattern;
+ }
#else
return pattern;
#endif
}
}
use strict;
-use Test::More tests => 15;
+use Test::More tests => 18;
BEGIN {use_ok('File::Glob', ':glob')};
use Cwd ();
is_deeply (\@a, [$home]);
}
}
+# check plain tilde expansion
+{
+ my $tilde_check = sub {
+ my @a = bsd_glob('~');
+
+ if (GLOB_ERROR) {
+ fail(GLOB_ERROR);
+ } else {
+ is_deeply (\@a, [$_[0]], join ' - ', 'tilde expansion', @_ > 1 ? $_[1] : ());
+ }
+ };
+ my $passwd_home = eval { (getpwuid($>))[7] };
+
+ {
+ local %ENV = %ENV;
+ delete $ENV{HOME};
+ delete $ENV{USERPROFILE};
+ $tilde_check->(defined $passwd_home ? $passwd_home : q{~}, 'no environment');
+ }
+
+ SKIP: {
+ skip 'MSWin32 only', 1 if $^O ne 'MSWin32';
+ local %ENV = %ENV;
+ delete $ENV{HOME};
+ $ENV{USERPROFILE} = 'sweet win32 home';
+ $tilde_check->(defined $passwd_home ? $passwd_home : $ENV{USERPROFILE}, 'USERPROFILE');
+ }
+
+ my $home = exists $ENV{HOME} ? $ENV{HOME}
+ : eval { getpwuid($>); 1 } ? (getpwuid($>))[7]
+ : $^O eq 'MSWin32' && exists $ENV{USERPROFILE} ? $ENV{USERPROFILE}
+ : q{~};
+ $tilde_check->($home);
+}
# check backslashing
# should return a list with one item, and not set ERROR