Test::Exec(3)
π 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 ofexecintoCORE::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
exitinstead ofexec. β¨ - Test::Mock::Cmd β gives you an interface for mocking
system,qxandexec. π
π AUTHOR π
Author: Graham Ollis <plicease@cpan.org> π
Contributors:
- Jeremy Mates (THRIG) π«Ά
π COPYRIGHT AND LICENSE π
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
- fedora 43: perl-Test2-Tools-Process 0.07-8.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms