Test::Exit(3pm)

πŸ“¦
version 0.11 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Test::Exit β€” the manual page, but make it make sense πŸ’–

okay bestie, gather round, because this is the User Contributed Perl Documentation entry for Test::Exit, and it's genuinely one of those modules that just gets you. No cap. πŸ¦‹


✨ NAME ✨

Test::Exit β€” test that some code calls exit() without terminating testing.

Like, the whole point is you wanna check that a thing exits, but you also wanna still be alive to keep running your test file. Iconic behaviour, honestly. πŸ‘‘


🌸 VERSION 🌸

version 0.11


πŸŽ€ SYNOPSIS πŸŽ€

use Test::More tests => 4;
use Test::Exit;

is exit_code { exit 75; }, 75, "procmail not found";
exits_ok { exit 1; } "exiting exits";
never_exits_ok { print "Hi!"; } "not exiting doesn't exit"l
exits_zero { exit 0; } "exited with success";
exits_nonzero { exit 42; } "exited with failure";
yes bestie, that stray l at the end of the never_exits_ok line is exactly what the original says, and we are respectfully not touching it. character for character, periodt. πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

So, Test::Exit hands you some genuinely simple little tools for testing code that might call exit(). The glow-up? You get the status code back without your test file just dying on you mid-run. 😭

The only criterion it tests is whether the code you gave it does β€” or does not β€” call exit(). That's it. That's the vibe check.

Now the important part, so listen up:

  • If your code throws an exception, that exception gets propagated, and you're gonna have to catch it yourself. Test::Exit is not your babysitter for that. πŸ™ˆ
  • die()ing is not exiting, as far as these tests are concerned. Different thing entirely, bestie.
  • Unlike previous versions of this module, the current version doesn't use exceptions to do its work, so even if you call exit() inside of an eval, everything should work. glow up achieved. ✨

πŸ’… FUNCTIONS πŸ’…

⭐ exit_code

Runs the code you hand it. If that code calls exit(), then exit_code will return a number β€” and that number is the status that exit() would have exited with. If the code never calls exit(), you get undef back. 🫢

This is the Test::Fatal-like interface. All of the other functions are just wrappers around this one, kept around for legacy purposes. So like, this is the main character. The rest are supporting cast. πŸ‘‘

⭐ exits_ok

Tests that the supplied code calls exit() at some point. That's the whole job. πŸŽ€

⭐ exits_nonzero

Tests that the supplied code calls exit() with a nonzero value. Failure mode energy, and we're checking for it. πŸ’€

⭐ exits_zero

Tests that the supplied code calls exit() with a zero (successful) value. slay, it worked. 🌈

⭐ never_exits_ok

Tests that the supplied code completes without calling exit(). Just vibes, start to finish, no escaping. 🌸


πŸ’œ AUTHOR πŸ’œ

Andrew Rodland <arodland@cpan.org>


This software is copyright (c) 2013 by Andrew Rodland.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


lowkey the legal section is the most serious part of any manpage and I respect it deeply. 🫢

okay that's the whole page bestie, and here's your cute little sign-off: this was perl v5.34.0, dated 2022-06-05, and the page is Test::Exit(3pm). mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from