Author: jkeenan Date: Wed Feb 21 20:34:29 2007 New Revision: 17137 Added: branches/buildtools/lib/Parrot/IO/Capture/ branches/buildtools/lib/Parrot/IO/Capture/Mini.pm - copied, changed from r17060, /branches/buildtools/t/tools/ops2cutils/testlib/Capture.pm Removed: branches/buildtools/t/tools/ops2cutils/testlib/Capture.pm
Log: Moved t/tools/ops2cutils/testlib/Capture.pm to become Parrot::IO::Capture::Mini, thereby making its functionality (capture warnings and error messages for later analysis during testing) available to Parrot more generally. Copied: branches/buildtools/lib/Parrot/IO/Capture/Mini.pm (from r17060, /branches/buildtools/t/tools/ops2cutils/testlib/Capture.pm) ============================================================================== --- /branches/buildtools/t/tools/ops2cutils/testlib/Capture.pm (original) +++ branches/buildtools/lib/Parrot/IO/Capture/Mini.pm Wed Feb 21 20:34:29 2007 @@ -1,9 +1,7 @@ # Copyright (C) 2006, The Perl Foundation. # $Id$ -package Capture; +package Parrot::IO::Capture::Mini; use strict; -# Adapted from IO::Capture::Tie_STDx. -# Thanks as always to Mark Reynolds and Jon Morgan! sub TIEHANDLE { my $class = shift; @@ -21,3 +19,52 @@ } 1; + +################### DOCUMENTATION ################### + +=head1 NAME + +Parrot::IO::Capture::Mini - capture messages printed to STDOUT or STDERR during Parrot testing + +=head1 SYNOPSIS + + use Parrot::IO::Capture::Mini; + +Tie C<STDOUT> or C<STDERR>. + + $tie = tie *STDERR, "Parrot::IO::Capture::Mini" or croak "Unable to tie"; + +Call a function which is likely to generate a warning or error message. + + $self = Parrot::Ops2c::Utils->new( { + argv => [ qw( CSwitch dan.ops dan.ops ) ], + flag => { dynamic => 1 }, + } ); + +Store what was captured in a variable, then C<untie>. + + $msg = $tie->READLINE; + untie *STDERR or croak "Unable to untie"; + +Use that variable in a test. + + like($msg, + qr/Ops file 'dan\.ops' mentioned more than once!/, + "Got expected error message about mentioning same file twice"); + +=head1 DESCRIPTION + +This package provides the bare minimum level of functionality needed to +capture messages printed to C<STDOUT> or C<STDERR> by Parrot build tools +written in Perl 5. + +=head1 AUTHOR + +Adapted by Jim Keenan from CPAN module IO::Capture::Tie_STDx. Thanks as +always to the authors of IO::Capture, Mark Reynolds and Jon Morgan! + +=head1 SEE ALSO + +IO::Capture (L<http://search.cpan.org/dist/IO-Capture/>). + +=cut