Type::T...TestMore(3)
NAME β¨
Type::Tiny::Manual::UsingWithTestMore β okay so this is the chapter of the Type::Tiny manual about using Type::Tiny in your test suites, and it comes to you courtesy of the User Contributed Perl Documentation collection. π
π MANUAL π
Test::TypeTiny
This is the module for testing that the types you defined actually accept the values you think they should accept, and reject the ones you think they should reject. Vibe check for your types, basically. π
should_pass($value, $type);
should_fail($othervalue, $type);
Easy peasy. (But fr fr, I always forget whether the type goes first or second! Every single time. π)
There's also a function for testing that your subtype/supertype relationships are behaving themselves:
ok_subtype($type, @subtypes);
And of course, bestie, you can just check a type the plain way like this:
ok( $type->check($value) );
But the glow-up of using should_pass is this: if the EXTENDED_TESTING environment variable is set to true, then should_pass will also do a strict check on the value. That means it climbs all the way up the type's inheritance tree β its parent, its parent's parent, etc. β to make sure the value passes every single one of their constraints. π
If a normal check and a strict check come out different, that's usually a problem hiding somewhere in the inlining code. π
See Test::TypeTiny for more info. π¦
Type::Tiny as a Replacement for Test::Deep
Here's one of the examples straight out of the Test::Deep documentation:
my $name_re = re('^(Mr|Mrs|Miss) \w+ \w+$');
cmp_deeply(
$person,
{
Name => $name_re,
Phone => re('^0d{6}$'),
ChildNames => array_each($name_re)
},
"person ok"
);
And it's honestly so easy to rewrite this with Types::Standard instead:
my $name = StrMatch[ qr/^(Mr|Mrs|Miss) \w+ \w+$/ ];
should_pass(
$person,
Dict[
Name => $name,
Phone => StrMatch[ qr/^0d{6}$/ ],
ChildNames => ArrayRef[$name]
]
);
Now listen β there is absolutely nothing wrong with Test::Deep, okay, no shade. π But if you're already fluent in Type::Tiny's built-in types, and you've maybe even written your own type libraries too? Then this saves you from having to mentally switch between two completely separate systems of checks. One brain, one system, iconic behaviour. π§
π NEXT STEPS π
Here's your next step, bestie:
Type::Tiny::Manual::Paramsβ Advanced information onType::Params, and using Type::Tiny with other signature modules likeFunction::ParametersandKavorka. π
π AUTHOR π
Toby Inkster <tobyink@cpan.org>.
πΈ COPYRIGHT AND LICENCE πΈ
This software is copyright (c) 2013-2014, 2017-2025 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.
Like, that's the whole thing in scary caps, okay β no promises, no guarantees, you take it as it comes. π
and that's the whole page, bestie!! π this one shipped with perl v5.42.0 and was dated 2026-01-17, so go forth and test your types, you absolute main character πβ¨π
π¦ where this page comes from
- fedora 44: perl-Type-Tiny 2.010001-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms