Commits

Anonymous committed a609169

Made the default test order lexicographical, and predictable. In the process,
eliminated keeping the directory handles, and possibly the fact that they
are kept open.

  • Participants
  • Parent commits 9ceb641

Comments (0)

Files changed (3)

 README
 t/01ffo.t
 t/02tree-create.t
+t/03traverse.t
 t/lib/File/Find/Object/TreeCreate.pm
 tree
 t/sample-data/h.txt

File lib/File/Find/Object/internal.pm

 use vars qw(@ISA);
 @ISA = qw(File::Find::Object);
 
+use File::Spec;
+
 sub new {
     my ($class, $from) = @_;
     my $self = {
 
 sub open_dir {
     my ($self) = @_;
-    opendir($self->{_handle}, $self->{dir}) or return undef;
+    opendir(my $handle, $self->{dir}) or return undef;
+    $self->{_files} =
+        [ sort { $a cmp $b } File::Spec->no_upwards(readdir($handle)) ];
+    closedir($handle);
     my @st = stat($self->{dir});
     $self->{inode} = $st[1];
     $self->{dev} = $st[0];
 
 sub movenext {
     my ($self) = @_;
-    my $h = $self->{_handle};
-    if ($self->{currentfile} = readdir($h)) {
+    if ($self->{currentfile} = shift(@{$self->{_files}})) {
         $self->{_action} = {};
         return 1;
     } else {

File t/03traverse.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+BEGIN
+{
+    use File::Spec;
+    use lib File::Spec->catdir(File::Spec->curdir(), "t", "lib");
+}
+
+use File::Find::Object::TreeCreate;
+use File::Find::Object;
+
+use File::Path;
+
+{
+    my $tree =
+    {
+        'name' => "traverse-1/",
+        'subs' =>
+        [
+            {
+                'name' => "b.doc",
+                'contents' => "This file was spotted in the wild.",
+            },            
+            {
+                'name' => "a/",
+            },
+            {
+                'name' => "foo/",
+                'subs' =>
+                [
+                    {
+                        'name' => "yet/",
+                    },
+                ],
+            },
+        ],
+    };
+
+    my $t = File::Find::Object::TreeCreate->new();
+    $t->create_tree("./t/sample-data/", $tree);
+    my $ff = 
+        File::Find::Object->new(
+            {},
+            $t->get_path("./t/sample-data/traverse-1")
+        );
+    my @results;
+    for my $i (1 .. 6)
+    {
+        push @results, $ff->next();
+    }
+    # TEST
+    is_deeply(
+        \@results,
+        [(map { $t->get_path("t/sample-data/traverse-1/$_") }
+            ("", qw(
+                a
+                b.doc
+                foo
+                foo/yet
+            ))),
+         undef
+        ],
+        "Checking for regular, lexicographically sorted order",
+    );
+
+    rmtree($t->get_path("./t/sample-data/traverse-1"))
+}