File: findknob.t

package info (click to toggle)
libfile-fu-perl 0.0.7-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 244 kB
  • ctags: 165
  • sloc: perl: 1,421; makefile: 2
file content (39 lines) | stat: -rwxr-xr-x 816 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
#!/usr/bin/perl

use warnings;
use strict;

use Test::More no_plan =>;

use File::Fu;

my $topdir = File::Fu->dir('tmp.' . $$);
END { $topdir->remove; }

$topdir->mkdir;
($topdir+$_)->touch for('a'..'z');
my $foo = $topdir->subdir("foo");
$foo->mkdir;
$foo->basename->symlink($topdir/'link');
($foo+$_)->touch for('a'..'z');

# bah!
my $x = do {
  # for this test to succeed, $files[0] must not be foo/ (a directory)
  # to achieve this, we sort the list
  my @files = sort $topdir->list;
  my ($i) = grep({$files[$_]->basename eq 'foo/'} 0..$#files);
  $_->unlink for(@files[($i+1)..$#files]);
  #warn join("|", $topdir->contents);
  $files[0]->basename;
};

my @files = $topdir->find(sub {
  #warn $_;
  $_->is_dir and return(shift->prune);
  $_->basename eq $x
});

is(scalar(@files), 1);

# vim:ts=2:sw=2:et:sta