```{index} single: Test2::V0 ``` # Test2::V0 0Th edition of the Test2 recommended bundle. ## V1 IS OUT NOW! See [Test2::V1](V1.md) for the most recent "Recommended" bundle. ## DESCRIPTION This is the big-daddy bundle. This bundle includes nearly every tool, and several plugins, that the Test2 author uses. This bundle is used extensively to test [Test2::Suite](Suite.md) itself. ## NAMING, USING, DEPENDING This bundle should not change in a _severely_ incompatible way. Some minor breaking changes, specially bugfixes, may be allowed. If breaking changes are needed then a new `Test2::V#` module should be released instead. As new `V#` modules are released old ones _may_ be moved to different cpan distributions. You should always use a specific bundle version and list that version in your distributions testing requirements. You should never simply list [Test2::Suite](Suite.md) as your modules dep, instead list the specific bundle, or tools and plugins you use directly in your metadata. ## SYNOPSIS ```perl use Test2::V0; ok(1, "pass"); ... done_testing; ``` ## RESOLVING CONFLICTS WITH MOOSE ```perl use Test2::V0 '!meta'; ``` [Moose](https://metacpan.org/pod/Moose) and [Test2::V0](V0.md) both export very different `meta()` subs. Adding `'!meta'` to the import args will prevent the sub from being imported. This bundle also exports the sub under the name `meta_check()` so you can use that spelling as an alternative. ### TAGS - :DEFAULT The following are both identical: ```perl use Test2::V0; use Test2::V0 ':DEFAULT'; ``` ### RENAMING ON IMPORT ```perl use Test2::V0 ':DEFAULT', '!ok', ok => {-as => 'my_ok'}; ``` This bundle uses [Test2::Util::Importer](Util/Importer.md) for exporting, as such you can use any arguments it accepts. Explanation: - '!ok' Do not export `ok()` - ok => {-as => 'my\_ok'} Actually, go ahead and import `ok()` but under the name `my_ok()`. If you did not add the `'!ok'` argument then you would have both `ok()` and `my_ok()` ## PRAGMAS All of these can be disabled via individual import arguments, or by the `-no_pragmas` argument. ```perl use Test2::V0 -no_pragmas => 1; ``` ### STRICT [strict](../strict.md) is turned on for you. You can disable this with the `-no_strict` or `-no_pragmas` import arguments: ```perl use Test2::V0 -no_strict => 1; ``` ### WARNINGS [warnings](../warnings.md) are turned on for you. You can disable this with the `-no_warnings` or `-no_pragmas` import arguments: ```perl use Test2::V0 -no_warnings => 1; ``` ### UTF8 This is actually done via the [Test2::Plugin::UTF8](Plugin/UTF8.md) plugin, see the "PLUGINS" section for details. **Note:** `-no_pragmas => 1` will turn off the entire plugin. ## PLUGINS ### SRAND See [Test2::Plugin::SRand](Plugin/SRand.md). This will set the random seed to today's date. You can provide an alternate seed with the `-srand` import option: ```perl use Test2::V0 -srand => 1234; ``` You can also disable this behavior: ```perl use Test2::V0 -no_srand => 1; ``` **Note** When srand is on (default) it can cause problems with things like [File::Temp](../File/Temp.md) which will end up attempting the same "random" filenames for every test process started on a given day (or sharing the same seed). ### UTF8 See [Test2::Plugin::UTF8](Plugin/UTF8.md). 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. This can be disabled using the `-no_utf8 => 1` or `-no_pragmas => 1` import arguments. ```perl use Test2::V0 -no_utf8 => 1; ``` ### EXIT SUMMARY See [Test2::Plugin::ExitSummary](Plugin/ExitSummary.md). This plugin has no configuration. ## ENVIRONMENT VARIABLES See [Test2::Env](Env.md) for a list of meaningful environment variables. ## API FUNCTIONS See [Test2::API](API.md) for these - $ctx = context() - $events = intercept { ... } ## TOOLS ### TARGET See [Test2::Tools::Target](Tools/Target.md). 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. ```perl use Test2::V0 -target => 'My::Class'; print $CLASS; # My::Class print CLASS(); # My::Class ``` Or you can specify names: ```perl 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](Tools/Defer.md). - def $func => @args; - do\_def() ### BASIC See [Test2::Tools::Basic](Tools/Basic.md). - 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](Tools/Compare.md). - 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](Tools/ClassicCompare.md). - cmp\_ok($got, $op, $want, $name) ### SUBTEST See [Test2::Tools::Subtest](Tools/Subtest.md). - subtest $name => sub { ... }; (Note: This is called `subtest_buffered()` in the Tools module.) ### CLASS See [Test2::Tools::Class](Tools/Class.md). - can\_ok($thing, @methods) - isa\_ok($thing, @classes) - DOES\_ok($thing, @roles) ### ENCODING See [Test2::Tools::Encoding](Tools/Encoding.md). - set\_encoding($encoding) ### EXPORTS See [Test2::Tools::Exports](Tools/Exports.md). - imported\_ok('function', '$scalar', ...) - not\_imported\_ok('function', '$scalar', ...) ### REF See [Test2::Tools::Ref](Tools/Ref.md). - ref\_ok($ref, $type) - ref\_is($got, $want) - ref\_is\_not($got, $do\_not\_want) See [Test2::Tools::Refcount](Tools/Refcount.md). - is\_refcount($ref, $count, $description) - is\_oneref($ref, $description) - $count = refcount($ref) ### MOCK See [Test2::Tools::Mock](Tools/Mock.md). - $control = mock ... - $bool = mocked($thing) ### EXCEPTION See [Test2::Tools::Exception](Tools/Exception.md). - $exception = dies { ... } - $bool = lives { ... } - $bool = try\_ok { ... } ### WARNINGS See [Test2::Tools::Warnings](Tools/Warnings.md). - $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/`. ## MAINTAINERS - Chad Granum ## AUTHORS - Chad Granum ## COPYRIGHT Copyright Chad Granum . 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/`