Giter VIP home page Giter VIP logo

test-fatal-matchfor's Introduction

NAME
    Test::Fatal::matchfor - match exceptions by class name or regexp

SYNOPSIS
    Let's say you're testing the following Moose class...

       package Goose {
          use Moose;
          has feather_count => (is => 'rw', isa => 'Int');
       }

    In Moose 2.1102 and above, exception objects are thrown, but in earlier
    versions of Moose, only string errors are given.

    So we might want to test it something like this:

       use Test::More;
       use Test::Fatal;
   
       use Goose;
   
       my $e = exception {
          Goose->new(feather_count => 3.1)
       };
   
       ref($e)
          ? isa_ok($e, 'Moose::Exception::ValidationFailedForTypeConstraint')
          : like($e, qr{does not pass the type constraint})

    This module provides a small shortcut for that pattern:

       use Test::More;
       use Test::Fatal;
       use Test::Fatal::matchfor;
   
       use Goose;
   
       my $e = exception {
          Goose->new(feather_count => 3.1)
       };
   
       is(
          $e,
          matchfor(
             'Moose::Exception::ValidationFailedForTypeConstraint',
             qr{does not pass the type constraint},
          ),
       );

DESCRIPTION
    Test::Fatal::matchfor exports the `matchfor` function which accepts a list
    of class/role names and regular expressions, and constructs an object
    overloading `==` and `eq` to return true if compared for equality against
    a string that matches one of those regular expressions, or an object that
    isa/does one of those class/role names.

    So for example, to check a type constraint error in Moose, you might use:

       my $tc_err = matchfor(
          'Moose::Exception::ValidationFailedForTypeConstraint',
          'Moose::Exception::ValidationFailedForInlinedTypeConstraint',
          qr{does not pass the type constraint},
       ),
   
       is($exception, $tc_err, "encountered error as expected");

BUGS
    Please report any bugs to
    <http://rt.cpan.org/Dist/Display.html?Queue=Test-Fatal-matchfor>.

SEE ALSO
    Test::Fatal, Moose::Exception.

AUTHOR
    Toby Inkster <[email protected]>.

COPYRIGHT AND LICENCE
    This software is copyright (c) 2013 by Toby Inkster.

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

DISCLAIMER OF WARRANTIES
    THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
    MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

test-fatal-matchfor's People

Contributors

tobyink avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.