/usr/share/perl5/Test/Roo/Class.pm is in libtest-roo-perl 1.002-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | use 5.008001;
use strictures;
package Test::Roo::Class;
# ABSTRACT: Base class for Test::Roo test classes
our $VERSION = '1.002'; # VERSION
use Moo;
use MooX::Types::MooseLike::Base qw/Str/;
use Test::More 0.96 import => [qw/subtest/];
#--------------------------------------------------------------------------#
# attributes
#--------------------------------------------------------------------------#
has description => (
is => 'rw',
isa => Str,
lazy => 1,
builder => 1,
);
sub _build_description {
my $class = ref $_[0];
return "testing with $class";
}
#--------------------------------------------------------------------------#
# class or object methods
#--------------------------------------------------------------------------#
sub run_tests {
my $self = shift;
# get hashref from end of args
# if any args are left, it must be description
my ( $desc, $args );
$args = pop if @_ && ref $_[-1] eq 'HASH';
$desc = shift;
# create an object if needed and possibly update description
$self = $self->new( $args || {} )
if !ref $self;
$self->description($desc)
if defined $desc;
# execute tests wrapped in a subtest
subtest $self->description => sub {
$self->setup;
$self->_do_tests;
$self->teardown;
};
}
#--------------------------------------------------------------------------#
# private methods and stubs
#--------------------------------------------------------------------------#
sub setup { }
sub each_test {
my ( $self, $code ) = @_;
$code->($self);
}
sub teardown { }
# anchor for tests as method modifiers
sub _do_tests { }
1;
# vim: ts=4 sts=4 sw=4 et:
__END__
=pod
=encoding utf-8
=head1 NAME
Test::Roo::Class - Base class for Test::Roo test classes
=head1 VERSION
version 1.002
=head1 DESCRIPTION
This module is the base class for L<Test::Roo> test classes. It provides
methods to run tests and anchor modifiers. Generally, you should not extend
this class yourself, but use L<Test::Roo> to do so instead.
=head1 ATTRIBUTES
=head2 description
A description for a subtest block wrapping all tests by the object. It is a
'lazy' attribute. Test classes may implement their own C<_build_description>
method to create a description from object attributes. Otherwise, the default
is "testing with CLASS".
=head1 METHODS
=head2 run_tests
# as a class method
$class->run_tests();
$class->run_tests($description);
$class->run_tests($init_args);
$class->run_tests($description $init_args);
# as an object method
$self->run_tests();
$self->run_tests($description);
If called as a class method, this creates a test object using an optional hash
reference of initialization arguments.
When called as an object method, or after an object has been generated, this
method sets an optional description and runs tests. It will call the C<setup>
method (triggering any method modifiers), will run all tests (triggering any
method modifiers on C<each_test>) and will call the C<teardown> method
(triggering any method modifiers).
If a description is provided, it will override any initialized or generated
C<description> attribute.
The setup, tests and teardown will be executed in a L<Test::More> subtest
block.
=head2 setup
This is an empty method used to anchor method modifiers. It should not
be overridden by subclasses.
=head2 each_test
This method wraps the code references set by the C<test> function
from L<Test::Roo> or L<Test::Roo::Role> in a L<Test::More> subtest block.
It may also be used to anchor modifiers that should run before or after
each test block, though this can lead to brittle design as modifiers
will globally affect every test block, including composed ones.
=head2 teardown
This is an empty method used to anchor method modifiers. It should not
be overridden by subclasses.
=for Pod::Coverage each_test setup teardown
=head1 AUTHOR
David Golden <dagolden@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
=cut
|