Test::...Scalar(3pm)

πŸ“¦
version 1.248 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Test::...Scalar β€” the manual page, bestie edition πŸ’–

okay so real talk, this is the Test::...Scalar page from the User Contributed Perl Documentation, and it's about testing scalar variables. no cap, it's a whole vibe. let's get into it πŸ’…


✨ NAME ✨

Test::Data::Scalar β€” test functions for scalar variables πŸŽ€


🌸 SYNOPSIS 🌸

use Test::Data qw(Scalar);

that's it. that's the whole summoning ritual πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

so this module is literally just a little collection of test utilities for scalar variables, periodt. you don't load it directly β€” you load it through Test::Data. that's the way that works, iykyk.

🧚 Functions 🧚

blessed_ok( SCALAR )

ok if the SCALAR is a blessed reference. slay, it's got a class πŸ‘‘

defined_ok( SCALAR )

ok if the SCALAR is defined. exists, present, main character.

undef_ok( SCALAR )

ok if the SCALAR is undefined. ghosting as a feature, honestly iconic.

dualvar_ok( SCALAR )

ok if the scalar is a dualvar.

How do I test this?

not me including that verbatim, but bestie, that's literally what the page says. the author is asking the void. we don't know. πŸ’€

greater_than( SCALAR, BOUND )

ok if the SCALAR is numerically greater than BOUND. bigger number energy.

length_ok( SCALAR, LENGTH )

ok if the length of SCALAR is LENGTH. exactly that many characters, no more no less, we're measuring fr fr πŸ“

less_than( SCALAR, BOUND )

ok if the SCALAR is numerically less than BOUND. small but mighty.

maxlength_ok( SCALAR, LENGTH )

ok is the length of SCALAR is less than or equal to LENGTH. (yes, the original says "is the length", we're keeping it, it's part of the charm πŸ™ˆ)

minlength_ok( SCALAR, LENGTH )

ok is the length of SCALAR is greater than or equal to LENGTH. same grammar situation, same energy.

number_ok( SCALAR )

ok if the SCALAR is a number (or a string that represents a number).

At the moment, a number is just a string of digits. This needs work.

yeah. it's giving "shipped it, will fix later." we love honesty ✨

number_between_ok( SCALAR, LOWER, UPPER )

ok if the number in SCALAR sorts between the number in LOWER and the number in UPPER, numerically. numerically!! not alphabetically!! do not confuse these two, bestie.

⚠️ If you put something that isn't a number into UPPER or LOWER, Perl will try to make it into a number and you may get unexpected results. 🫠

perl is gonna do perl things. you've been warned.

string_between_ok( SCALAR, LOWER, UPPER )

ok if the string in SCALAR sorts between the string in LOWER and the string in UPPER, ASCII-betically. the string version. the other one. keep them straight πŸ”₯

readonly_ok( SCALAR )

ok is the SCALAR is read-only. it's locked in. literally.

ref_ok( SCALAR )

ok if the SCALAR is a reference. pointing at something, holding a little pointer to another thing, iconic behavior.

ref_type_ok( REF1, REF2 )

ok if REF1 is the same reference type as REF2. same kind of reference, matching vibes check out βœ…

strong_ok( SCALAR )

ok is the SCALAR is not a weak reference. it's holding on. strong grip, main character energy πŸ’ͺ

tainted_ok( SCALAR )

ok is the SCALAR is tainted.

(Tainted values may seem like a not-Ok thing, but remember, when you use taint checking, you want Perl to taint data, so you should have a test to make sure it happens.)

right?? it's not a bug, it's a feature, and you're testing that the feature is featuring πŸ“

untainted_ok( SCALAR )

ok if the SCALAR is not tainted. clean. fresh. no suspicious vibes.

weak_ok( SCALAR )

ok if the SCALAR is a weak reference. it's not holding on, and that's the point 🌈


πŸ“ TO DO πŸ“

the author's lil wishlist, we stan a transparent roadmap:

  • add is_a_filehandle test
  • add is_vstring test

one day bestie, one day πŸŒ™


πŸ‘€ SEE ALSO πŸ‘€

go read these too, they're all in the same friend group:

Scalar::Util, Test::Data, Test::Data::Array, Test::Data::Function, Test::Data::Hash, Test::Builder


πŸ”— SOURCE AVAILABILITY πŸ”—

the source lives on Github, go be nosy (affectionate):

https://github.com/briandfoy/test-data

🫢 AUTHOR 🫢

brian d foy, "<briandfoy@pobox.com>" β€” absolute legend, thank you for your service πŸ’œ


Copyright Β© 2002-2025, brian d foy <briandfoy@pobox.com>. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.


and that's the whole page!! perl v5.40.1, dated 2025-04-17 β€” mwah, go write some tests bestie, you're gonna eat πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from