home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Manifest.pm < prev    next >
Encoding:
Perl POD Document  |  2003-09-16  |  4.0 KB  |  181 lines

  1. # $Id: Manifest.pm,v 1.2 2003/09/16 18:16:45 joker Exp $
  2. package Test::Manifest;
  3. use strict;
  4.  
  5. use base qw(Exporter);
  6. use vars qw(@EXPORT_OK @EXPORT $VERSION);
  7.  
  8. use Carp qw(carp);
  9. use Exporter;
  10.  
  11. @EXPORT    = qw(run_t_manifest);
  12. @EXPORT_OK = qw(get_t_files make_test_manifest manifest_name);
  13.  
  14. #$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ m/(\d+) . (\d+)/x;
  15. $VERSION = 0.91;
  16.  
  17. my $Manifest = "t/test_manifest";
  18.  
  19. =head1 NAME
  20.  
  21. Test::Manifest - interact with a t/test_manifest file
  22.  
  23. =head1 SYNOPSIS
  24.  
  25. See the functions section.
  26.  
  27. =head1 DESCRIPTION
  28.  
  29. MakeMaker assumes that you want to run all of the .t files
  30. in the t/ directory in ascii-betical order during C<make test>
  31. unless you say otherwise.  This leads to some interesting 
  32. naming schemes for test files to get them in the desired order.
  33.  
  34. You can specify any order or any files that you like, though,
  35. with the C<test> directive to WriteMakefile.
  36.  
  37. Test::Manifest looks in the t/test_manifest file to find out
  38. which tests you want to run and the order in which you want
  39. to run them.  It constructs the right value for MakeMaker to
  40. do the right thing.
  41.  
  42. =head1 FUNCTIONS
  43.  
  44. =over 4
  45.  
  46. =item run_t_manifest
  47.  
  48. Run all of the files in t/test_manifest through Test::Harness:runtests
  49. in the order they appear in the file.
  50.  
  51. If you want to use this, in Makefile.PL you need to override some 
  52. MakeMaker magic (after you load ExtUtils::MakeMaker).  I recommend
  53. putting something like this directly in Makefile.PL so it does not
  54. depend on anything else.  A Makefile.PL with dependencies is a big
  55. headache.
  56.  
  57.     sub ExtUtils::MM_Any::test_via_harness
  58.         {
  59.         my($self, $perl, $tests) = @_;
  60.     
  61.         return qq|\t$perl "-MTest::Manifest" | .
  62.                qq|"-e" "run_t_manifest(\$(TEST_VERBOSE), '\$(INST_LIB)', | .
  63.                qq|'\$(INST_ARCHLIB)')"\n|;
  64.         }
  65.  
  66. =cut
  67.  
  68. sub run_t_manifest 
  69.     {
  70.     require Test::Harness;
  71.     require File::Spec;
  72.  
  73.     $Test::Harness::verbose = shift;
  74.  
  75.     local @INC = @INC;
  76.     unshift @INC, map { File::Spec->rel2abs($_) } @_;
  77.  
  78.     my @files = get_t_files();
  79.     print STDERR "Test::Manifest::test_harness found [@files]\n";
  80.     
  81.     Test::Harness::runtests( @files );
  82.     }
  83.  
  84. =item get_t_files()
  85.  
  86. In scalar context it returns a single string that you can use directly
  87. in WriteMakefile().
  88.  
  89. In list context it returns a list of the files it found in
  90. t/test_manifest.
  91.  
  92. If a t/test_manifest file does not exist, get_t_files() returns
  93. nothing.
  94.  
  95. get_t_files() warns you if it can't find t/test_manifest, or if
  96. entries start with "t/".
  97.  
  98. =cut
  99.  
  100. sub get_t_files()
  101.     {
  102.     carp( "$Manifest does not exist!" ) unless -e $Manifest;
  103.     return unless open my $fh, $Manifest;
  104.     
  105.     my @tests = ();
  106.     
  107.     while( <$fh> )
  108.         {
  109.         chomp;
  110.         carp( "test file begins with t/ [$_]" ) if m|^t/|;
  111.         push @tests, "t/$_" if -e "t/$_";
  112.         }
  113.         
  114.     return wantarray ? @tests : join " ", @tests;
  115.     }
  116.  
  117. =item make_test_manifest()
  118.  
  119. Creates the test_manifest file in the t directory by reading
  120. the contents of the t directory.
  121.  
  122. TO DO: specify tests in argument lists.
  123.  
  124. TO DO: specify files to skip.
  125.  
  126. =cut
  127.  
  128. sub make_test_manifest()
  129.     {
  130.     carp( "t/ directory does not exist!" ) unless -d "t";
  131.     return unless open my $fh, "> $Manifest";
  132.     
  133.     my $count = 0;
  134.     while( my $file = glob("t/*.t") )
  135.         {
  136.         $file =~ s|^t/||;
  137.         print $fh "$file\n";
  138.         $count++;
  139.         }
  140.     
  141.     return $count;
  142.     }
  143.  
  144. =item manifest_name
  145.  
  146. Returns the name of the test manifest file, relative to t/
  147.  
  148. =cut
  149.  
  150. sub manifest_name
  151.     {
  152.     return $Manifest;
  153.     }
  154.     
  155. =back
  156.  
  157. =head1 SOURCE AVAILABILITY
  158.  
  159. This source is part of a SourceForge project which always has the
  160. latest sources in CVS, as well as all of the previous releases.
  161.  
  162.     https://sourceforge.net/projects/brian-d-foy/
  163.     
  164. If, for some reason, I disappear from the world, one of the other
  165. members of the project can shepherd this module appropriately.
  166.  
  167. =head1 AUTHOR
  168.  
  169. brian d foy, E<lt>bdfoy@cpan.orgE<lt>
  170.  
  171. =head1 COPYRIGHT
  172.  
  173. Copyright 2002, brian d foy, All Rights Reserved
  174.  
  175. You may use and distribute this module under the same terms
  176. as Perl itself
  177.  
  178. =cut
  179.     
  180. 1;
  181.