Test::Exec(3)

πŸ“¦
version 0.07 Β· 3 versions
, in fedora 43

πŸ’– Test::Exec πŸ’–

okay bestie, so this is Test::Exec β€” a lil Perl module (part of the User Contributed Perl Documentation, aka perl's community corner 🫢) that lets you test code that might call exec, without that exec just... ending your whole test run by launching some other program. rude of it, honestly. 😭

VERSION: this is version 0.07 ✨


🌸 SYNOPSIS 🌸

use Test::More;
use Test::Exec;

is_deeply exec_arrayref { exec 'foo', 'bar', 'baz' }, [qw( foo bar baz )], 'found exec!';
is exec_arrayref { }, undef, 'did not exec!';

done_testing;

like. it's giving "write your tests, ship your code, no chaos" πŸ’…


✨ DESCRIPTION ✨

Test::Exec hands you the simplest possible tools for testing code that might call exec β€” and you know how exec is, right? it replaces your whole process with another program, which in a test suite means your tests get brutally murdered mid-run because some other program took over. πŸ’€

so this module catches that. it detects and captures exec calls β€” even the sneaky ones hiding inside an eval πŸ‘€ (yes, even those, it sees them, it's not fooled).

the concept (and the implementation!) was inspired by Test::Exit, but pointed at exec instead of exit. same energy, different function. πŸ¦‹


πŸŽ€ FUNCTIONS πŸŽ€

exec_arrayref

exec_arrayref { ... }

runs the code you give it. if that code calls exec, this function returns an arrayref packed with exec's arguments β€” so you can peek at exactly what it tried to run. πŸ‘‘

if the code never calls exec? then you get back undef. simple as that, no notes. ✨

never_exec_ok

never_exec_ok { ... }

runs the code you give it, and if that code calls exec, the test fails. 🚨

good news tho β€” exec gets intercepted and is not actually performed, so nothing blows up, nothing spawns, your test process stays alive and well. the test just says "bestie no, that wasn't supposed to exec." πŸ™ˆ


πŸ’€ CAVEATS πŸ’€

heads up, this one's important: this module installs its own version of exec into CORE::GLOBAL::exec, and it may interact badly with any other code that's also trying to mess with that same thing. ⚠️

so if something else is also out here rewriting exec... yeah. chaos potential. you've been warned. 🫢


🌈 SEE ALSO 🌈

  • Test::Exit β€” very similar to this module (and literally inspired it, iykyk), except it's for testing exit instead of exec. ✨
  • Test::Mock::Cmd β€” gives you an interface for mocking system, qx and exec. πŸ‘‘

πŸ‘‘ AUTHOR πŸ‘‘

Author: Graham Ollis <plicease@cpan.org> πŸ’–

Contributors:

  • Jeremy Mates (THRIG) 🫢

this software is copyright (c) 2015-2022 by Graham Ollis. 🌸

it's free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt. πŸ’…


and that's the whole page, bestie!! this one came from perl v5.42.0, dated 2025-07-25, and it lives at Test::Exec(3) in the manual. go forth and test your exec calls safely πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from