Test::Without

Run code while hiding library paths or specific modules
Download

Test::Without Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Randy J Ray
  • Publisher web site:
  • http://search.cpan.org/~rjray/

Test::Without Tags


Test::Without Description

Run code while hiding library paths or specific modules Test::Without is a Perl module that makes it easy for test scripts to exclude specific modules and/or directories from the Perl search-path during the execution of blocks of code.Developer commentsI wrote this after needing to write a fairly ugly hack for a different CPAN module, in order to test code that would try to load Compress::Zlib, but needed to test the logic paths that only execute when compression is not available. This module is not for testing whether code loads and compiles correctly; see the use_ok function of Test::More for that.The module works by creating a lexical scope in which both @INC and %INC are localized, and executing the given block within that scope. The modules (and possibly direcories) to be hidden are specified at this time. Directories that are given are immediately removed from @INC. Modules are handled by means of a subroutine inserted at the head of @INC.Conversely, the syntax can be used to require the present of specific modules, throwing an exception via die if any request resource is not available, or temporarily add extra paths to @INC. In such a case, none of the code in the provided block will have been run prior to the reporting of the missing resources.A caller can also provide parameters to be passed to the code block when it is called. This is superfluous for inline-defined blocks, but in cases where the block argument is a code-reference scalar that is being reused, this can be useful.SYNOPSIS use Test::Without; run { eval "require RPC::XML::Client"; $client = RPC::XML::Client->new(); ok(! $client->compress(), "Client has no compression support"); } without 'Compress::Zlib'; # Run a block with parameters run { my %args = @_; eval "require RPC::XML::Server"; $server = RPC::XML::Server->new(@_); is($server->port, $args{port}, "Port set correctly"); is($server->path, $args{path}, "Path set correctly"); # Etc. } without 'Compress::Zlib', 'Net::Server', params port => 9000, path => '/RPC'; Requirements: · Perl


Test::Without Related Software