File: GenTemp.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (44 lines) | stat: -rw-r--r-- 1,025 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use Test2::V0 -target => 'Test2::Tools::GenTemp';

use ok $CLASS => 'gen_temp';

use File::Spec;

use IO::Handle;

imported_ok qw/gen_temp/;

my $tmp = gen_temp(
    -tempdir => [CLEANUP => 1, TMPDIR => 1],
    foo => "foo\n",
    bar => "bar\n",
    subdir => {
        baz => "baz\n",
        nested => {
            bat => "bat",
        },
    },
);

ok($tmp, "Got a temp dir ($tmp)");

ok(-d File::Spec->canonpath($_), "Created dir $_") for (
    $tmp,
    File::Spec->catdir($tmp, 'subdir'),
    File::Spec->catdir($tmp, 'subdir', 'nested'),
);

for my $file (qw{foo bar subdir/baz subdir/nested/bat}) {
    my $cp = File::Spec->catfile($tmp, $file);
    ok(-f $cp, "Created file $file");
    open(my $fh, '<', $cp) or die "Could not open file '$cp': $!";
    my $content = $file;
    $content =~ s{^.*/}{}g;
    $content .= "\n" unless $content eq 'bat';
    my $printable = $content;
    $printable =~ s/\n/\\n/;
    is(<$fh>, $content, "Got content ($printable)");
    ok($fh->eof, "$file At EOF");
}

done_testing;