File: mkdir.t

package info (click to toggle)
libpath-tiny-perl 0.148-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: perl: 1,300; makefile: 2; sh: 1
file content (56 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use File::Temp ();

use lib 't/lib';
use TestUtils qw/exception/;

use Path::Tiny;

my $tempdir = File::Temp->newdir;

my $path = path($tempdir)->child("foo");

ok( !-e $path,     "target directory not created yet" );
ok( $path->mkdir, "mkdir on directory returned true" );
ok( -d $path,      "target directory created" );
ok( $path->mkdir, "mkdir on existing directory returned true" );

if ( $^O ne 'MSWin32' ) {
    my $path2 = path($tempdir)->child("bar");
    ok( !-e $path2, "target directory not created yet" );
    ok( $path2->mkdir( { mode => 0700 } ), "mkdir on directory with mode" );
    if ( $^O ne 'msys' ) {
        is( $path2->stat->mode & 0777, 0700, "correct mode" );
    }
    ok( -d $path2, "target directory created" );
}

{
    for my $weird_args (
        ["bogus"],  # a string, somebody thought it's the child name
        [mode=>1],  # programmer forgot to wrap pairs in {...}
        [{}, 1 ],   # valid {} but extra argument; oops!
        [[]],       # weird mistake, but better to die than ignore
    ) {
        my $error = exception { $path->mkdir(@$weird_args) };
        like(
          $error,
          qr/method argument was given, but was not a hash reference/,
          "passing a weird argument to ->mkdir throws (@$weird_args)",
        );
    }
}

done_testing;
#
# This file is part of Path-Tiny
#
# This software is Copyright (c) 2014 by David Golden.
#
# This is free software, licensed under:
#
#   The Apache License, Version 2.0, January 2004
#