1Test::Deep::Type(3)   User Contributed Perl Documentation  Test::Deep::Type(3)
2
3
4

NAME

6       Test::Deep::Type - A Test::Deep plugin for validating type constraints
7

VERSION

9       version 0.008
10

SYNOPSIS

12           use Test::More;
13           use Test::Deep;
14           use Test::Deep::Type;
15           use MooseX::Types::Moose 'Str';
16
17           cmp_deeply(
18               {
19                   message => 'ack I am slain',
20                   counter => 123,
21               },
22               {
23                   message => is_type(Str),
24                   counter => is_type(sub { die "not an integer" unless int($_[0]) eq $_[0] }),
25               },
26               'message is a plain string, counter is a number',
27           );
28

DESCRIPTION

30       This is a Test::Deep plugin that provides the sub "is_type" to indicate
31       that the data being tested must validate against the passed type. This
32       is an actual type object, not a string name -- for example something
33       provided via MooseX::Types, or a plain old coderef that returns a bool
34       (such as what might be used in a Moo type constraint).
35

FUNCTIONS

37   "is_type"
38       Exported by default; to be used within a Test::Deep comparison function
39       such as cmp_deeply.  As this module aims to be a solution for many
40       popular type systems, we attempt to use the type in multiple ways:
41
42       MooseX::Types/Moose::Meta::TypeConstraint-style types:
43           If the "validate" method exists, it is invoked on the type object
44           with the data as its parameter (which should return "undef" on
45           success, and the error message on failure).
46
47       coderef/Moo-style types:
48           If the type appears to be or act like a coderef (either a coderef,
49           blessed or unblessed, or possesses a coderef overload) the type is
50           invoked as a sub, with the data as its parameter. Its return value
51           is treated as a boolean; if it also dies with a message describing
52           the failure, this message is used in the failure diagnostics.
53
54           Type::Tiny types fall into this category, and are fully supported.
55

CAVEATS

57       Regular strings describing a type under a particular system (e.g.
58       Moose, Params::Validate) are not currently supported.
59

SEE ALSO

61       •   Test::Deep
62
63       •   Test::TypeConstraints
64
65       •   Test::Type
66
67       •   Test::Deep::Matcher
68
69       •   MooseX::Types
70
71       •   Moose::Meta::TypeConstraint
72
73       •   Moo
74
75       •   Type::Tiny
76

SUPPORT

78       Bugs may be submitted through the RT bug tracker
79       <https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Deep-Type> (or
80       bug-Test-Deep-Type@rt.cpan.org <mailto:bug-Test-Deep-
81       Type@rt.cpan.org>).
82
83       There is also a mailing list available for users of this distribution,
84       at <http://lists.perl.org/list/perl-qa.html>.
85
86       There is also an irc channel available for users of this distribution,
87       at "#perl" on "irc.perl.org" <irc://irc.perl.org/#perl-qa>.
88
89       I am also usually active on irc, as 'ether' at "irc.perl.org".
90

AUTHOR

92       Karen Etheridge <ether@cpan.org>
93

CONTRIBUTOR

95       Graham Knop <haarg@haarg.org>
96
98       This software is copyright (c) 2013 by Karen Etheridge.
99
100       This is free software; you can redistribute it and/or modify it under
101       the same terms as the Perl 5 programming language system itself.
102
103
104
105perl v5.38.0                      2023-07-21               Test::Deep::Type(3)
Impressum