cvs commit: modperl-2.0/Apache-Test/lib/Apache Test.pm

2001-04-17 Thread dougm

dougm   01/04/17 21:36:58

  Modified:Apache-Test/lib/Apache Test.pm
  Log:
  add Apache::TestToString class for feeding Test.pm output into a string
  
  Revision  ChangesPath
  1.3   +34 -3 modperl-2.0/Apache-Test/lib/Apache/Test.pm
  
  Index: Test.pm
  ===
  RCS file: /home/cvs/modperl-2.0/Apache-Test/lib/Apache/Test.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Test.pm   2001/04/04 04:36:57 1.2
  +++ Test.pm   2001/04/18 04:36:56 1.3
  @@ -11,6 +11,12 @@
   our $VERSION = '0.01';
   
   #so Perl's Test.pm can be run inside mod_perl
  +sub test_pm_refresh {
  +$Test::TESTOUT = \*STDOUT;
  +$Test::planned = 0;
  +$Test::ntest = 1;
  +}
  +
   sub init_test_pm {
   my $r = shift;
   
  @@ -27,9 +33,7 @@
   
   $r->content_type('text/plain');
   
  -$Test::TESTOUT = \*STDOUT;
  -$Test::planned = 0;
  -$Test::ntest = 1;
  +test_pm_refresh();
   }
   
   sub plan {
  @@ -51,6 +55,33 @@
   }
   
   Test::plan(@_);
  +}
  +
  +package Apache::TestToString;
  +
  +sub TIEHANDLE {
  +my $string = "";
  +bless \$string;
  +}
  +
  +sub PRINT {
  +my $string = shift;
  +$$string .= join '', @_;
  +}
  +
  +sub start {
  +tie *STDOUT, __PACKAGE__;
  +Apache::Test::test_pm_refresh();
  +}
  +
  +sub finish {
  +my $s;
  +{
  +my $o = tied *STDOUT;
  +$s = $$o;
  +}
  +untie *STDOUT;
  +$s;
   }
   
   1;
  
  
  



cvs commit: modperl-2.0/Apache-Test/lib/Apache Test.pm

2001-04-02 Thread dougm

dougm   01/04/02 01:53:06

  Added:   Apache-Test/lib/Apache Test.pm
  Log:
  Test.pm wrapper to run under mod_perl
  
  Revision  ChangesPath
  1.1  modperl-2.0/Apache-Test/lib/Apache/Test.pm
  
  Index: Test.pm
  ===
  package Apache::Test;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Test qw(ok);
  use Exporter ();
  
  our @ISA = qw(Exporter);
  our @EXPORT = qw(ok plan);
  our $VERSION = '0.01';
  
  #so Perl's Test.pm can be run inside mod_perl
  sub init_test_pm {
  my $r = shift;
  
  if (defined &Apache::RequestRec::puts) {
  package Apache::RequestRec;
  unless (defined &PRINT) {
  *PRINT = \&puts;
  }
  tie *STDOUT, __PACKAGE__, $r;
  }
  else {
  $r->send_http_header; #1.xx
  }
  
  $r->content_type('text/plain');
  
  $Test::TESTOUT = \*STDOUT;
  $Test::planned = 0;
  $Test::ntest = 1;
  }
  
  sub plan {
  init_test_pm(shift) if ref $_[0];
  
  my $condition = pop @_ if ref $_[-1];
  if ($condition and ! $condition->()) {
  print "0..1\n";
  exit; #XXX: Apache->exit
  }
  
  Test::plan(@_);
  }
  
  1;