1# Before `make install' is performed this script should be runnable with 2# `make test'. 3 4######################### 5 6# change 'tests => 1' to 'tests => last_test_to_print'; 7 8use Test::More tests => 4; 9 10BEGIN { use_ok('File::Rename') }; 11 12######################### 13 14# Insert your test code below, the Test::More module is use()ed here so read 15# its man page ( perldoc Test::More ) for help writing this test script. 16 17unshift @INC, 't' if -d 't'; 18require 'testlib.pl'; 19 20sub test_rename { goto &test_rename_list; } 21 22my $dir = do { require File::Temp; File::Temp::tempdir() }; 23chdir $dir or die; 24 25my @files = ('file.txt', 'bad file', "new\nline"); 26my @target = grep { create_file($_) } @files; 27die unless @target; 28 29my $file = 'list.txt'; 30create_file($file, map qq($_\0), @target) or die; 31 32our $found; 33our $print; 34our $warn; 35local $SIG{__WARN__} = sub { $warn .= $_[0] }; 36 37my $s = sub { s/\W// }; 38 39{ 40 open my $fh, '<', $file or die "Can't open $file: $!\n"; 41 test_rename($s, $fh, {verbose=>1, input_null=>1}, 0, 42 "Reading filenames from file handle" ); 43} 44ok( $found, "rename_list"); 45diag_rename; 46 47s/\W// for @target; 48is_deeply( [ sort(listdir('.')) ], 49 [sort($file, @target)], 50 'rename - list - null' ); 51 52END { chdir File::Spec->rootdir; 53 File::Path::rmtree($dir); 54 ok( !-d $dir, "test dir removed"); 55} 56 57