Test2::V0(3pm)

πŸ’– Test2::V0 β€” the manual, but make it a group chat πŸ’–

Okay so bestie, welcome to the manual for Test2::V0, aka the 0th edition of the Test2 recommended bundle (yes, we're counting from zero, it's a Perl thing, iykyk). This page lives in section 3pm of the Perl Programmers Reference Guide, and I'm gonna walk you through literally all of it. Buckle up. πŸŽ€


✨ NAME ✨

Test2::V0 β€” the 0th edition of the Test2 recommended bundle. She's the blueprint, the original, the main character. πŸ’…


🌸 DESCRIPTION 🌸

This is the big-daddy bundle. Like, no exaggeration β€” this bundle includes nearly every tool and several plugins that the Test2 author actually uses. It's used extensively to test Test2::Suite itself, so you know it's eating. πŸ”₯

If you want the full toolkit in one use line, this is it. Periodt.


πŸ¦‹ NAMING, USING, DEPENDING πŸ¦‹

Okay so real talk: this bundle should not change in a severely incompatible way. Some minor breaking changes β€” especially bugfixes β€” may be allowed. The vibe is "stable but not frozen." If breaking changes are genuinely needed, then a whole new Test2::V# module should be released instead. New name, new module, no chaos for existing users. πŸ’–

And listen: as new V# modules get released, old ones may be moved to different CPAN distributions. So you should always use a specific bundle version and list that version in your distribution's testing requirements. Do not just list Test2::Suite as your module dep β€” nope, not today. Instead, list the specific bundle, or the tools and plugins you use directly, in your metadata. This is the way. πŸ™


⭐ SYNOPSIS ⭐

use Test2::V0;

ok(1, "pass");

...

done_testing;

That's it. That's the whole vibe. use it, test something, done_testing, bye. 🫢


πŸ’œ RESOLVING CONFLICTS WITH MOOSE πŸ’œ

use Test2::V0 '!meta';

So here's the tea: Moose and Test2::V0 both export very different meta() subs, and they will absolutely fight over who gets to define it. Adding '!meta' to the import args will prevent the sub from being imported, conflict resolved, slay. πŸ’…

This bundle also exports the sub under the name meta_check() so you can use that spelling as an alternative. Iconic workaround, honestly.

πŸŽ€ TAGS πŸŽ€

:DEFAULT

The following are both, like, literally identical:

use Test2::V0;

use Test2::V0 ':DEFAULT';

Same energy. Same bundle. Same everything. ✨

🌈 RENAMING ON IMPORT 🌈

use Test2::V0 ':DEFAULT', '!ok', ok => {-as => 'my_ok'};

This bundle uses Test2::Util::Importer for exporting, so you can use any arguments it accepts. Flexible queen. πŸ’…

Explanation, bestie:

  • '!ok' β€” Do not export ok().
  • ok => {-as => 'my_ok'} β€” Actually, go ahead and import ok() but under the name my_ok().

And heads up: if you did not add the '!ok' argument, then you would have both ok() and my_ok(). Two of them. Double the ok. πŸ™ˆ


🧚 PRAGMAS 🧚

All of these can be disabled via individual import arguments, or by the -no_pragmas argument:

use Test2::V0 -no_pragmas => 1;

One flag to turn them all off. Powerful. πŸ‘‘

🌸 STRICT 🌸

strict is turned on for you. Automatic. No cap. You can disable this with the -no_strict or -no_pragmas import arguments:

use Test2::V0 -no_strict => 1;

πŸŽ€ WARNINGS πŸŽ€

warnings are turned on for you. Also automatic. Also no cap. You can disable this with the -no_warnings or -no_pragmas import arguments:

use Test2::V0 -no_warnings => 1;

πŸ¦‹ UTF8 πŸ¦‹

This is actually done via the Test2::Plugin::UTF8 plugin β€” see the "PLUGINS" section for the details, bestie.

Note: -no_pragmas => 1 will turn off the entire plugin. Like, the whole thing. Gone. πŸ’€

πŸ”₯ PLUGINS πŸ”₯

⭐ SRAND ⭐

See Test2::Plugin::SRand.

This will set the random seed to today's date. Cute, right? You can provide an alternate seed with the -srand import option:

use Test2::V0 -srand => 1234;

You can also disable this behavior entirely:

use Test2::V0 -no_srand => 1;
Note: When srand is on (default) it can cause problems with things like File::Temp, which will end up attempting the same "random" filenames for every test process started on a given day (or sharing the same seed). So like, same-day tests can collide. Just so you know. 😭

πŸ’œ UTF8 πŸ’œ

See Test2::Plugin::UTF8.

This will set the file, and all output handles (including formatter handles), to utf8. This will turn on the utf8 pragma for the current scope. Everything's utf8, we love to see it. ✨

This can be disabled using the -no_utf8 => 1 or -no_pragmas => 1 import arguments:

use Test2::V0 -no_utf8 => 1;

πŸŽ€ EXIT SUMMARY πŸŽ€

See Test2::Plugin::ExitSummary.

This plugin has no configuration. Zero settings. It just does its thing. Minimalist icon. πŸ’…


🌈 ENVIRONMENT VARIABLES 🌈

See Test2::Env for a list of meaningful environment variables. That's where the env lore lives. πŸ‘‘


🫢 API FUNCTIONS 🫢

See Test2::API for these:

  • $ctx = context()
  • $events = intercept { ... }

πŸ‘‘ TOOLS πŸ‘‘

🎯 TARGET 🎯

See Test2::Tools::Target.

You can specify a target class with the -target import argument. If you do not provide a target, then $CLASS and CLASS() will not be imported. No target, no import, simple as that.

use Test2::V0 -target => 'My::Class';

print $CLASS;  # My::Class
print CLASS(); # My::Class

Or you can specify names:

use Test2::V0 -target => { pkg => 'Some::Package' };

pkg()->xxx; # Call 'xxx' on Some::Package
$pkg->xxx;  # Same

πŸ’– $CLASS

Package variable that contains the target class name.

πŸ’– $class = CLASS()

Constant function that returns the target class name.

πŸ¦‹ DEFER πŸ¦‹

See Test2::Tools::Defer.

def $func => @args;
do_def()

⭐ BASIC ⭐

See Test2::Tools::Basic.

  • ok($bool, $name)
  • ok($bool, $name, @diag)
  • pass($name)
  • pass($name, @diag)
  • fail($name)
  • fail($name, @diag)
  • diag($message)
  • note($message)
  • $todo = todo($reason)
  • todo $reason => sub { ... }
  • skip($reason, $count)
  • plan($count)
  • skip_all($reason)
  • done_testing()
  • bail_out($reason)

πŸ’œ COMPARE πŸ’œ

See Test2::Tools::Compare.

  • is($got, $want, $name)
  • isnt($got, $do_not_want, $name)
  • like($got, qr/match/, $name)
  • unlike($got, qr/mismatch/, $name)
  • $check = match(qr/pattern/)
  • $check = mismatch(qr/pattern/)
  • $check = validator(sub { return $bool })
  • $check = hash { ... }
  • $check = array { ... }
  • $check = bag { ... }
  • $check = object { ... }
  • $check = meta { ... }
  • $check = number($num)
  • $check = string($str)
  • $check = bool($bool)
  • $check = check_isa($class_name)
  • $check = in_set(@things)
  • $check = not_in_set(@things)
  • $check = check_set(@things)
  • $check = item($thing)
  • $check = item($idx => $thing)
  • $check = field($name => $val)
  • $check = call($method => $expect)
  • $check = call_list($method => $expect)
  • $check = call_hash($method => $expect)
  • $check = prop($name => $expect)
  • $check = check($thing)
  • $check = T()
  • $check = F()
  • $check = D()
  • $check = DF()
  • $check = E()
  • $check = DNE()
  • $check = FDNE()
  • $check = U()
  • $check = L()
  • $check = exact_ref($ref)
  • end()
  • etc()
  • filter_items { grep { ... } @_ }
  • $check = event $type => ...
  • @checks = fail_events $type => ...

πŸŽ€ CLASSIC COMPARE πŸŽ€

See Test2::Tools::ClassicCompare.

  • cmp_ok($got, $op, $want, $name)

🌸 SUBTEST 🌸

See Test2::Tools::Subtest.

  • subtest $name => sub { ... }; β€” (Note: This is called subtest_buffered() in the Tools module.)

🎯 CLASS 🎯

See Test2::Tools::Class.

  • can_ok($thing, @methods)
  • isa_ok($thing, @classes)
  • DOES_ok($thing, @roles)

🧚 ENCODING 🧚

See Test2::Tools::Encoding.

  • set_encoding($encoding)

⭐ EXPORTS ⭐

See Test2::Tools::Exports.

  • imported_ok('function', '$scalar', ...)
  • not_imported_ok('function', '$scalar', ...)

πŸ’œ REF πŸ’œ

See Test2::Tools::Ref.

  • ref_ok($ref, $type)
  • ref_is($got, $want)
  • ref_is_not($got, $do_not_want)

See Test2::Tools::Refcount.

  • is_refcount($ref, $count, $description)
  • is_oneref($ref, $description)
  • $count = refcount($ref)

πŸ¦‹ MOCK πŸ¦‹

See Test2::Tools::Mock.

  • $control = mock ...
  • $bool = mocked($thing)

πŸ”₯ EXCEPTION πŸ”₯

See Test2::Tools::Exception.

  • $exception = dies { ... }
  • $bool = lives { ... }
  • $bool = try_ok { ... }

πŸŽ€ WARNINGS πŸŽ€

See Test2::Tools::Warnings.

  • $count = warns { ... }
  • $warning = warning { ... }
  • $warnings_ref = warnings { ... }
  • $bool = no_warnings { ... }

🌈 SOURCE 🌈

The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go give it a star, bestie. ⭐


πŸ‘‘ MAINTAINERS πŸ‘‘

Chad Granum <exodist@cpan.org>


πŸ’– AUTHORS πŸ’–

Chad Granum <exodist@cpan.org>


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 http://dev.perl.org/licenses/


And that's the whole page, bestie! πŸŒˆπŸ’…βœ¨

This little masterpiece comes to you from perl v5.42.3, dated 2026-11-03 β€” that's the version and date of this Test2::V0(3pm) page, so jot that down in your notes. Bye bestie, go write some slay tests! πŸ«ΆπŸŽ€πŸ’–

πŸ“¦ where this page comes from