1Type::Tiny::Manual::UsiUnsgeWritChoTnetsrtiMbourtee(d3T)Pyeprel::DToicnuym:e:nMtaantuiaoln::UsingWithTestMore(3)
2
3
4
6 Type::Tiny::Manual::UsingWithTestMore - Type::Tiny for test suites
7
9 Test::TypeTiny
10 This is a module for testing that types you've defined accept and
11 reject the values you think they should.
12
13 should_pass($value, $type);
14 should_fail($othervalue, $type);
15
16 Easy. (But yeah, I always forget whether the type goes first or
17 second!)
18
19 There's also a function to test that subtype/supertype relationships
20 are working okay.
21
22 ok_subtype($type, @subtypes);
23
24 Of course you can just check a type like this:
25
26 ok( $type->check($value) );
27
28 But the advantage of "should_pass" is that if the "EXTENDED_TESTING"
29 environment variable is set to true, "should_pass" will also perform a
30 strict check on the value, which involves climbing up the type's
31 inheritance tree (its parent, its parent's parent, etc) to make sure
32 the value passes all their constraints.
33
34 If a normal check and strict check differ, this is usually a problem in
35 the inlining code somewhere.
36
37 See Test::TypeTiny for more information.
38
39 Type::Tiny as a Replacement for Test::Deep
40 Here's one of the examples from the Test::Deep documentation:
41
42 my $name_re = re('^(Mr|Mrs|Miss) \w+ \w+$');
43 cmp_deeply(
44 $person,
45 {
46 Name => $name_re,
47 Phone => re('^0d{6}$'),
48 ChildNames => array_each($name_re)
49 },
50 "person ok"
51 );
52
53 It's pretty easy to rewrite this to use Types::Standard:
54
55 my $name = StrMatch[ qr/^(Mr|Mrs|Miss) \w+ \w+$/ ];
56 should_pass(
57 $person,
58 Dict[
59 Name => $name,
60 Phone => StrMatch[ qr/^0d{6}$/ ],
61 ChildNames => ArrayRef[$name]
62 ]
63 );
64
65 There's nothing especially wrong with Test::Deep, but if you're already
66 familiar with Type::Tiny's built-in types and you've maybe written your
67 own type libraries too, it will save you having to switch between using
68 two separate systems of checks.
69
71 Here's your next step:
72
73 • Type::Tiny::Manual::Params
74
75 Advanced information on Type::Params, and using Type::Tiny with
76 other signature modules like Function::Parameters and Kavorka.
77
79 Toby Inkster <tobyink@cpan.org>.
80
82 This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.
83
84 This is free software; you can redistribute it and/or modify it under
85 the same terms as the Perl 5 programming language system itself.
86
88 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
89 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
90 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
91
92
93
94perl v5.38.0 2023-T0y7p-e2:1:Tiny::Manual::UsingWithTestMore(3)