| 1 | package Test2::Plugin::FauxHomeDir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.008001; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use File::Temp qw( tempdir ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use File::Spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::Path qw( mkpath ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use if $^O eq 'cygwin', 'File::Spec::Win32'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Test2::API qw( test2_add_callback_post_load test2_stack test2_add_callback_exit ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # ABSTRACT: Setup a faux home directory for tests | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | our $VERSION = '0.06'; # VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | my $real; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | my $faux; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | my $user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | my @mocks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub real_home_dir | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
real_home_dir: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $real; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub import | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=13 SCAR=34.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | my @notes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | unless(defined $faux) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | if($^O eq 'MSWin32') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $real = $ENV{USERPROFILE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | $real = File::Spec->catdir($ENV{HOMEDRIVE}, $ENV{HOMEPATH}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | unless defined $real; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $user = $ENV{USERNAME}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | $real = $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | $user = $ENV{USER}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | $user = eval { getlogin } unless defined $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | $user = eval { scalar getpwuid($>) } unless defined $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | die "unable to determine username" unless defined $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | die "unable to determine 'real' home directory" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $real and -d $real
MC/DC0%0/2
defined $real and -d $real
defined $real
-d $real
Truth table33%1/3
A and B
A= defined $realB= -d $real
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | unless defined $real && -d $real; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | delete $ENV{USERPROFILE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | delete $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | delete $ENV{HOMEDRIVE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | delete $ENV{HOMEPATH}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | $faux = File::Spec->catdir(tempdir( CLEANUP => 1 ), 'home', $user); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | mkpath $faux, 0, 0700; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | if($^O eq 'MSWin32') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $ENV{USERPROFILE} = $faux; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ($ENV{HOMEDRIVE}, $ENV{HOMEPATH}) = File::Spec->splitpath($faux,1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if(eval { require Portable }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | push @notes, "Portable strawberry detected"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if(eval { require File::HomeDir }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # annoyingly, Strawberry Portable Perl patches | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # File::HomeDir, but not things like File::Glob | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # so since there isn't a good interface to override | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # this behavior, we need to patch the patch :( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | push @notes, "Patching File::HomeDir"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | require Test2::Mock; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | push @mocks, Test2::Mock->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | class => 'File::HomeDir', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | override => [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my_home => sub { $faux }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | elsif($^O eq 'cygwin') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $ENV{USERPROFILE} = Cygwin::posix_to_win_path($faux); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ($ENV{HOMEDRIVE}, $ENV{HOMEPATH}) = File::Spec::Win32->splitpath($ENV{USERPROFILE},1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $ENV{HOME} = $faux; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | $ENV{HOME} = $faux; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | push @notes, "Test2::Plugin::FauxHomeDir using faux home dir $faux"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | push @notes, "Test2::Plugin::FauxHomeDir real home dir is $real"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | test2_add_callback_post_load(sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | test2_stack()->top; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | my($hub) = test2_stack->all; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | $hub->send( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Test2::Event::Note->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | message => $_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | ) for @notes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | ▶ | test2_add_callback_exit(sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=25.5
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | my ($ctx, $real, $new) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | ▶ | if($INC{'File/HomeDir/Test.pm'}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my @message = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 'File::HomeDir::Test was loaded.', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 'You probably do not want to load both File::HomeDir::Test and Test2::Plugin::FauxHomeDir', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | if($real || ($new && $$new) || !$ctx->hub->is_passing) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$real or $new and $$new or not $ctx->hub->is_passing
$real or $new and $$new
$new and $$new
MC/DC0%0/4
$real or $new and $$new or not $ctx->hub->is_passing
$real
$new
$$new
not $ctx->hub->is_passing
Truth table16%1/6
A or B and C or not(D)
A= $realB= $newC= $$newD= not $ctx->hub->is_passing
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $ctx->diag($_) for @message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | $ctx->note($_) for @message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||