Acme-EyeDrops

 view release on metacpan or  search on metacpan

t/19_surrounds.t  view on Meta::CPAN

   my $fromdrops = "$fromdir/lib/Acme/EyeDrops";
   my $todrops   = "$todir/lib/Acme/EyeDrops";
   File::Path::mkpath($todrops, 0, 0777) or
      die "error: mkpath '$todrops': $!";

   local *D;
   opendir(D, $fromdrops) or die "error: opendir '$fromdrops': $!";
   my @eye = grep(/\.ey[ep]$/, readdir(D));
   closedir(D);

   for my $f (@eye) {
      File::Copy::copy("$fromdrops/$f", "$todrops/$f")
         or die "error: File::Copy::copy '$f': $!";
   }
   build_file("$todir/lib/Acme/EyeDrops.pm", eye_drop_eyedrops_pm());
}

# --------------------------------------------------

my $genbase = 'knob';

my $base = File::Basename::dirname($0);
# In the normal case, $base will be set to 't'.
# If you are naughtily running the tests from the t directory,
# base will probably be set to '.'.
my $frombase = $base eq 't' ? '.' : '..';

rm_f_dir($genbase);
create_eyedrops_tree($frombase, $genbase);

# --------------------------------------------------
# This saving and re-directing of STDOUT/STDERR in temporary files
# (implemented in test_one() below) is simple but not very clean.
# An alternative may be to use tie in some way, for example:
#    my $knob;
#    package MyStdout;
#    sub TIEHANDLE {
#       my $class = shift;
#       bless [], $class;
#    }
#    sub PRINT { my $self = shift; $knob .= join('', @_) }
#    sub PRINTF {
#       my $self = shift; my $fmt = shift;
#       $knob .= sprintf($fmt, @_);
#    }
#    package main;
#    tie *STDOUT, 'MyStdout';
# See, for example, TieOut.pm in the t/lib directory of ExtUtils-MakeMaker.
# (TieOut.pm is a little invention of chromatic's).

my $outf = 'out.tmp';
my $errf = 'err.tmp';
-f $outf and (unlink($outf) or die "error: unlink '$outf': $!");
-f $errf and (unlink($errf) or die "error: unlink '$errf': $!");

my $itest = 0;

sub test_one {
   my ($e, $rtests) = @_;

   local *SAVERR; open(SAVERR, ">&STDERR");  # save original STDERR
   local *SAVOUT; open(SAVOUT, ">&STDOUT");  # save original STDOUT
   open(STDOUT, '>'.$outf) or die "Could not create '$outf': $!";
   open(STDERR, '>'.$errf) or die "Could not create '$errf': $!";
   my $status = Test::Harness::runtests(@{$rtests});
   # XXX: Test harness does not like the next two closes.
   # close(STDOUT) or die "error: close STDOUT: $!";
   # close(STDERR) or die "error: close STDERR: $!";
   open(STDERR, ">&SAVERR") or die "error: restore STDERR: $!";
   open(STDOUT, ">&SAVOUT") or die "error: restore STDOUT: $!";
   # XXX: is this necessary to prevent leaks?
   close(SAVOUT) or die "error: close SAVOUT: $!";
   close(SAVERR) or die "error: close SAVERR: $!";

   my $outstr = Acme::EyeDrops::_slurp_tfile($outf);
   my $errstr = Acme::EyeDrops::_slurp_tfile($errf);

   print STDERR "\nstdout of TestHarness::runtests:\n$outstr\n";
   print STDERR "stderr of TestHarness::runtests:\n$errstr\n";

   $status or print "not ";
   ++$itest; print "ok $itest - TestHarness::runtests of $e\n";
}

# --------------------------------------------------

my %attrs = (
   Shape          => 'camel',
   Regex          => 0,
   Compact        => 1,
   TrapEvalDie    => 1,
   InformHandler  => sub {},
   Shape          => 'camel',
   Gap            => 1
);

my @unames = (
   '00_Coffee.t',
   '01_mug.t',
   '02_shatters.t',
   '03_Larry.t',
   '04_Apocalyptic.t',
   '05_Parrot.t',
   '06_not.t',
   '07_a.t',
   '08_hoax.t',
   '09_Gallop.t',
   '10_Ponie.t',
   '11_bold.t',
   '12_Beer.t',
   '13_to.t',
   '14_gulp.t',
   '15_Buffy.t',
   '16_astride.t',
   '17_Orange.t',
   '18_sky.t',
);
my @tests  = map("$base/$_",  @unames);
my @ztests = map("$base/z$_", @unames);

# Generate sightly-encoded versions of test programs (see also gen.t).
for my $i (0..$#unames) {



( run in 2.443 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )