blob: 4c0e26605194381ff0d1185713998ed95b0e2f07 (
plain)
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
|
use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use File::Basename ();
use File::Temp ();
use File::Spec::Unix;
use lib 't/lib';
use TestUtils qw/exception/;
use Path::Tiny;
my $tempdir = File::Temp->newdir;
my @kids = qw/apple banana carrot/;
path($tempdir)->child($_)->touch for @kids;
my @expected = map { path( File::Spec::Unix->catfile( $tempdir, $_ ) ) } @kids;
is_deeply(
[ sort { $a cmp $b } path($tempdir)->children ],
[ sort @expected ],
"children correct"
);
my $regexp = qr/.a/;
is_deeply(
[ sort { $a cmp $b } path($tempdir)->children($regexp) ],
[
sort grep { my $child = File::Basename::basename($_); $child =~ /$regexp/ }
@expected
],
"children correct with Regexp argument"
);
my $arrayref = [];
eval { path($tempdir)->children($arrayref) };
like $@, qr/Invalid argument '\Q$arrayref\E' for children()/,
'children with invalid argument';
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
#
|