| 1 | package Test::Sweet::Meta::Class; | ||||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | $Test::Sweet::Meta::Class::VERSION = '0.03'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | # ABSTRACT: metaclass role that provides methods for keeping track of tests | ||||||||||||
| 6 | 3 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use MooseX::Types::Moose qw(Str ArrayRef ClassName Object); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use Test::Sweet::Meta::Method; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | ▶ | use Moose::Meta::Class; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use List::MoreUtils qw(uniq); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | has 'local_tests' => ( | ||||||||||||
| 15 | traits => ['Array'], | ||||||||||||
| 16 | is => 'ro', | ||||||||||||
| 17 | isa => ArrayRef[Str], | ||||||||||||
| 18 | required => 1, | ||||||||||||
| 19 | 6 | ▶ | default => sub { [] }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 3 | auto_deref => 1, | |||||||||||
| 21 | handles => { | ||||||||||||
| 22 | '_add_test' => 'push', | ||||||||||||
| 23 | } | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | 3 | has 'test_metaclass' => ( | |||||||||||
| 27 | is => 'ro', | ||||||||||||
| 28 | isa => Object, | ||||||||||||
| 29 | lazy_build => 1, | ||||||||||||
| 30 | ); | ||||||||||||
| 31 | |||||||||||||
| 32 | has 'test_metamethod_roles' => ( | ||||||||||||
| 33 | is => 'ro', | ||||||||||||
| 34 | isa => ArrayRef[ClassName], | ||||||||||||
| 35 | required => 1, | ||||||||||||
| 36 | 6 | ▶ | default => sub { ['Test::Sweet::Meta::Method'] }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 37 | 3 | ); | |||||||||||
| 38 | |||||||||||||
| 39 | 6 | ▶ | sub _build_test_metaclass { | ||||||||||
|
Subroutine
_build_test_metaclass: called CC=1 SCAR=0.0
| |||||||||||||
| 40 | 6 | my $self = shift; | |||||||||||
| 41 | 6 | return Moose::Meta::Class->create_anon_class( | |||||||||||
| 42 | superclasses => [ $self->method_metaclass ], | ||||||||||||
| 43 | roles => $self->test_metamethod_roles, | ||||||||||||
| 44 | cache => 1, | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 13 | ▶ | sub add_test { | ||||||||||
|
Subroutine
add_test: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 49 | 13 | my ($self, $name, $code, $test_traits) = @_; | |||||||||||
| 50 | 13 | ▶ | my $body = $self->test_metaclass->name->wrap( | ||||||||||
|
Condition50%1/2
$test_traits || []
MC/DC0%0/1
$test_traits || []
$test_traits
Truth table50%1/2
A
A= $test_traits
| |||||||||||||
| 51 | $code, | ||||||||||||
| 52 | requested_test_traits => $test_traits || [], | ||||||||||||
| 53 | original_body => $code, | ||||||||||||
| 54 | name => $name, | ||||||||||||
| 55 | package_name => $self->name, | ||||||||||||
| 56 | ); | ||||||||||||
| 57 | |||||||||||||
| 58 | 13 | $self->add_method( $name, $body ); | |||||||||||
| 59 | 13 | $self->_add_test ( $name ); | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | # ensure that we get the role's tests (they are available via the MOP, of course) | ||||||||||||
| 63 | 2 | ▶ | after 'add_role' => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||
| 64 | 2 | my ($self, $role) = @_; | |||||||||||
| 65 | 2 | ▶ | if ( $role->can('local_tests') ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 2 | $self->_add_test($role->local_tests); | |||||||||||
| 67 | } | ||||||||||||
| 68 | 3 | }; | |||||||||||
| 69 | |||||||||||||
| 70 | 3 | ▶ | sub get_all_tests { | ||||||||||
|
Subroutine
get_all_tests: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 71 | 3 | my $self = shift; | |||||||||||
| 72 | 3 | ▶ | return $self->local_tests unless $self->can('linearized_isa'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | |||||||||||||
| 74 | 3 | my @ordering = reverse $self->linearized_isa; | |||||||||||
| 75 | my @tests = map { | ||||||||||||
| 76 | 3 | eval { | |||||||||||
| 77 | 10 | my $meta = $_->meta; | |||||||||||
| 78 | 10 | $meta->local_tests; | |||||||||||
| 79 | }; | ||||||||||||
| 80 | } @ordering; | ||||||||||||
| 81 | |||||||||||||
| 82 | 3 | return uniq @tests; | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 3 | 1; | |||||||||||
| 86 | |||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | =pod | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 NAME | ||||||||||||
| 92 | |||||||||||||
| 93 | Test::Sweet::Meta::Class - metaclass role that provides methods for keeping track of tests | ||||||||||||
| 94 | |||||||||||||
| 95 | =head1 VERSION | ||||||||||||
| 96 | |||||||||||||
| 97 | version 0.03 | ||||||||||||
| 98 | |||||||||||||
| 99 | =head1 METHODS | ||||||||||||
| 100 | |||||||||||||
| 101 | =head2 get_all_tests | ||||||||||||
| 102 | |||||||||||||
| 103 | Returns the names of all test methods in this class' hierarchy. | ||||||||||||
| 104 | |||||||||||||
| 105 | =head2 local_tests | ||||||||||||
| 106 | |||||||||||||
| 107 | Returns the names of the test methods defined in this class. Includes | ||||||||||||
| 108 | tests composed in via roles. | ||||||||||||
| 109 | |||||||||||||
| 110 | =head1 AUTHOR | ||||||||||||
| 111 | |||||||||||||
| 112 | Jonathan Rockway <jrockway@cpan.org> | ||||||||||||
| 113 | |||||||||||||
| 114 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 115 | |||||||||||||
| 116 | This software is copyright (c) 2011 by Jonathan Rockway. | ||||||||||||
| 117 | |||||||||||||
| 118 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 119 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 120 | |||||||||||||
| 121 | =cut | ||||||||||||
| 122 | |||||||||||||
| 123 | |||||||||||||
| 124 | __END__ | ||||||||||||