File: 03-list.t

package info (click to toggle)
libdirectory-scratch-perl 0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 404 kB
  • ctags: 25
  • sloc: perl: 1,173; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 976 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
# 03-list.t 
# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>

use strict;
use warnings;
use Test::More tests=>16;
use Directory::Scratch;
use Path::Class;

my @files = qw(foo bar baz);
my @dirs  = qw(1 2 3);

my $t = Directory::Scratch->new;
my @list;

foreach my $dir (@dirs){
    my $tmp = $t->mkdir($dir);
    ok($tmp, "mkdir $dir");
    push @list, $dir;
    foreach my $file (@files){
	my $name = file($dir, $file);
	$tmp = $t->touch($name); 
	ok($tmp, "touch $tmp");
	push @list, $name;
    }
}

# do it
my @result = $t->ls;

@list   = sort @list;
@result = sort @result;

is_deeply(\@result, \@list, "listed everything");

@result = $t->ls;
@result = sort @result;
is_deeply(\@result, \@list, "listed everything (with /)");

@result = sort $t->ls('1');

my @possible = map {file('1', $_)} qw(bar baz foo);

is_deeply(\@result, \@possible, 'listed 1');

$t->touch('fooo');
is_deeply([$t->ls('fooo')], ['fooo'], "listing a single file is OK");