This just basically walks a given directory (skipping CVS directories) and finding all the .pm files and then builds a rudimentary 'smoke test' using Test::More::use_ok.
It will likely work on most *nix systems (please let me know if it doesn't). It is by no means a full featured test-creator (check out tachyon's Autogenerate Test Scripts for that). But I find it especially useful for when you decide to build a test suite for those old 'before-I-knew-about-testing' projects.
-stvn
UPDATE:
I was poking around CPAN, and it seems that Module::Starter will do something similar to this. Just FYI.
#!/usr/bin/perl use strict; use warnings; my $directory = shift(@ARGV); (defined($directory)) || die "You must specify a directory to create a smoke test for\nu +sage: create_smoke_test <directory>\n"; sub map_dir { my ($dir, $dir_func, $file_func, $depth) = @_; $depth ||= 0; map { if (-d $_ && !/CVS/) { $dir_func->($_, $depth + 1); map_dir($_, $dir_func, $file_func, $depth + 1); } elsif (-f $_ && /\.pm/) { $file_func->($_, $depth); } } sort { ((-d $a) ? 1 : (-d $b) ? -1 : ($a cmp $b)) } <$dir/*>; } sub handle_dir { my ($dir, $depth) = @_; $depth ||= 1; $dir =~ s/^$directory\///; print("\n" . ("\t" x $depth) . "# $dir\n"); } sub handle_file { my ($file, $depth) = @_; $depth ||= 1; $file =~ s/^$directory\///; my ($module_name) = ($file =~ /(.*?)\.pm/); $module_name =~ s/\//\:\:/g; print(("\t" x $depth) . "use_ok('$module_name');\n"); } print <<HEADER; #!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; BEGIN { HEADER map_dir($directory, \&handle_dir, \&handle_file); print <<FOOTER; }; 1; FOOTER 1; __END__
|
|---|