.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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 >0, 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 "2022-10-14" "perl v5.34.0" "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.050 of Test::Moose::More \- released September 20, 2017 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. .SS "Export Groups" .IX Subsection "Export Groups" By default, this package exports all test functions. You can be more selective, however, and there are a number of export groups (aside from the default \f(CW\*(C`:all\*(C'\fR) to help you achieve those dreams! .IP ":all" 4 .IX Item ":all" All exportable functions. .IP ":validate" 4 .IX Item ":validate" \&\*(L"validate_attribute\*(R", \*(L"validate_class\*(R", \*(L"validate_role\*(R", \*(L"validate_thing\*(R" .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. Passes if \f(CW$thing\fR has a metaclass. .ie n .SS "no_meta_ok $thing" .el .SS "no_meta_ok \f(CW$thing\fP" .IX Subsection "no_meta_ok $thing" Tests \f(CW$thing\fR to see if it does not have a metaclass; \f(CW$thing\fR may be the class name or instance of the class you wish to check. Passes if \f(CW$thing\fR does not have a metaclass. .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. .PP Note: This does \fBnot\fR include inherited methods; see \&\*(L"has_method\*(R" in Class::MOP::Class. .ie n .SS "has_no_method_ok $thing, @methods" .el .SS "has_no_method_ok \f(CW$thing\fP, \f(CW@methods\fP" .IX Subsection "has_no_method_ok $thing, @methods" Queries \f(CW$thing\fR's metaclass to ensure \f(CW$thing\fR does not provide the methods named in \f(CW@methods\fR. .PP Note: This does \fBnot\fR include inherited methods; see \&\*(L"has_method\*(R" in Class::MOP::Class. .ie n .SS "has_method_from_anywhere_ok $thing, @methods" .el .SS "has_method_from_anywhere_ok \f(CW$thing\fP, \f(CW@methods\fP" .IX Subsection "has_method_from_anywhere_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. .PP Note: This \fBdoes\fR include inherited methods; see \&\*(L"find_method_by_name\*(R" in Class::MOP::Class. .ie n .SS "has_no_method_from_anywhere_ok $thing, @methods" .el .SS "has_no_method_from_anywhere_ok \f(CW$thing\fP, \f(CW@methods\fP" .IX Subsection "has_no_method_from_anywhere_ok $thing, @methods" Queries \f(CW$thing\fR's metaclass to ensure \f(CW$thing\fR does not provide the methods named in \f(CW@methods\fR. .PP Note: This \fBdoes\fR include inherited methods; see \&\*(L"find_method_by_name\*(R" in Class::MOP::Class. .ie n .SS "method_from_pkg_ok $thing, $method, $orig_pkg" .el .SS "method_from_pkg_ok \f(CW$thing\fP, \f(CW$method\fP, \f(CW$orig_pkg\fP" .IX Subsection "method_from_pkg_ok $thing, $method, $orig_pkg" Given a thing (role, class, etc) and a method, test that it originally came from \f(CW$orig_pkg\fR. .ie n .SS "method_not_from_pkg_ok $thing, $method, $orig_pkg" .el .SS "method_not_from_pkg_ok \f(CW$thing\fP, \f(CW$method\fP, \f(CW$orig_pkg\fP" .IX Subsection "method_not_from_pkg_ok $thing, $method, $orig_pkg" Given a thing (role, class, etc) and a method, test that it did not come from \&\f(CW$orig_pkg\fR. .ie n .SS "method_is_accessor_ok $thing, $method" .el .SS "method_is_accessor_ok \f(CW$thing\fP, \f(CW$method\fP" .IX Subsection "method_is_accessor_ok $thing, $method" Given a thing (role, class, etc) and a method, test that the method is an accessor \*(-- that is, it descends from Class::MOP::Method::Accessor. .ie n .SS "method_is_not_accessor_ok $thing, $method" .el .SS "method_is_not_accessor_ok \f(CW$thing\fP, \f(CW$method\fP" .IX Subsection "method_is_not_accessor_ok $thing, $method" Given a thing (role, class, etc) and a method, test that the method is \fBnot\fR an accessor \*(-- that is, it does not descend from Class::MOP::Method::Accessor. .ie n .SS "definition_context_ok $meta, \e%dc" .el .SS "definition_context_ok \f(CW$meta\fP, \e%dc" .IX Subsection "definition_context_ok $meta, %dc" Validates the definition context of a metaclass instance. This is a strict comparison. .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 "does_not_require_method_ok $thing, @methods" .el .SS "does_not_require_method_ok \f(CW$thing\fP, \f(CW@methods\fP" .IX Subsection "does_not_require_method_ok $thing, @methods" Queries \f(CW$thing\fR's metaclass to ensure \f(CW$thing\fR does not require 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_pristine_ok $thing" .el .SS "is_pristine_ok \f(CW$thing\fP" .IX Subsection "is_pristine_ok $thing" Passes if \f(CW$thing\fR is pristine. See \*(L"is_pristine\*(R" in Class::MOP::Class. .ie n .SS "is_not_pristine_ok $thing" .el .SS "is_not_pristine_ok \f(CW$thing\fP" .IX Subsection "is_not_pristine_ok $thing" Passes if \f(CW$thing\fR is not pristine. See \*(L"is_pristine\*(R" in Class::MOP::Class. .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\*(C`\f(CW$thing\f(CW\*(Aqs\*(C'\fR 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\*(C`\f(CW$thing\f(CW\*(Aqs\*(C'\fR 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. .ie n .SS "does_metaroles_ok $thing => { $mop => [ @traits ], ... };" .el .SS "does_metaroles_ok \f(CW$thing\fP => { \f(CW$mop\fP => [ \f(CW@traits\fP ], ... };" .IX Subsection "does_metaroles_ok $thing => { $mop => [ @traits ], ... };" Validate the metaclasses associated with a class/role metaclass. .PP e.g., if I wanted to validate that the attribute trait for MooseX::AttributeShortcuts is actually applied, I could do this: .PP .Vb 3 \& { package TestClass; use Moose; use MooseX::AttributeShortcuts; } \& use Test::Moose::More; \& use Test::More; \& \& does_metaroles_ok TestClass => { \& attribute => [\*(AqMooseX::AttributeShortcuts::Trait::Attribute\*(Aq], \& }; \& done_testing; .Ve .PP This function will accept either class or role metaclasses for \f(CW$thing\fR. .PP The MOPs available for classes (Moose::Meta::Class) are: .IP "class" 4 .IX Item "class" .PD 0 .IP "attribute" 4 .IX Item "attribute" .IP "method" 4 .IX Item "method" .IP "wrapped_method" 4 .IX Item "wrapped_method" .IP "instance" 4 .IX Item "instance" .IP "constructor" 4 .IX Item "constructor" .IP "destructor" 4 .IX Item "destructor" .PD .PP The MOPs available for roles (Moose::Meta::Role) are: .IP "role" 4 .IX Item "role" .PD 0 .IP "attribute" 4 .IX Item "attribute" .IP "method" 4 .IX Item "method" .IP "required_method" 4 .IX Item "required_method" .IP "wrapped_method" 4 .IX Item "wrapped_method" .IP "conflicting_method" 4 .IX Item "conflicting_method" .IP "application_to_class" 4 .IX Item "application_to_class" .IP "application_to_role" 4 .IX Item "application_to_role" .IP "application_to_instance" 4 .IX Item "application_to_instance" .IP "applied_attribute" 4 .IX Item "applied_attribute" .PD .PP Note! Neither this function nor \f(CW\*(C`does_not_metaroles_ok()\*(C'\fR attempts to validate that the \s-1MOP\s0 type passed in is a member of the above lists. There's no gain here in implementing such a check, and a negative to be had: specifying an invalid \s-1MOP\s0 type will result in immediate explosions, while it's entirely possible other \s-1MOP\s0 types will be added (either to core, via traits, or \*(L"let's subclass Moose::Meta::Class/etc and implement something new\*(R"). .ie n .SS "does_not_metaroles_ok $thing => { $mop => [ @traits ], ... };" .el .SS "does_not_metaroles_ok \f(CW$thing\fP => { \f(CW$mop\fP => [ \f(CW@traits\fP ], ... };" .IX Subsection "does_not_metaroles_ok $thing => { $mop => [ @traits ], ... };" As with \*(L"does_metaroles_ok\*(R", but test that the metaroles are not consumed, a la \*(L"does_not_ok\*(R". .SS "attribute_options_ok" .IX Subsection "attribute_options_ok" Validates that an attribute is set up as expected; like \&\f(CW\*(C`validate_attribute()\*(C'\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 \&\f(CW\*(C`\-subtest => \*(Aqsubtest name...\*(Aq\*(C'\fR .Sp If set, all tests run (save the first, \*(L"does this thing even have this attribute?\*(R" test) 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 \&\f(CW\*(C`is => ro|rw\*(C'\fR .Sp Tests for reader/writer options set as one would expect. .IP "\(bu" 4 \&\f(CW\*(C`isa => ...\*(C'\fR .Sp Validates that the attribute requires its value to be a given type. .IP "\(bu" 4 \&\f(CW\*(C`does => ...\*(C'\fR .Sp Validates that the attribute requires its value to do a given role. .IP "\(bu" 4 \&\f(CW\*(C`builder => \*(Aq...\*(Aq\*(C'\fR .Sp Validates that the attribute expects the method name given to be its builder. .IP "\(bu" 4 \&\f(CW\*(C`default => ...\*(C'\fR .Sp Validates that the attribute has the given default. .IP "\(bu" 4 \&\f(CW\*(C`init_arg => \*(Aq...\*(Aq\*(C'\fR .Sp Validates that the attribute has the given initial argument name. .IP "\(bu" 4 \&\f(CW\*(C`lazy => 0|1\*(C'\fR .Sp Validates that the attribute is/isn't lazy. .IP "\(bu" 4 \&\f(CW\*(C`required => 0|1\*(C'\fR .Sp Validates that setting the attribute's value is/isn't required. .SH "VALIDATION METHODS" .IX Header "VALIDATION METHODS" .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 \&\f(CW\*(C`\-subtest => \*(Aqsubtest name...\*(Aq\*(C'\fR .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 \&\f(CW\*(C`isa => [ ... ]\*(C'\fR .Sp A list of superclasses thing should have. .IP "\(bu" 4 \&\f(CW\*(C`anonymous => 0|1\*(C'\fR .Sp Check to see if the class is/isn't anonymous. .IP "\(bu" 4 \&\f(CW\*(C`does => [ ... ]\*(C'\fR .Sp A list of roles the thing should do. .IP "\(bu" 4 \&\f(CW\*(C`does_not => [ ... ]\*(C'\fR .Sp A list of roles the thing should not do. .IP "\(bu" 4 \&\f(CW\*(C`attributes => [ ... ]\*(C'\fR .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 \&\f(CW\*(C`methods => [ ... ]\*(C'\fR .Sp A list of methods the thing should have; see \*(L"has_method_ok\*(R". .IP "\(bu" 4 \&\f(CW\*(C`no_methods => [ ... ]\*(C'\fR .Sp A list of methods the thing should not have; see \*(L"has_no_method_ok\*(R". .IP "\(bu" 4 \&\f(CW\*(C`sugar => 0|1\*(C'\fR .Sp Ensure that thing can/cannot do the standard Moose sugar. .IP "\(bu" 4 \&\f(CW\*(C`metaclasses => { $mop => { ... }, ... }\*(C'\fR .Sp Validates this thing's metaclasses: that is, given a \s-1MOP\s0 type (e.g. class, attribute, method, ...) and a hashref, find the associated metaclass of the given type and invoke \*(L"validate_thing\*(R" on it, using the hashref as options for \f(CW\*(C`validate_thing()\*(C'\fR. .Sp e.g. .Sp .Vb 8 \& validate_thing \*(AqTestClass\*(Aq => ( \& metaclasses => { \& attribute => { \& isa => [ \*(AqMoose::Meta::Attribute\*(Aq ], \& does => [ \*(AqMetaRole::attribute\*(Aq ], \& }, \& }, \& ); .Ve .Sp \&...yields: .Sp .Vb 7 \& # Subtest: Checking the attribute metaclass, Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 \& ok 1 \- TestClass\*(Aqs attribute metaclass has a metaclass \& ok 2 \- TestClass\*(Aqs attribute metaclass is a Moose class \& ok 3 \- TestClass\*(Aqs attribute metaclass isa Moose::Meta::Attribute \& ok 4 \- TestClass\*(Aqs attribute metaclass does MetaRole::attribute \& 1..4 \& ok 1 \- Checking the attribute metaclass, Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 .Ve .Sp Note that \f(CW\*(C`validate_class()\*(C'\fR and \f(CW\*(C`validate_role()\*(C'\fR implement this using \&\f(CW\*(C`class_metaclasses\*(C'\fR and \f(CW\*(C`role_metaclasses\*(C'\fR, respectively. .SS "validate_role" .IX Subsection "validate_role" The same as \f(CW\*(C`validate_thing()\*(C'\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 \&\f(CW\*(C`\-compose => 0|1\*(C'\fR .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 \f(CW\*(C`validate_class()\*(C'\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 \- TestRole\*(Aqs composed class has a metaclass \& ok 2 \- TestRole\*(Aqs composed class is a Moose class \& ok 3 \- TestRole\*(Aqs composed class does TestRole \& ok 4 \- TestRole\*(Aqs composed class does not do TestRole::Two \& ok 5 \- TestRole\*(Aqs composed class has method method1 \& ok 6 \- TestRole\*(Aqs composed class has method blargh \& ok 7 \- TestRole\*(Aqs composed class has an attribute named bar \& 1..7 \& ok 8 \- role composed into Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 \& 1..8 .Ve .IP "\(bu" 4 \&\f(CW\*(C`\-subtest => \*(Aqsubtest name...\*(Aq\*(C'\fR .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 \&\f(CW\*(C`required_methods => [ ... ]\*(C'\fR .Sp A list of methods the role requires a consuming class to supply. .IP "\(bu" 4 \&\f(CW\*(C`before => [ ... ]\*(C'\fR .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 \&\f(CW\*(C`around => [ ... ]\*(C'\fR .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 \&\f(CW\*(C`after => [ ... ]\*(C'\fR .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. .IP "\(bu" 4 \&\f(CW\*(C`role_metaroles => { $mop => [ $role, ... ], ... }\*(C'\fR .Sp Checks metaclasses to ensure the given metaroles are applied. See \&\*(L"does_metaroles_ok\*(R". .IP "\(bu" 4 \&\f(CW\*(C`no_role_metaroles => { $mop => [ $role, ... ], ... }\*(C'\fR .Sp Checks metaclasses to ensure the given metaroles are applied. See \&\*(L"does_not_metaroles_ok\*(R". .IP "\(bu" 4 \&\f(CW\*(C`role_metaclasses => { $mop => { ... }, ... }\*(C'\fR .Sp Validates this role's metaclasses: that is, given a \s-1MOP\s0 type (e.g. role, attribute, method, ...) and a hashref, find the associated metaclass of the given type and invoke \*(L"validate_thing\*(R" on it, using the hashref as options for \f(CW\*(C`validate_thing()\*(C'\fR. .Sp e.g. .Sp .Vb 8 \& validate_role \*(AqTestRole\*(Aq => ( \& metaclasses => { \& attribute => { \& isa => [ \*(AqMoose::Meta::Attribute\*(Aq ], \& does => [ \*(AqMetaRole::attribute\*(Aq ], \& }, \& }, \& ); .Ve .Sp \&...yields: .Sp .Vb 7 \& # Subtest: Checking the attribute metaclass, Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 \& ok 1 \- TestRole\*(Aqs attribute metaclass has a metaclass \& ok 2 \- TestRole\*(Aqs attribute metaclass is a Moose class \& ok 3 \- TestRole\*(Aqs attribute metaclass isa Moose::Meta::Attribute \& ok 4 \- TestRole\*(Aqs attribute metaclass does MetaRole::attribute \& 1..4 \& ok 1 \- Checking the attribute metaclass, Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 .Ve .Sp Note that \f(CW\*(C`validate_class()\*(C'\fR and \f(CW\*(C`validate_role()\*(C'\fR implement this using \&\f(CW\*(C`class_metaclasses\*(C'\fR and \f(CW\*(C`role_metaclasses\*(C'\fR, respectively. .IP "\(bu" 4 \&\f(CW\*(C`class_metaclasses => { $mop => { ... }, ... }\*(C'\fR .Sp As with role_metaclasses, above, except that this option is only used if \f(CW\*(C`\-compose\*(C'\fR is also specified. .SS "validate_class" .IX Subsection "validate_class" The same as \f(CW\*(C`validate_thing()\*(C'\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 => [ ... ], \& \& # 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 \&\f(CW\*(C`\-subtest => \*(Aqsubtest name...\*(Aq\*(C'\fR .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 \&\f(CW\*(C`immutable => 0|1\*(C'\fR .Sp Checks the class to see if it is/isn't immutable. .IP "\(bu" 4 \&\f(CW\*(C`class_metaroles => { $mop => [ $role, ... ], ... }\*(C'\fR .Sp Checks metaclasses to ensure the given metaroles are applied. See \&\*(L"does_metaroles_ok\*(R". .IP "\(bu" 4 \&\f(CW\*(C`no_class_metaroles => { $mop => [ $role, ... ], ... }\*(C'\fR .Sp Checks metaclasses to ensure the given metaroles are applied. See \&\*(L"does_not_metaroles_ok\*(R". .IP "\(bu" 4 \&\f(CW\*(C`class_metaclasses => { $mop => { ... }, ... }\*(C'\fR .Sp Validates this class' metaclasses: that is, given a \s-1MOP\s0 type (e.g. role, attribute, method, ...) and a hashref, find the associated metaclass of the given type and invoke \*(L"validate_thing\*(R" on it, using the hashref as options for \f(CW\*(C`validate_thing()\*(C'\fR. .Sp e.g. .Sp .Vb 8 \& validate_class \*(AqTestClass\*(Aq => ( \& metaclasses => { \& attribute => { \& isa => [ \*(AqMoose::Meta::Attribute\*(Aq ], \& does => [ \*(AqMetaRole::attribute\*(Aq ], \& }, \& }, \& ); .Ve .Sp \&...yields: .Sp .Vb 9 \& ok 1 \- TestClass has a metaclass \& ok 2 \- TestClass is a Moose class \& # Subtest: Checking the attribute metaclass, Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 \& ok 1 \- TestClass\*(Aqs attribute metaclass has a metaclass \& ok 2 \- TestClass\*(Aqs attribute metaclass is a Moose class \& ok 3 \- TestClass\*(Aqs attribute metaclass isa Moose::Meta::Attribute \& ok 4 \- TestClass\*(Aqs attribute metaclass does MetaRole::attribute \& 1..4 \& ok 3 \- Checking the attribute metaclass, Moose::Meta::Class::_\|_ANON_\|_::SERIAL::1 .Ve .SS "validate_attribute" .IX Subsection "validate_attribute" \&\f(CW\*(C`validate_attribute()\*(C'\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 \f(CW\*(C`validate_attribute()\*(C'\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 \f(CW\*(C`validate_attribute()\*(C'\fR prefixed with \f(CW\*(C`\-\*(C'\fR test the attribute's metaclass instance rather than a setting on the attribute; that is, \f(CW\*(C`\-does\*(C'\fR ensures that the metaclass does a particular role (e.g. MooseX::AttributeShortcuts), while \f(CW\*(C`does\*(C'\fR 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 \&\f(CW\*(C`\-subtest => \*(Aqsubtest name...\*(Aq\*(C'\fR .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. .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 .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 .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) 2017, 2016, 2015, 2014, 2013, 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