File Coverage

blib/lib/RapidApp/Test/EnvUtil.pm
Criterion Covered Total %
statement 22 24 91.6
branch 6 10 60.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 34 43 79.0


line stmt bran cond sub pod time code
1             package # hide from PAUSE
2             RapidApp::Test::EnvUtil;
3              
4             # THIS PACKAGE IS ONLY MEANT TO BE USED IN TEST SCRIPTS
5              
6 4     4   43185 use strict;
  4         24  
  4         101  
7 4     4   18 use warnings;
  4         7  
  4         102  
8 4     4   729 use Path::Class qw(dir);
  4         78086  
  4         195  
9 4     4   30 use FindBin '$Bin';
  4         7  
  4         1068  
10              
11              
12             # Dynamically set a local TMPDIR to be relative to our
13             # expected directory structure within the RapidApp t/
14             # directory. We want to always end up with 't/var/tmp'
15             sub set_tmpdir_env {
16            
17 4     4 0 166 my $dir = dir($Bin);
18 4         423 while(-d $dir->parent) {
19 4 50 33     552 if (-d $dir->subdir('testapps')) {
    50          
20             # we're done
21 0         0 last;
22             }
23             elsif(-d $dir->subdir('var') && -d $dir->subdir('var')->subdir('testapps')) {
24             # This code path happens when we're called from a .t script
25 4         949 $dir = $dir->subdir('var');
26 4         148 last;
27             }
28             else {
29             # keep walking up parent directories (this code path happens when we're
30             # being called from a script within the test app)
31 0         0 $dir = $dir->parent;
32             }
33             }
34            
35 4 50       22 die "Unable to resolve test tmp dir" unless (-d $dir->subdir('testapps'));
36            
37 4         235 my $tmpdir = $dir->subdir('tmp')->absolute;
38 4 100       244 $tmpdir->mkpath unless (-d $tmpdir);
39            
40             # Make sure it actually exists/was created:
41 4 50       490 die "Error resolving/creating test tmp dir '$tmpdir'" unless (-d $tmpdir);
42            
43             # Now, set the TMPDIR env variable (used by Catalyst::Utils::class2tempdir)
44 4         131 $ENV{TMPDIR} = $tmpdir->stringify;
45            
46             }
47              
48              
49             1;