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 opened IO::File object
  • $REGEX β€” a regex created with qr//
  • $REGEX_OBJ β€” a regex created with qr// that was then blessed into class
  • $FAKE_REGEX β€” a non-regex blessed into the Regexp class which Perl uses internally for qr// 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 🌟


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