[perl-glib-io] RT#134851 Generate files for file-enumerator.t



commit f7bd76a1202fe39ac3add90dc8695cbb6d120744
Author: Michal Josef Špaček <mspacek redhat com>
Date:   Wed May 5 18:02:54 2021 +0200

    RT#134851 Generate files for file-enumerator.t
    
    Rewrite file-enumerator.t to use temp directory with 4 files and run on
    it. Original version cannot run from common directory, test was depend
    on number of files in t/.

 t/file-enumerator.t | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/t/file-enumerator.t b/t/file-enumerator.t
index 6fc57f9..86771d7 100644
--- a/t/file-enumerator.t
+++ b/t/file-enumerator.t
@@ -2,9 +2,15 @@
 use strict;
 use warnings;
 use Test::More tests => 3;
+use File::Temp qw(tempdir tempfile);
 use Glib::IO;
 
-my $dir = Glib::IO::File::new_for_path ('.');
+my $temp_dir = tempdir(CLEANUP => 1);
+my $files_count = 4;
+foreach (1 .. $files_count) {
+       my (undef, $temp_file) = tempfile(DIR => $temp_dir);
+}
+my $dir = Glib::IO::File::new_for_path ($temp_dir);
 my $enumerator = $dir->enumerate_children ('standard::*', [], undef);
 
 my $next_file = $enumerator->next_file (undef);
@@ -12,12 +18,13 @@ ok (defined $next_file->get_name ());
 
 {
   my $loop = Glib::MainLoop->new ();
-  $enumerator->next_files_async (2, 0, undef, \&next_files, [ 'bla', 23 ]);
+  my $files_requested = 2;
+  $enumerator->next_files_async ($files_requested, 0, undef, \&next_files, [ 'bla', 23 ]);
   sub next_files {
     my ($enumerator, $res, $data) = @_;
 
     my $files = $enumerator->next_files_finish ($res);
-    is (scalar @{$files}, 2);
+    is (scalar @{$files}, $files_requested);
     is_deeply ($data, [ 'bla', 23 ]);
 
     $loop->quit ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]