.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test::Moose::More 3pm" .TH Test::Moose::More 3pm "2016-07-03" "perl v5.22.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::Moose::More \- More tools for testing Moose packages .SH "VERSION" .IX Header "VERSION" This document describes version 0.038 of Test::Moose::More \- released June 22, 2016 as part of Test-Moose-More. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Test::Moose::More; \& \& is_class_ok \*(AqSome::Class\*(Aq; \& is_role_ok \*(AqSome::Role\*(Aq; \& has_method_ok \*(AqSome::Class\*(Aq, \*(Aqfoo\*(Aq; \& \& # ... etc .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This package contains a number of additional tests that can be employed against Moose classes/roles. It is intended to replace Test::Moose in your tests, and re-exports any tests that it has and we do not, yet. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "known_sugar" .IX Subsection "known_sugar" Returns a list of all the known standard Moose sugar (has, extends, etc). .SH "TEST FUNCTIONS" .IX Header "TEST FUNCTIONS" .ie n .SS "meta_ok $thing" .el .SS "meta_ok \f(CW$thing\fP" .IX Subsection "meta_ok $thing" Tests \f(CW$thing\fR to see if it has a metaclass; \f(CW$thing\fR may be the class name or instance of the class you wish to check. .ie n .SS "does_ok $thing, < $role | \e@roles >, [ $message ]" .el .SS "does_ok \f(CW$thing\fP, < \f(CW$role\fP | \e@roles >, [ \f(CW$message\fP ]" .IX Subsection "does_ok $thing, < $role | @roles >, [ $message ]" Checks to see if \f(CW$thing\fR does the given roles. \f(CW$thing\fR may be the class name or instance of the class you wish to check. .PP Note that the message will be taken verbatim unless it contains \f(CW%s\fR somewhere; this will be replaced with the name of the role being tested for. .ie n .SS "does_not_ok $thing, < $role | \e@roles >, [ $message ]" .el .SS "does_not_ok \f(CW$thing\fP, < \f(CW$role\fP | \e@roles >, [ \f(CW$message\fP ]" .IX Subsection "does_not_ok $thing, < $role | @roles >, [ $message ]" Checks to see if \f(CW$thing\fR does not do the given roles. \f(CW$thing\fR may be the class name or instance of the class you wish to check. .PP Note that the message will be taken verbatim unless it contains \f(CW%s\fR somewhere; this will be replaced with the name of the role being tested for. .ie n .SS "has_attribute_ok $thing, $attribute_name, [ $message ]" .el .SS "has_attribute_ok \f(CW$thing\fP, \f(CW$attribute_name\fP, [ \f(CW$message\fP ]" .IX Subsection "has_attribute_ok $thing, $attribute_name, [ $message ]" Checks \f(CW$thing\fR for an attribute named \f(CW$attribute_name\fR; \f(CW$thing\fR may be a class name, instance, or role name. .ie n .SS "has_method_ok $thing, @methods" .el .SS "has_method_ok \f(CW$thing\fP, \f(CW@methods\fP" .IX Subsection "has_method_ok $thing, @methods" Queries \f(CW$thing\fR's metaclass to see if \f(CW$thing\fR has the methods named in \f(CW@methods\fR. .ie n .SS "role_wraps_around_method_ok $role, @methods" .el .SS "role_wraps_around_method_ok \f(CW$role\fP, \f(CW@methods\fP" .IX Subsection "role_wraps_around_method_ok $role, @methods" Queries \f(CW$role\fR's metaclass to see if \f(CW$role\fR wraps the methods named in \&\f(CW@methods\fR with an around method modifier. .ie n .SS "role_wraps_before_method_ok $role, @methods" .el .SS "role_wraps_before_method_ok \f(CW$role\fP, \f(CW@methods\fP" .IX Subsection "role_wraps_before_method_ok $role, @methods" Queries \f(CW$role\fR's metaclass to see if \f(CW$role\fR wraps the methods named in \&\f(CW@methods\fR with an before method modifier. .ie n .SS "role_wraps_after_method_ok $role, @methods" .el .SS "role_wraps_after_method_ok \f(CW$role\fP, \f(CW@methods\fP" .IX Subsection "role_wraps_after_method_ok $role, @methods" Queries \f(CW$role\fR's metaclass to see if \f(CW$role\fR wraps the methods named in \&\f(CW@methods\fR with an after method modifier. .ie n .SS "requires_method_ok $thing, @methods" .el .SS "requires_method_ok \f(CW$thing\fP, \f(CW@methods\fP" .IX Subsection "requires_method_ok $thing, @methods" Queries \f(CW$thing\fR's metaclass to see if \f(CW$thing\fR requires the methods named in \&\f(CW@methods\fR. .PP Note that this really only makes sense if \f(CW$thing\fR is a role. .ie n .SS "is_immutable_ok $thing" .el .SS "is_immutable_ok \f(CW$thing\fP" .IX Subsection "is_immutable_ok $thing" Passes if \f(CW$thing\fR is immutable. .ie n .SS "is_not_immutable_ok $thing" .el .SS "is_not_immutable_ok \f(CW$thing\fP" .IX Subsection "is_not_immutable_ok $thing" Passes if \f(CW$thing\fR is not immutable; that is, is mutable. .ie n .SS "is_role_ok $thing" .el .SS "is_role_ok \f(CW$thing\fP" .IX Subsection "is_role_ok $thing" Passes if \f(CW$thing\fR's metaclass is a Moose::Meta::Role. .ie n .SS "is_class_ok $thing" .el .SS "is_class_ok \f(CW$thing\fP" .IX Subsection "is_class_ok $thing" Passes if \f(CW$thing\fR's metaclass is a Moose::Meta::Class. .ie n .SS "is_anon_ok $thing" .el .SS "is_anon_ok \f(CW$thing\fP" .IX Subsection "is_anon_ok $thing" Passes if \f(CW$thing\fR is \*(L"anonymous\*(R". .ie n .SS "is_not_anon_ok $thing" .el .SS "is_not_anon_ok \f(CW$thing\fP" .IX Subsection "is_not_anon_ok $thing" Passes if \f(CW$thing\fR is not \*(L"anonymous\*(R". .ie n .SS "check_sugar_removed_ok $thing" .el .SS "check_sugar_removed_ok \f(CW$thing\fP" .IX Subsection "check_sugar_removed_ok $thing" Ensures that all the standard Moose sugar is no longer directly callable on a given package. .ie n .SS "check_sugar_ok $thing" .el .SS "check_sugar_ok \f(CW$thing\fP" .IX Subsection "check_sugar_ok $thing" Checks and makes sure a class/etc can still do all the standard Moose sugar. .SS "validate_thing" .IX Subsection "validate_thing" Runs a bunch of tests against the given \f(CW$thing\fR, as defined: .PP .Vb 1 \& validate_thing $thing => ( \& \& attributes => [ ... ], \& methods => [ ... ], \& isa => [ ... ], \& \& # ensures sugar is/is\-not present \& sugar => 0, \& \& # ensures $thing does these roles \& does => [ ... ], \& \& # ensures $thing does not do these roles \& does_not => [ ... ], \& ); .Ve .PP \&\f(CW$thing\fR can be the name of a role or class, an object instance, or a metaclass. .IP "\(bu" 4 \&\-subtest => 'subtest name...' .Sp If set, all tests run will be wrapped in a subtest, the name of which will be whatever \f(CW\*(C`\-subtest\*(C'\fR is set to. .IP "\(bu" 4 isa => [ ... ] .Sp A list of superclasses thing should have. .IP "\(bu" 4 anonymous => 0|1 .Sp Check to see if the class is/isn't anonymous. .IP "\(bu" 4 does => [ ... ] .Sp A list of roles the thing should do. .IP "\(bu" 4 does_not => [ ... ] .Sp A list of roles the thing should not do. .IP "\(bu" 4 attributes => [ ... ] .Sp The attributes list specified here is in the form of a list of names, each optionally followed by a hashref of options to test the attribute for; this hashref takes the same arguments \*(L"validate_attribute\*(R" does. e.g.: .Sp .Vb 1 \& validate_thing $thing => ( \& \& attributes => [ \& \*(Aqfoo\*(Aq, \& \*(Aqbar\*(Aq, \& baz => { is => \*(Aqro\*(Aq, ... }, \& \*(Aqbip\*(Aq, \& ], \& ); .Ve .IP "\(bu" 4 methods => [ ... ] .Sp A list of methods the thing should have. .IP "\(bu" 4 sugar => 0|1 .Sp Ensure that thing can/cannot do the standard Moose sugar. .SS "validate_role" .IX Subsection "validate_role" The same as \fIvalidate_thing()\fR, but ensures \f(CW$thing\fR is a role, and allows for additional role-specific tests. .PP .Vb 1 \& validate_role $thing => ( \& \& required_methods => [ ... ], \& \& # ...and all other options from validate_thing() \& ); .Ve .IP "\(bu" 4 \&\-compose => 0|1 .Sp When true, attempt to compose the role into an anonymous class, then use it to run \*(L"validate_class\*(R". The options we're given are passed to \fIvalidate_class()\fR directly, except that any \f(CW\*(C`required_methods\*(C'\fR entry is removed and its contents pushed onto \f(CW\*(C`methods\*(C'\fR. (A stub method for each entry in \f(CW\*(C`required_methods\*(C'\fR will also be created in the new class.) .Sp e.g.: .Sp .Vb 10 \& ok 1 \- TestRole has a metaclass \& ok 2 \- TestRole is a Moose role \& ok 3 \- TestRole requires method blargh \& ok 4 \- TestRole does TestRole \& ok 5 \- TestRole does not do TestRole::Two \& ok 6 \- TestRole has method method1 \& ok 7 \- TestRole has an attribute named bar \& # Subtest: role composed into Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 \& ok 1 \- Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 has a metaclass \& ok 2 \- Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 is a Moose class \& ok 3 \- Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 does TestRole \& ok 4 \- Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 does not do TestRole::Two \& ok 5 \- Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 has method method1 \& ok 6 \- Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 has method blargh \& ok 7 \- Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 has an attribute named bar \& 1..7 \& ok 8 \- role composed into Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 \& 1..8 .Ve .IP "\(bu" 4 \&\-subtest => 'subtest name...' .Sp If set, all tests run will be wrapped in a subtest, the name of which will be whatever \f(CW\*(C`\-subtest\*(C'\fR is set to. .IP "\(bu" 4 required_methods => [ ... ] .Sp A list of methods the role requires a consuming class to supply. .IP "\(bu" 4 before => [ ... ] .Sp A list of methods the role expects to wrap before, on application to a class. .Sp See \*(L"before\*(R" in Moose for information on before method modifiers. .IP "\(bu" 4 around => [ ... ] .Sp A list of methods the role expects to wrap around, on application to a class. .Sp See \*(L"around\*(R" in Moose for information on around method modifiers. .IP "\(bu" 4 after => [ ... ] .Sp A list of methods the role expects to wrap after, on application to a class. .Sp See \*(L"after\*(R" in Moose for information on after method modifiers. .SS "validate_class" .IX Subsection "validate_class" The same as \fIvalidate_thing()\fR, but ensures \f(CW$thing\fR is a class, and allows for additional class-specific tests. .PP .Vb 1 \& validate_class $thing => ( \& \& isa => [ ... ], \& \& attributes => [ ... ], \& methods => [ ... ], \& isa => [ ... ], \& \& # ensures sugar is/is\-not present \& sugar => 0, \& \& # ensures $thing does these roles \& does => [ ... ], \& \& # ensures $thing does not do these roles \& does_not => [ ... ], \& \& # ...and all other options from validate_thing() \& ); .Ve .IP "\(bu" 4 \&\-subtest => 'subtest name...' .Sp If set, all tests run will be wrapped in a subtest, the name of which will be whatever \f(CW\*(C`\-subtest\*(C'\fR is set to. .IP "\(bu" 4 immutable => 0|1 .Sp Checks the class to see if it is/isn't immutable. .SS "validate_attribute" .IX Subsection "validate_attribute" \&\fIvalidate_attribute()\fR allows you to test how an attribute looks once built and attached to a class. .PP Let's say you have an attribute defined like this: .PP .Vb 7 \& has foo => ( \& traits => [ \*(AqTestRole\*(Aq ], \& is => \*(Aqro\*(Aq, \& isa => \*(AqInt\*(Aq, \& builder => \*(Aq_build_foo\*(Aq, \& lazy => 1, \& ); .Ve .PP You can use \fIvalidate_attribute()\fR to ensure that it's built out in the way you expect: .PP .Vb 1 \& validate_attribute TestClass => foo => ( \& \& # tests the attribute metaclass instance to ensure it does the roles \& \-does => [ \*(AqTestRole\*(Aq ], \& # tests the attribute metaclass instance\*(Aqs inheritance \& \-isa => [ \*(AqMoose::Meta::Attribute\*(Aq ], # for demonstration\*(Aqs sake \& \& traits => [ \*(AqTestRole\*(Aq ], \& isa => \*(AqInt\*(Aq, \& does => \*(AqBar\*(Aq, \& handles => { }, \& reader => \*(Aqfoo\*(Aq, \& builder => \*(Aq_build_foo\*(Aq, \& default => undef, \& init_arg => \*(Aqfoo\*(Aq, \& lazy => 1, \& required => undef, \& ); .Ve .PP Options passed to \fIvalidate_attribute()\fR prefixed with '\-' test the attribute's metaclass instance rather than a setting on the attribute; that is, '\-does' ensures that the metaclass does a particular role (e.g. MooseX::AttributeShortcuts), while 'does' tests the setting of the attribute to require the value do a given role. .PP This function takes all the options \*(L"attribute_options_ok\*(R" takes, as well as the following: .IP "\(bu" 4 \&\-subtest => 'subtest name...' .Sp If set, all tests run will be wrapped in a subtest, the name of which will be whatever \f(CW\*(C`\-subtest\*(C'\fR is set to. .SS "attribute_options_ok" .IX Subsection "attribute_options_ok" Validates that an attribute is set up as expected; like \fIvalidate_attribute()\fR, but only concerns itself with attribute options. .PP Note that some of these options will skip if used against attributes defined in a role. .IP "\(bu" 4 is => ro|rw .Sp Tests for reader/writer options set as one would expect. .IP "\(bu" 4 isa => ... .Sp Validates that the attribute requires its value to be a given type. .IP "\(bu" 4 does => ... .Sp Validates that the attribute requires its value to do a given role. .IP "\(bu" 4 builder => '...' .Sp Validates that the attribute expects the method name given to be its builder. .IP "\(bu" 4 default => ... .Sp Validates that the attribute has the given default. .IP "\(bu" 4 init_arg => '...' .Sp Validates that the attribute has the given initial argument name. .IP "\(bu" 4 lazy => 0|1 .Sp Validates that the attribute is/isn't lazy. .IP "\(bu" 4 required => 0|1 .Sp Validates that setting the attribute's value is/isn't required. .SH "SEE ALSO" .IX Header "SEE ALSO" Please see those modules/websites for more information related to this module. .IP "\(bu" 4 Test::Moose .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website https://github.com/RsrchBoy/Test\-Moose\-More/issues .PP When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. .SH "AUTHOR" .IX Header "AUTHOR" Chris Weyl .SS "I'm a material boy in a material world" .IX Subsection "I'm a material boy in a material world" Please note \fBI do not expect to be gittip'ed or flattr'ed for this work\fR, rather \fBit is simply a very pleasant surprise\fR. I largely create and release works like this because I need them or I find it enjoyable; however, don't let that stop you if you feel like it ;) .PP Flattr , Gratipay , or indulge my Amazon Wishlist ... If and *only* if you so desire. .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Chad Granum .IP "\(bu" 4 Karen Etheridge .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2012 by Chris Weyl. .PP This is free software, licensed under: .PP .Vb 1 \& The GNU Lesser General Public License, Version 2.1, February 1999 .Ve