note "\nTest function: get_files_in_watched_directory"; subtest 'get_files_in_watched_directory' => sub { my @got_files; my @expected_files; my $project_name = 'default'; # create a temporary directory my $temp_dir = tempdir( CLEANUP => 1 ); # create some temporary files in the directory my ($temp_file1_handle, $temp_file1) = tempfile(DIR => $temp_dir); my ($temp_file2_handle, $temp_file2) = tempfile(DIR => $temp_dir); my ($temp_file3_handle, $temp_file3) = tempfile(DIR => $temp_dir); my ($temp_file4_handle, $temp_file4) = tempfile(DIR => $temp_dir); my ($temp_file5_handle, $temp_file5) = tempfile(DIR => $temp_dir); # create an array populated with the names of the temporary files that we expectd to see push (@expected_files, basename($temp_file1)); push (@expected_files, basename($temp_file2)); push (@expected_files, basename($temp_file3)); push (@expected_files, basename($temp_file4)); push (@expected_files, basename($temp_file5)); # now pass the temporary directory to the the function # the function should return an array @got_files with the names of the files in the directory @got_files = get_files_in_watched_directory($temp_dir, $project_name, \@expected_files); print "\n\nGOT\n"; print Dumper(@got_files); print "\n"; print "\n\nEXPECTED\n"; print Dumper(@expected_files); print "\n"; #compare the two arrays is_deeply(\@got_files, \@expected_files, 'Function should return a list of directory contents that will be processed'); }; #### ######################################################################################################## sub get_files_in_watched_directory { my ($directory_to_check, $project_name, $original_content_ref) = @_; my @problem_files; my @content_to_process; my $this_file; print "\n\nCalled Function: get_files_in_watched_directory"; print "\n Checking $directory_to_check"; chdir ($directory_to_check) || die "cannot chdir to directory $directory_to_check: $!"; # Get everything - files and directories - and decide what to do with each one opendir(DIR,$directory_to_check) || die "cannot open directory $directory_to_check: $!"; while (defined($this_file = readdir(DIR))) { my $full_file_name = $directory_to_check . '/' . $this_file; # ignore the special directories "." and '.." if ($this_file =~ /^\.\.?$/) { next } # wite anything else (file or directory) to an array to be processed later else { print "\n found: $this_file"; push (@content_to_process, $this_file) } } closedir(DIR); print "\n\nabout to retun"; #return @content_to_process; return (@{$original_content_ref}); }