use Test::More tests => 13; use My::Module; # Make my object my $object = My::Module->new(); my $dir = '/home/trs80'; my $test_file = 'file.txt'; # create hashref for use later on my $session = { base_dir => $dir, } # test that the object exists ok( $object->isa('My::Module' , "Our object is in the right class"); # first we try a file name by itself my $content = $object->get_file_contents( "$dir/$test_file" ); ok( $content ne '' , "\$content has something in it!" ); ok( $content =~ /string/ , "\$content contains string!" ); undef $content; ok( !$content , "\$content is empty" # now we try a file name like the first test. $content = $object->get_file_contents( { file_name => "$dir/$test_file", } ); ok( $content ne '' , "\$content has something in it!" ); ok( $content =~ /string/ , "\$content contains string!" ); undef $content; ok( !$content , "\$content is empty" ); # test of the 'fancy_magic_file_find' way # and make sure it gives back a file name my ($contents,$file_name) = $object->get_file_contents( $session ); ok( $file_name =~ m#^$dir#, "our file_name: $file_name" ); ok( $contents ne '' , "\$content has something in it!" ); ok( $contents =~ /string/ , "\$content contains string!" ); undef $contents; ok( !$contents , "\$content is empty" ); # test the error condition $content = $object->get_file_contents(); ok( $content =~ /^ERROR\:/ , 'error on retrieve with no arguments' ); 1;