1use 5.008001;
2use strict;
3use warnings;
4use Test::More 0.96;
5use File::Basename ();
6use File::Temp     ();
7use File::Spec::Unix;
8
9use lib 't/lib';
10use TestUtils qw/exception/;
11
12use Path::Tiny;
13
14my $tempdir = File::Temp->newdir;
15
16my @kids = qw/apple banana carrot/;
17path($tempdir)->child($_)->touch for @kids;
18
19my @expected = map { path( File::Spec::Unix->catfile( $tempdir, $_ ) ) } @kids;
20
21is_deeply(
22    [ sort { $a cmp $b } path($tempdir)->children ],
23    [ sort @expected ],
24    "children correct"
25);
26
27my $regexp = qr/.a/;
28is_deeply(
29    [ sort { $a cmp $b } path($tempdir)->children($regexp) ],
30    [
31        sort grep { my $child = File::Basename::basename($_); $child =~ /$regexp/ }
32          @expected
33    ],
34    "children correct with Regexp argument"
35);
36
37my $arrayref = [];
38eval { path($tempdir)->children($arrayref) };
39like $@, qr/Invalid argument '\Q$arrayref\E' for children()/,
40  'children with invalid argument';
41
42done_testing;
43#
44# This file is part of Path-Tiny
45#
46# This software is Copyright (c) 2014 by David Golden.
47#
48# This is free software, licensed under:
49#
50#   The Apache License, Version 2.0, January 2004
51#
52