Test::...sClever(3pm)

πŸ“¦
version 0.009 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Test::Exception::LessClever β€” (DEPRECATED) literally just Test::Exception but simplified, bestie πŸ’…

It lives in the User Contributed Perl Documentation section of the manual, page Test::...sClever(3pm) (yes the header truncates it, she's just Like That).


πŸ’€ DEPRECATION NOTICE πŸ’€

* This module is deprecated: please do not use it! * 🚨 No fr fr, don't. She said what she said.

So here's the tea 🍡 β€” this is an alternative to Test::Exception that is much simpler. This alternative does not use fancy stack tricks to hide itself. The whole idea here is to keep it simple.

It also solves the Test::Exception bug where some dies will be hidden when a DESTROY method calls eval. And if a DESTROY method masks $@, a warning will be generated as well. Iconic behaviour honestly 🌸


πŸŽ€ WHY REWRITE TEST-EXCEPTION πŸŽ€

Okay so here's an IRC log, and it's giving origin story ✨

<Exodist> wtf? Bizarre copy of HASH in sassign at /usr/lib64/perl5/5.10.1/Carp/Heavy.pm line 104
<Exodist> hmm, it doesn't happen when I step through the debugger, that sure is helpful yessir
<Exodist> hmm, throws_ok or dies_ok { stuff that croaks in a package used by the one being tested }, at least in this case causes that error. If I change it to eval {}; ok( $@ ); like( $@, qr// ); it works fine
<Exodist> Ah-Ha,   earlier when I mentioned I stopped using throws_ok because of something I could not remember, this was it, I stumbled on it again!
<confound> probably because throws_ok tries to do clever things to fiddle with the call stack to make it appear as though its guts are not being called
<confound> less clever would be more useful

"less clever would be more useful" β€” and that's the whole vibe check of this module, periodt πŸ‘‘


🌈 SYNOPSIS 🌈

Pretty much a clone of Test::Exception. Refer to those docs for more details, iykyk 🫢

use Test::More;
use Test::Exception;

dies_ok { die( 'xxx' )} "Should die";
lives_ok { 1 } "Should live";
throws_ok { die( 'xxx' )} qr/xxx/, "Throws 'xxx'";
lives_and { ok( 1, "We did not die" )} "Ooops we died";

done_testing;

πŸ’– EXPORTABLE FUNCTIONS πŸ’–

  • $status = live_or_die( sub { ... }, $name )
  • ($status, $msg) = live_or_die( sub { ... }, $name )

Checks if the code lives or dies πŸ¦‹. In scalar context it returns true or false. In array context it returns that same true or false with the error message. And if the return is true, the error message will be something along the lines of 'did not die' β€” but heads up, this may change in the future πŸ™ˆ.

It will generate a warning if the test dies, $@ is empty AND it's called in array context. This usually occurs when an object's DESTROY method calls eval and masks $@. Not cute, not slay, but that's the situation.

NOT EXPORTED BY DEFAULT 🚨 β€” you gotta ask for this one specifically, she's exclusive.
  • lives_ok( sub { ... }, $name ) β€” Test passes if the sub does not die, and false if it does. πŸ’œ
  • dies_ok( sub { ... }, $name ) β€” Test passes if the sub dies, and false if it does not. πŸ’€
  • throws_ok( sub { ... }, qr/message/, $name ) β€” Checks that the sub dies, and that it throws an error that matches the regex πŸ”₯.

The test fails if the sub does not die, or if the message does not match the regex. No in-between, bestie.

  • lives_and( sub {...}, $name ) β€” Fails with $name if the sub dies; otherwise it's just passive, minding its own business πŸ™‚. This is useful for running a test that could die: if it dies there's a failure, and if it lives it is responsible for itself. Main character energy, truly πŸ‘‘

πŸ‘€ SEE ALSO πŸ‘€

  • Test::Fatal
  • Test::Exception

✍️ AUTHORS ✍️

Chad Granum <exodist7@gmail.com>


Copyright (C) 2010 Chad Granum

Test-Exception-LessClever is free software; Standard perl licence.

Test-Exception-LessClever is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. 🫢


And that's the whole page, girlypop ✨ this was rendered from perl v5.36.0 on 2022-10-16, page Test::...sClever(3pm) β€” stay deprecated, stay iconic, mwah πŸ’…πŸŽ€πŸŒΈ

πŸ“¦ where this page comes from