GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  TEST::STREAM::PLUGIN::WARNINGS (3)

.ds Aq ’

NAME

Test::Stream::Plugin::Warnings - Simple tools for testing code that may generate warnings.

CONTENTS

DEPRECATED

<B>This distribution is deprecatedB> in favor of Test2, Test2::Suite, and Test2::Workflow.

See Test::Stream::Manual::ToTest2 for a conversion guide.

SYNOPSIS



    # Load the Warnings plugin, and Core cause we need that as well.
    use Test::Stream qw/Core Warnings/;

    # Returns undef if there are no warnings.
    ok(!warns { ... }, "Codeblock did not warn");

    is_deeply(
        warns { warn "foo\n"; warn "bar\n" },
        [
            "foo\n",
            "bar\n",
        ],
        "Got expected warnings"
    );

    # Dies if there are 0 warnings, or 2+ warnings, otherwise returns the 1 warning.
    like( warning { warn xxx }, qr/xxx/, "Got expected warning");



EXPORTS

$warnings = warns { ... } If the codeblock issues any warnings they will be captured and returned in an arrayref. If there were no warnings this will return undef. You can be sure this will always be undef, or an arrayref with 1 or more warnings.



    # Returns undef if there are no warnings.
    ok(!warns { ... }, "Codeblock did not warn");

    is_deeply(
        warns { warn "foo\n"; warn "bar\n" },
        [
            "foo\n",
            "bar\n",
        ],
        "Got expected warnings"
    );



$warning = warning { ... } Only use this for code that should issue exactly 1 warning. This will throw an exception if there are no warnings, or if there are multiple warnings.



    like( warning { warn xxx }, qr/xxx/, "Got expected warning");



These both die:



    warning { warn xxx; warn yyy };
    warning { return };



$bool = no_warnings { ... } This will return true if there are no warnings in the codeblock. This will return false, and print the warnings if any are encountered.



    ok(no_warnings { ... }, "Did not warn.");



This is sometimes more useful that checking !warns { ... } since it lets you see the warnings when it fails.

SOURCE

The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2015 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 TEST::STREAM::PLUGIN::WARNINGS (3) 2016-02-05

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.