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__

In reply to Create smoke test for your directory of modules by stvn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.