Test2::Util(3)
π NAME π
Test2::Util β tools used by Test2 and friends. This is the Test2::Util(3) page from the User Contributed Perl Documentation, bestie, and we're gonna make it make sense. π
πΈ DESCRIPTION πΈ
Okay so this is a collection of tools used by Test2 and friends. That's the whole vibe: handy little utilities for the Test2 ecosystem. β¨
π§° EXPORTS π§°
All exports are optional. You must specify subs to import β no sneaky auto-import situation here, bestie. π«Ά
($success, $error) = try { ... }β Eval the codeblock, then return success or failure plus the error message. This code protects$@and$!β they get restored by the end of the run. It also temporarily blocks$SIG{DIE}handlers. πβ¨protect { ... }β Similar totry, except it does not catch exceptions. The whole idea is protecting$@and$!from changes.$@and$!will be restored to whatever they were before the run so long as it is successful. If the run fails,$!will still be restored, but$@will contain the exception being thrown. πCAN_FORKβ True if this system is capable of true or pseudo-fork. πCAN_REALLY_FORKβ True if the system can really fork. This will be false for systems where fork is emulated. πCAN_THREADβ True if this system is capable of using threads. π§΅USE_THREADSβ Returns true if threads are enabled, false if they are not. βget_tidβ Returns the id of the current thread when threads are enabled. Otherwise it returns0. πͺ‘my $file = pkg_to_file($package)β Convert a package name to a filename. π$string = ipc_separator()β Get the IPC separator. Currently this is always the string'~'. π$string = gen_uid()β Generate a unique id (NOT A UUID). This will typically be the process id, the thread id, the time, and an incrementing integer all joined with theipc_separator(). π
These IDs are unique enough for most purposes. For identical ids to be generated, you must have 2 processes with the same PID generate IDs at the same time with the same current state of the incrementing integer. This is a perfectly reasonable thing to expect to happen across multiple machines, but it is quite unlikely to happen on one machine. π«
This can fail to be unique if a process generates an id, calls exec, and does it again after the exec, and it all happens in less than a second. It can also happen if the system's process ids cycle in less than a second, allowing 2 different programs that use this generator to run with the same PID in less than a second. Both these cases are sufficiently unlikely. If you need universally unique ids, or ids that are unique in these conditions, look at Data::UUID. π
($ok, $err) = do_rename($old_name, $new_name)β Rename a file. This wrapsrename()in a way that makes it more reliable cross-platform when trying to rename files you recently altered. π($ok, $err) = do_unlink($filename)β Unlink a file. This wrapsunlink()in a way that makes it more reliable cross-platform when trying to unlink files you recently altered. ποΈ
β οΈ NOTES && CAVEATS β οΈ
π 5.10.0 π
Perl 5.10.0 has a bug when compiled with newer gcc versions. This bug causes a segfault whenever a new thread is launched. Test2 will attempt to detect this, and note that the system is not capable of forking when it is detected. π΅βπ«
π Devel::Cover π
Devel::Cover does not support threads. CAN_THREAD will return false if Devel::Cover is loaded before the check is first run. π
π SOURCE π
The source code repository for Test2 can be found at https://github.com/Test-More/test-more/. π
π MAINTAINERS π
- Chad Granum
<exodist@cpan.org>π«Ά
β¨ AUTHORS β¨
- Chad Granum
<exodist@cpan.org>π - Kent Fredric
<kentnl@cpan.org>π
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>. π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
See https://dev.perl.org/licenses/. π
π«Ά That's the whole page, bestie! Source/version vibes:perl v5.42.0, dated2025-07-28β and yes, this was theTest2::Util(3)manual. mwah π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms