Test2-Plugin-FauxHomeDir

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.05      2019-05-24 10:12:14 -0400
  - Patch the patched File::HomeDir that is patched by Portable Strawberry Perl on windows
    (gh#2, gh#4)
  - Better diagnostics when things fail (gh#3 shawnlaffan++)

0.04      2018-04-18 12:46:06 -0400
  - Add real_home_dir method
    mildly begrudgingly

0.03      2017-08-07 15:52:03 -0400
  - Fall back on getlogin or getpwuid for determining username

0.02      2017-07-23 08:59:06 -0400
  - warn via either note or diag (depending on if the test fails) if
    File::HomeDir::Test has been loaded.

0.01      2017-07-22 21:58:35 -0400
  - initial version

README  view on Meta::CPAN


    This module sets up a faux home directory for tests. The home directory
    is empty, and will be removed when the test completes. This can be
    helpful when you are writing tests that may be reading from the real
    user configuration files, or if it writes output to the user home
    directory.

    At the moment this module accomplishes this by setting the operating
    system appropriate environment variables. In the future, it may hook
    into some of the other methods used for determining home directories
    (such as getpwuid and friends). There are many ways of getting around
    this faux module and getting the real home directory (especially from
    C). But if your code uses standard Perl interfaces then this plugin
    should fool your code okay.

    This module sets the native environment variables for the home
    directory on your platform. That means on Windows USERPROFILE,
    HOMEDRIVE and HOMEPATH will be set, but HOME will not. This is
    important because your testing environment should match as closely as
    possible what the actual environment will look like.

lib/Test2/Plugin/FauxHomeDir.pm  view on Meta::CPAN

        unless defined $real;
      $user = $ENV{USERNAME};
    }
    else
    {
      $real = $ENV{HOME};
      $user = $ENV{USER};
    }

    $user = eval { getlogin } unless defined $user;
    $user = eval { scalar getpwuid($>) } unless defined $user;
    die "unable to determine username" unless defined $user;

    die "unable to determine 'real' home directory"
      unless defined $real && -d $real;

    delete $ENV{USERPROFILE};
    delete $ENV{HOME};
    delete $ENV{HOMEDRIVE};
    delete $ENV{HOMEPATH};

lib/Test2/Plugin/FauxHomeDir.pm  view on Meta::CPAN


This module sets up a faux home directory for tests. The home directory
is empty, and will be removed when the test completes.  This can be
helpful when you are writing tests that may be reading from the real
user configuration files, or if it writes output to the user home
directory.

At the moment this module accomplishes this by setting the operating
system appropriate environment variables. In the future, it may hook
into some of the other methods used for determining home directories
(such as C<getpwuid> and friends).  There are many ways of getting
around this faux module and getting the real home directory (especially
from C).  But if your code uses standard Perl interfaces then this
plugin should fool your code okay.

This module sets the native environment variables for the home directory
on your platform.  That means on Windows C<USERPROFILE>, C<HOMEDRIVE>
and C<HOMEPATH> will be set, but C<HOME> will not.  This is important
because your testing environment should match as closely as possible
what the actual environment will look like.



( run in 0.278 second using v1.01-cache-2.11-cpan-8d75d55dd25 )