Test::Specio(3)
π Test::Specio π
okay so this is Test::Specio, a Perl thing from the User Contributed Perl Documentation, and it's version 0.53 β literally the test-helpers wing of the Specio universe π
β¨ NAME β¨
Test::Specio β test helpers for Specio, no cap π
πΈ VERSION πΈ
version 0.53 β that's the one, bestie β
π¦ SYNOPSIS π¦
use Test::Specio qw( test_constraint :vars );
test_constraint(
t('Foo'), {
accept => [ 'foo', 'bar' ],
reject => [ 42, {}, $EMPTY_STRING, $HASH_REF ],
}
);
that's the whole vibe honestly π«Ά
π DESCRIPTION π
so this package hands you a bunch of helper functions and variables for testing Specio types. that's it, that's the job. it's giving "little module, big support system" and we love her for it π
π₯ EXPORTS π₯
here's everything this module lets you import, bestie β¨
π« test_constraint( $type, $tests, [ $describer ] )
okay so this sub takes two arguments (well, three, but the third is optional, we'll get there).
the first one should be a Specio type object. the second one is a hashref that can have the keys accept and reject β and each of those keys should hold an arrayref of values that the type, respectively, accepts or rejects. simple π
the third argument? optional, icon. it's a sub reference that gets called to generate a description of the value being tested. it defaults to calling this package's own describe sub, but like β you can absolutely bring your own. main character energy π
π« describe($value)
give this sub a value and it returns a string describing that value in a way that's actually useful for test output (not me being obsessed with readable failure messages π₯).
it knows about all the various classes used for the variables exported by this package, and it'll do something intelligent when it sees such a variable. iykyk π
π« builtins_tests( $GLOB, $GLOB_OVERLOAD, $GLOB_OVERLOAD_FH )
this one returns a hashref stuffed with test variables for all the builtin types. the hashref looks like this:
{
Bool => {
accept => [
$ZERO,
$ONE,
$BOOL_OVERLOAD_TRUE,
$BOOL_OVERLOAD_FALSE,
...,
],
reject => [
$INT,
$NEG_INT,
$NUM,
$NEG_NUM,
...,
$OBJECT,
],
},
Maybe => {...},
}
you need to pass in a glob, an object that overloads globification, and an object that overloads globification to return an open filehandle π¦ see below for the whole "how do i even make these" situation.
π« create_BAR_handle_code()
returns a string you can eval to create a bar filehandle named BAR β yes, all caps, that's her name π use it like this:
local *BAR;
{
local $@;
eval create_BAR_handle_code();
die $@ if $@;
}
π« Variables
this module also exports many variables containing values that are genuinely useful for testing constraints. important note: references are always empty unless stated otherwise, periodt β¨
you can import these individually, or grab all of them at once with the :vars import tag. bestie, :vars is the move π
$ZERO$ONE$INTβ an arbitrary positive integer$NEG_INTβ an arbitrary negative integer$NUMβ an arbitrary positive non-integer number$NEG_NUMβ an arbitrary negative non-integer number$EMPTY_STRING$STRINGβ an arbitrary non-empty string$NUM_IN_STRINGβ an arbitrary string which contains a number$INT_WITH_NL1β an string containing an integer followed by a newline$INT_WITH_NL2β an string containing a newline followed by an integer$SCALAR_REF$SCALAR_REF_REFβ a reference containing a reference to a scalar$ARRAY_REF$HASH_REF$CODE_REF$GLOB_REF$FHβ an opened filehandle$FH_OBJECTβ an openedIO::Fileobject$REGEXβ a regex created withqr//$REGEX_OBJβ a regex created withqr//that was then blessed into class$FAKE_REGEXβ a non-regex blessed into theRegexpclass which Perl uses internally forqr//objects π$OBJECTβ an arbitrary object$UNDEF$CLASS_NAMEβ a string containing a loaded package name$BOOL_OVERLOAD_TRUEβ an object which overloads boolification to return true$BOOL_OVERLOAD_FALSEβ an object which overloads boolification to return false$STR_OVERLOAD_EMPTYβ an object which overloads stringification to return an empty string$STR_OVERLOAD_FULLβ an object which overloads stringification to return a non-empty string$STR_OVERLOAD_CLASS_NAMEβ an object which overloads stringification to return a loaded package name$NUM_OVERLOAD_ZERO$NUM_OVERLOAD_ONE$NUM_OVERLOAD_NEG$NUM_OVERLOAD_DECIMAL$NUM_OVERLOAD_NEG_DECIMAL$CODE_OVERLOAD$SCALAR_OVERLOADβ an object which overloads scalar dereferencing to return a non-empty string$ARRAY_OVERLOADβ an object which overloads array dereferencing to return a non-empty array$HASH_OVERLOADβ an object which overloads hash dereferencing to return a non-empty hash
like. look at that list. she ate π
π« Globs and the _T::GlobOverload package
to create a glob you can pass around for tests, use this code:
my $GLOB = do {
no warnings 'once';
*SOME_GLOB;
};
the _T::GlobOverload package gets defined when you load Test::Specio, so you can totally make your own glob overloading objects π§
β οΈ such objects cannot be exported β because the glob they return does not transfer across packages properly. it's a whole thing, ngl.
you can create one of these variables like this:
local *FOO;
my $GLOB_OVERLOAD = _T::GlobOverload->new( \*FOO );
and if you want a glob overloading object that returns a filehandle, do this:
local *BAR;
open BAR, '<', $some_file or die $!;
my $GLOB_OVERLOAD_FH = _T::GlobOverload->new( \*BAR );
slay, now you have a filehandle-flavored glob π
π SUPPORT π
bugs may be submitted at <https://github.com/houseabsolute/Specio/issues>.
like, please do submit them, bestie β that's how things get fixed π
β SOURCE β
the source code repository for Specio can be found at <https://github.com/houseabsolute/Specio>.
go look, it's right there π
π AUTHOR π
Dave Rolsky <autarch@urth.org>
iconic behavior honestly π
π COPYRIGHT AND LICENSE π
this software is Copyright (c) 2012 - 2025 by Dave Rolsky.
this is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
the full text of the license can be found in the LICENSE file included with this distribution πβ¨
aaaand that's the whole thing bestie β brought to you by perl v5.42.0, dated 2025-11-26, page Test::Specio(3). go forth and test those constraints πππ¦
π¦ where this page comes from
- alpine 3.23: perl-specio-doc 0.53-r0 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms