use strict; use warnings; use Test::More; use Test::Exception; use Test::Builder; use Test::Directory; my $builder = Test::More->builder->output('test-result.txt'); note "\nTest function: open_log_file"; subtest 'open_log_file' => sub { my $log_file = 'xyz.log'; my $log_dir = 'unit-test-temp'; my $dir = Test::Directory->new($log_dir); $dir->hasnt($log_file , "log file should not exist"); ok(open_log_file($log_dir . '/' . $log_file), "open_log_file should create a the log file"); $dir->has($log_file , "log file should now exist"); #cleanup after the test - this fails so far $dir->remove_files($log_file); $dir->remove_directories($log_dir); #another attempt to cleanup after the test - this also fails $dir->clean($log_dir); }; # doesn't work either #if (-e $log_dir) { # rmtree($log_dir); #} #### ####################################################################################################### use FileHandle; ... ... sub open_log_file { my $log_file = shift; # open the log $log_fh = FileHandle->new("> $log_file") || die "Failed to open log file $log_file: $!"; return 1; }