Test::Effects

Test all effects at once: return, I/O, warning, exceptions, etc
Download

Test::Effects Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Damian Conway
  • Publisher web site:
  • http://search.cpan.org/~dconway/

Test::Effects Tags


Test::Effects Description

Test::Effects is a Perl module that provides a single exported subroutine: effects_ok.This sub expects a block of code (or sub ref) as its first argument, followed by an optional hash ref as its second, and an optional string as its third.The first argument specifies some code to be tested. This code is run in void context by default, but may instead be called in either list or scalar context, depending on the test specification provided by the second argument. The block is run within a call to Test::Trap::trap(), so all warnings, exceptions, output, and exit attempts are trapped. The block may contain calls to other Test::Builder-based testing modules; these are handled correctly within the overall test.The second argument is a hash reference, whose entries specify the expected side-effects of executing the block. You specify the name of the side-effect you're interested in as the key, and the "effect" you expected as the value. Side-effects that are not explicitly specified are automatically tested for default behaviour (e.g. no warnings, no exceptions, no output, not call to exit(), etc. If the entire hash is omitted, all possible side-effects are tested for default behaviour (in other words, did the block of code have no side-effects whatsoever?)The third argument is the overall description of the test (i.e. the usual final argument for Perl tests). If omitted, effects_ok() generates a description based on the line number at which it was called.SYNOPSIS use Test::Effects; # Test all possible detectable side-effects of some code... effects_ok { your_code_here() } { return => $expected_scalar_context_return_value, warn => qr/match expected warning text/, stdout => '', # i.e. Doesn't print anything. } => 'Description of test'; # Test only specifically requested side-effects of some code... effects_ok { your_code_here() } only { return => \@expected_list_context_return_values, stderr => 'Expected output to STDERR', die => undef, # i.e. Doesn't die. exit => undef, # i.e. Doesn't exit either. } => 'Description of test'; # Test that some code has no detectable side-effects... effects_ok { your_code_here() };Product's homepage


Test::Effects Related Software