File Coverage

inc/TestHelper.pm
Criterion Covered Total %
statement 7 13 53.8
branch 0 4 0.0
condition n/a
subroutine 3 5 60.0
pod 3 3 100.0
total 13 25 52.0


line stmt bran cond sub pod time code
1             package inc::TestHelper;
2 14     14   210819 use strict;
  14         47  
  14         421  
3 14     14   68 use warnings;
  14         23  
  14         3036  
4              
5             require Exporter;
6             our @ISA = qw(Exporter);
7             our @EXPORT_OK = qw(test_output_file test_input_file);
8              
9             =head2 test_output_file
10              
11             Title : test_output_file
12             Usage : my $output_file = test_output_file();
13             Function: Get the full path of a file suitable for writing to.
14             When your test script ends, the file will be automatically deleted.
15             Returns : string (file path)
16             Args : none
17              
18             =cut
19              
20             sub test_output_file {
21 0 0   0 1 0 die "test_output_file takes no args\n" if @_;
22 0         0 my $tmp = File::Temp->new();
23 0         0 close($tmp); # Windows needs this
24 0         0 return $tmp->filename;
25             }
26              
27             =head2 test_output_dir
28              
29             Title : test_output_dir
30             Usage : my $output_dir = test_output_dir();
31             Function: Get the full path of a directory suitable for storing temporary files
32             in.
33             When your test script ends, the directory and its contents will be
34             automatically deleted.
35             Returns : string (path)
36             Args : none
37              
38             =cut
39              
40             sub test_output_dir {
41 0 0   0 1 0 die "test_output_dir takes no args\n" if @_;
42              
43 0         0 return tempdir(CLEANUP => 1);
44             }
45              
46             =head2 test_input_file
47              
48             Title : test_input_file
49             Usage : my $input_file = test_input_file();
50             Function: Get the path of a desired input file stored in the standard location
51             (currently t/data), but correct for all platforms.
52             Returns : string (file path)
53             Args : list of strings (ie. at least the input filename, preceded by the
54             names of any subdirectories within t/data)
55             eg. for the file t/data/in.file pass 'in.file', for the file
56             t/data/subdir/in.file, pass ('subdir', 'in.file')
57              
58             =cut
59              
60             sub test_input_file {
61 22     22 1 3437 return File::Spec->catfile('t', 'data', @_);
62             }
63              
64             1;